• 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] GSC Modding Tutorial
#1
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
  Reply
#2
Nice tutorial...Now we need a variable list
[Image: wyipjqo9qon7rc2v1lo.jpg]
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TUTORIAL CHEAT ENGINE for mw3 [HARD] Tony. 5 4,293 10-24-2013, 15:22
Last Post: Tomsen1410
  [Request] Request for Assistance with Modding COD: BO using Mod Tools one1lion 9 6,068 09-17-2013, 21:04
Last Post: one1lion
  Help Modding Zombie Mode DarthKiller 3 4,486 07-09-2013, 21:08
Last Post: Nekochan
Question Tutorial addon! [HARD] Tony. 2 2,656 04-30-2013, 13:55
Last Post: [HARD] Tony.
  Why there are no modding for Frostbite Engine RaZ 2 3,085 03-30-2013, 17:14
Last Post: Pozzuh
  Modding online custom classes? jarniboi 0 2,423 03-12-2013, 00:21
Last Post: jarniboi
  [Tutorial] Modding Terraria Pozzuh 5 10,399 01-12-2013, 22:27
Last Post: Xeramon
  [TUTORIAL] Various Statements KrypTiK 2 2,608 01-07-2013, 21:00
Last Post: kokole
  Help Game Programming Tutorial Ich1994 8 4,331 01-01-2013, 21:21
Last Post: Ich1994
  [TUTORIAL] C# Introduction KrypTiK 4 3,031 12-30-2012, 10:06
Last Post: KrypTiK

Forum Jump:


Users browsing this thread: 1 Guest(s)