MP6767's scripting tutorialIf you've clicked on this topic, chances are you want to know how to make your own modifications. This will teach you the basics. First off, we'll look at a script add-on's folder structure.

First off, let me say that this is for a server script, not a client one.
For description.txt, you need these things
Title: Test
Author: [Yourname]
A brief description. Try to keep it to one line.
Now for namecheck.txt, which doesn't REALLY need to be included as I'm sure the game makes it if it doesn't exist anyways, you need this
script_scriptName
nothing more, nothing less.
Server.cs is a little different. It contains the script for your modification.
//CodegoesinthisYou can also put the main script in a different .cs file and keep server.cs to
exec("./yourscript.cs");
Part 2 - The beefFirst off, lets look at functions. They are probably the most common thing you'll find, as they are used for everything.
function test(%arg1, %arg2)
{
echo("This is a test");
}
This script prints a line into the console saying "This is a test". Now lets look at the arguments, %arg1 and %arg2.
Essentially, arguments are something you can put after the function when calling it from the console, so if I typed "test(herp derp);" in the console, it would print the line, but that's because we haven't done anything with the arguments yet. Lets try this.
function test(%arg1, %arg2)
{
echo("Argument one is" @ %arg1 @ ", while argument 2 is" @ %arg2 ".");
}
So now, if I put
test(herp derp"); in the console, it would say
Argument 1 is herp, while argument 2 is derp. Cool, huh? Arguments are essentially variables, which we will get into in the next section.
Lets try a servercmd. You know servercmds like /kick and /wand, right? Well you can make your own like this...
NOTE - The servercmd's first argument must always be %client. The game thinks the first argument is %client, anyway so if you put %derp for the first argument, it would work the same as %client. Just keep it as %client, though.
function serverCmdtest(%client, %arg1, %arg2)
{
echo("Argument 1 is" @ %arg1 @ ", while argument 2 is" @ %arg2 @ ".");
}Also, if you haven't figured it out yet, the @ symbol sticks pieces of text together. so "Herp" @ "derp" would print as "Herp derp".
It does essentially the same thing as test(herp derp);, but through a slash command. Very cool.
VariablesYou've already technically seen variables, because arguments are basically local variables.
First off, the two types of variables
%variable - Local variable. Can only be defined within a function. Only exists within the function. It usually can't be used anywhere but inside of the function.
$variable - Global variable. It can be defined both in and out of a function, and used within one. Example
$variable = "foo";
function foobar()
{
%var2 = "bar";
echo("derp" @ $variable @ %var2 " :D");
}
That saucy little number prints "derp foobar :D" into the console.
Now lets take a looksy-doo at defining variables.
Defining a global variable is as easy as pie.
$Global::Variable = "Global :D";
$Global::Variable::Number = 7;Text must be contained in quotation marks, while numbers can just be out there.
Global variables are about as easy, but require a function.
function local()
{
%localVariable = "Local :|";
%localVariableNumber = 8;
}
They work together quite well. For example, look at this simple math function, which will add $Global::Variable::number to %localVariableNumber...
function varMath()
{
%localVariableNumber = 8;
%ans = %localVariableNumber + $global::variable::number;
echo("Ans =" @ %ans @ ".");
}
Result - 15 printed into the console.
Lets do a function serverCmd with variables. But this time, lets define them with the command.
function serverCmdAdd(%client, %num1, %num2)
{
%answer = %num1 + %num2;
echo("Answer is" @ %answer ".");
}
Lets break this down.
First, the client types /add [number] [number]
Next, the function sets a local variable, called answer, to %num1 plus %num2.
Then, it prints in the client's console "Answer is [answer]."
Simple stuff, so far. Next, we'll be taking a look at things that are a bit more complicated.
The magical if and else statements Okay, so far we've looked at basics, functions and variables, but what if we want to check if a variable is the same as another one? Here's where the if statement comes in.
function serverCmdAdd(%client, %num1, %num2)
{
if(%num1 > 200)
{
echo("I'm not smart enough to add a number bigger than 200.");
}
else
{
%ans = %num1 + %num2;
echo("I KNOW THAT, IT'S" @ %ans "!");
}
}Lets just dive right into this one :)
Okay, the client types /add and then their numbers
then, the function checks if the first number is bigger than 200,
if it is, then it tells you that it's not smart enough.
if not, or ELSE, it sets the answer to a variable, and prints it into the console. Same as last time :D
Now, lets look at a more complicated function.
function serverCmdDivide(%client, %num1, %num2)
{
if(%num1 == 0)
{
echo("Division by 0 is impossible, man.");
}
else
{
if(%num2 == 0)
{
echo("Division by 0 is impossible, man.");
}
else
{
%ans = %num1 / %num2;
echo("Hey broham. Answer is" @ %ans @ ".");
}
}
}Woah, now lets take this one slow.
First, it sees if the first number is 0, if it is, it won't do the function.
Then, if not it goes merrily along and sees if the second number is 0.
If it is, it won't do the function.
If both those are not 0, then it will set the answer to a variable and echos it.
Same as last time.
More user friendly stuff.Up until now, we've been using echo to print text into the console. The problem with that is, it makes it look like the function doesn't work because the player doesn't immediately see the number. Lets do some messaging ;)
function serverCmdHelloWorld(%client)
{
messageClient(%client, '', "Hello, world!");
announce("Hello, world!");
}For the record, announce(); is the same as messageAll, but I just like Announce, so i'll use it for now.
Anyway, this tells the client, in chat, "Hello, world!", then announces it to the server.
Lets do another, hmm?
function serverCmdFurpDurp(%client, %var1)
{
if(%var1 > 64)
{
messageClient(%client, '', "Var1 is bigger than 64, i'm gonna go and do something else.");
%variable = 1234;
}
else
{
messageClient(%client, '', "Var1 isn't bigger than 64, i'm gonna sit here and listen like a good script");
listen();
}
}
function listen(0;
{
echo("I'm listening.");
}This one checks if %var1 is bigger than 64, if it is, it won't listen and will set a random var to 1234.
If not, it tells the client it's going to listen, then calls the function listen.
The function listen echos "I'm listening." into the console.
To be continued