ItsMods
[Tutorial] GSC Modding Tutorial - Printable Version

+- ItsMods (https://www.itsmods.com)
+-- Forum: Archive (https://www.itsmods.com/Forum-Archive.html)
+--- Forum: Archive (https://www.itsmods.com/Forum-Archive--64.html)
+--- Thread: [Tutorial] GSC Modding Tutorial (/Thread-Tutorial-GSC-Modding-Tutorial.html)



GSC Modding Tutorial - Killingdyl - 12-25-2010

Tutorial for the xmas Giveaway

Basic GSC Modding:

Code Flow:
Code:
Example(arg1, arg2) { //Single Line Comment /* Block Comment */ /* Part 1 */ self endon("disconnect"); /* Part 2 */ if( variable == 1 ) self function1(); else if( variable == 2) self thread function2(); /* Part 3 */ if( variable == 1 ){ self function1(); }else if( variable == 2){ self thread function2(); }else{ return; } /* Part 4 */ while(test equation) { break; } /* Part 5 */ for(i = 0; i < 10; i++) { if(something == true) continue; } /* Part 6 */ switch(variable) { case condition1: break; case condition2: case condition3: doTest(); case condition4: doStuff(); break; default: return; } wait 1; }

Ok, time to break that down. To make your own gsc, you will most likely have to create your own function. Functions can have any number of arguments.

Part 1: Endon
Endon functions are very important, it terminates the function whenever the object is notified that specific string. Custom endon functions can look like this
Code:
self endon("TheModdingSanctuaryIsTheBest"); self notify("TheModdingSanctuaryIsTheBest");

Part 2: the If-ElseIf Statement
Code:
self function1();
Runs function1 and when that function is done, it continues the current function. While,
Code:
self thread function2();
Runs function2 AT THE SAME TIME as the current function.

Part 3: just shows that for if statements, you can brackets. However if you are doing more than 1 thing, you Must have brackets.

Part 4: the While Loop.

As long as the test equation is true, the code will run. For a never ending loop, the test equation can be 1.
Code:
break;
If in a for loop or while loop, this function is called, the loop is broken.

Part 5: the For Loop.
The first part of the argument is defining a variable, the second part is the test equation, and the third part is what to do for each loop.
Code:
continue;
If in a for loop or while loop, this function is called, the loop skips the rest of the functions within that loops and starts over.

Part 6: the Switch
Switch statements are great alternatives to gigantic if statements. It takes the variable and checks for the cases.
Code:
switch(variable) { case condition1: break; - does nothing and exits the switch case condition2: - falls down through condition 3 case condition3: doTest(); - for both cases, does this function. Since there isnt a break, condition 2 and 3 falls down through condition 4 case condition4: doStuff(); break; default: - any other case return; - ends function prematurely }

Code:
return; - ends function prematurely return variable; - returns the variable and ends the function.

Code:
wait 1;
Waits for 1 second, this is important in infinite loops to keep from major lags.

The 2 lines you see at the top are comments, any lines commented out will not be executed. Comments are there merely for reference, or to take notes.

NOTE: All functions end with a semicolon ";"
Variables:
Variables in gsc does not have to be defined by type like in more complex scripts neither does it have to be defined before use.
There are only 4 types of variables in GSC coding.
Code:
Int - Integer (5, 0, -5) Float - Decimal number (5.6034) String - Text String ("Hi") Boolean - True or False int(string) turns a string "1" to the integer 1
There are different ways variables stored in gsc
Code:
self.variable = "Killingdyl"; - stores the variable attached to whatever self is, most of the time its a player level.variable = "TheModdingSanctuary"; - stores the variable to the level, resets if map_restart(true); functionvariable = ::function; - stores a function into a variable position = (x, y, z); - position is an array with 3 values angle = (pitch, yaw, roll); - angle is an array with 3 values array = []; - defines an array, doing this will clear any previous values inside the array array[value] = []; - defines multi-dimensional arrays, clears any previous values.
To call the functionvariable you do it like this
Code:
[[functionvaraible]](arguments);
Variables are used in if-else statements. You can use the following evaluators.
Code:
== - equal to != - not equal to > - greater than < - less than >= - greater than or equal to <= - less than or equal to && - and || - or
For variables that are defined true or false, in if statements you can use the following.
Code:
if(variable) - this is the same as if(variable == true) if(!variable) - this is the same as if(variable == false) true == 1 and false == 0

Now some fun ways to transfer variables is going back to the self notify function.
Code:
self notify("TMS", "TMS IS", 1, "Killingdyl is", 1, true);
This will notify yourself TMS. You can catch the notify by using a waittill.

Code:
self waittill("TMS");
Now any code after this line will not be executed until you are notified the string. This can be expanded to retrieve variables too.

Code:
self waittill("TMS", string, int, player, int2, bool);
Now you can use those variables.

More tutorials and useful information .............Here


RE: GSC Modding Tutorial - alistair3149 - 12-26-2010

Nice tutorial...Now we need a variable list