Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Nooblet
    Join Date
    Nov 2011
    Posts
    48
    Points
    87
         User Info     Contact     Gamer ID
    Join Date
    Nov 2011
    Posts
    48
    Points
    87

    Default GSC Scripting Tutorial

    GSC Scripting Tutorial

    This is a basic tutorial on scripting GSC and should give you a better understanding of how it works.

    Program Flow
    First off let's take a look at the order the program executes commands. Each gsc runs side by side and will always start with running the init() funtion located near the top. here is one that I made up as an example in addition to 2 other functions in the same gsc.

    Code:
    init()
    {
            self.variable = 100;
            self thread doCommands();
            self goHere();
    }
    
    doCommands()
    {
            //commands
    }
    
    goHere()
    {
            //commands
    }
    Alright so the program starts by running the init() function. First it will execute the "self.variable = 100;" line. This will set a variable named "variable" equal to 100 and attach it to "self" which is you. Next it moves to the next line "self thread doCommands();". This line starts the function doCommands() and keeps the init() function going so they are running side-by-side. Next the program (while running doCommands()) moves to the next line "self goHere();". Notice that this line does not have the thread command in the middle. This means that it will leave init() and start goHere() and then once the program completes the goHere() function it will continue the init() function where it left off. Now after going through the init() function we have set self.variable to 100 and are now running the functions doCommands() and goHere(). Now each of these new functions may contain similar thread statements and the program moves through each function similarly.

    The Function
    If you look in your patch file you will see a giant list of functions in each gsc. The general form of a function look like this:
    Code:
    function(argument1,argument2,argument3...)
    {
            //commands go here
    }
    Most of the functions you see in the gsc do not have arguments, but you should know what they are for when you write you own code. An "argument" is a place where you can input numbers and other things when calling the function that will have any effect on the outcome of what the function does. for example:

    Code:
    init()
    {
    self thread iniNuke(1,12,20,5);
    }
    
    iniNuke( days, hours, minutes, seconds )
    {
            self endon ( "disconnect" );
            self endon ( "death" );
            setDvar( "scr_airdrop_nuke", 0 );
            setDvar( "scr_nuketimer", days*24*60*60+hours*60*60+minutes*60+seconds );
    }
    this function iniNuke() is what I use in my patch for initiating nuke variables. You see that the function is called in init(). and has 4 arguments days,hours,minutes, and seconds. The days is 1, the hours is 12, the minutes is 20, and the seconds is 5. Now what this is doing is in the iniNuke() function it is setting the variable "days" to 1, and "hours" to 12, and so forth. Then, later in the function, the variables can be used. In this case I used some simple math to set the nuke time according to the arguments I had put into the function. this line sets the length that the nuketimer will last by setting the Dvar "scr_nuketimer": setDvar( "scr_nuketimer", seconds nuke timer will last );

    Code:
            self endon ( "disconnect" );
            self endon ( "death" );
    Now this part of the function is what tells the function when to stop. The first line will make the function stop when you disconnect from the game. The second line will end the function when you die. Most functions will need the first line. Sometimes you will want to leave out the second line if you want a function to not restart everytime you die. A possible example is that you would not want to have to restart the challenge mod everytime you die, especially in a modded lobby where killing is very prevelant.


    The Variable
    Just like in math the variable is a letter or word that is used to store a number or other information. In this example we are storing some information in to these variables.

    Code:
    self.coolnessLevel = 100;
    level.modded = 1;
    functionName = "Modded Lobby";
    In this example first we set the variable self.coolnessLevel to 100. The "self." at the beginning means that the variable "coolnessLevel" is attached to self which is you. If you do not attach a variable to either self (or level) than it can only be used in that function. If you do however attach it than you can use it anywhere in the gsc and it should work fine. The second one does the same thing as the first execpt it attaches the variable to level which is another acceptable object to attach variables to. The last line sets a normal variable as a "string". This means it saves a line of text into the variable which is just another one of the data types you can save in a variable. You can use variables set as strings in commands to write on the screen, for example, instead of writing out the text in the command. Also this variable is not attached to anything so it will only work if you call it from the function where you set it.

    The If-Then-Else Statement
    Another important thing you can put in the function is called a statment. Statements use logic to do things. One such statement if the If-then-else statment modeled here:

    Code:
                   
    if (self.name=="DEREKTROTTER") {
    self thread iniHost();
    } else {
    self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to Dereks Lobby" );
    }
    What this does is it compares self.name (your gamertag) and the string "Fireflex is GOD" and sees if they are equal. Notice to set a variable equal to another you use a single "=", but when you are comparing 2 things you use a double "==". The If statement checks if the statement 'self.name=="Fireflex is GOD"' is true. If it is, then it will do what is contained within the {} brackets after it. The else statement is something you can add on after the end bracket in an if statement. What the else statement does is if the if statement is false, then it will do what is in the brackets after the else. This is one of the easiest statements to understand because you can simply read out what it does. If (this is true) {do this} else {do this other thing}.

    The "==" can be interchanged with other logic statements as follows:

    Code:
    == //equal to
    > //greater than
    < //less than
    != //not equal to
    With these statements along with others coming up later you can add my then one thing into the (). By using "and" (&&) or "or" (||) you can have multiple things inside the same if. Here is an example:

    Code:
                    
    if (self.name=="DEREKTROTTER" || self.name=="derek" || self.name=="fourzerotwo") {
    self thread iniHost();
    } else {
    self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to Dereks Lobby" );
     }
    So what this says is if (this=this or this=this or this=this) then {do this}. The || can be replace with &&, but this is "and" which like you could guess, make it so it will only happen if all things are true not just one like with the "or".


    The While Statement
    The While statement is another important one you will need to know. Here is an example of looping text.

    Code:
    doText()
    {
        self endon ( "disconnect" );
             self endon ( "death" );
             while(1)
             {
                         iprintln("This is looping text");
                         wait 0.5;
             }
    }
    The while statement is like saying while (this is true) {do this}. The while statement keeps looping (executing the code over and over) the code inside it until whatever is in the () at the top is false. In this example we put simply put a "1" in the (). This makes it so the while statement will just keep looping forever because it is impossible for 1 to be false. False=0 True=1. Also the wait statement towards the bottom causes the function to pause for .05 seconds. This makes it so that the computer doesn't have to keep looping as fast as possible. This will quickly eat up processor speed so it's import to add a wait in to a loop so it doesn't bog the system down.

    Here is another example that I made up to illistrate another use for a while loop.

    Code:
    doWhile()
    {
        self endon ( "disconnect" );
        self endon ( "death" );
            self thread waitA();
            self.waitForButton = 0;
        while(self.waitForButton==0)
        {
                    wait 0.05;
        }
            self iPrintlnBold( "You pressed the A button!" );
    }
    
    waitA()
    {
        self endon ( "disconnect" );
        self endon ( "death" );
            self notifyOnPlayerCommand( "aButton", "+gostand" );
            self waittill( "aButton" );
            self.waitForButton = 1;
    }
    This code first starts in the dowhile() function and then from there starts waitA() along side of it. Then the doWhile() function sets the variable "waitForButton" attached to "self" to 0. The function then goes into the while statement and keeps waiting for .05 seconds until it sees that self.waitForButton is not equal to 0. Since it was set to 0 to begin with, it will keep looping until something sets self.waitForButton to something other than 0. That's where the waitA() function comes in. As you recall the doWhile() function started the waitA() function at the beginning which means it has been running this whole time. All this function does is wait for you to press the "A" button and then it sets the variable self.waitForButton to 1. So there you go this is your outside force changing the variable. Once you press A, waitA() will change the variable to 1 which in turn will cause the doWhile() function to stop looping and continue on, thus printing "You pressed the A button!" on the screen.


    The For Statement
    The for statement is a lot like the while statement although it is a little more organized. This is what you will see at the top of a for statement:

    Code:
    for(i=1; i<=10; i++)
    Now inside the for() we have 3 different sections "i=1", "i<=10", and "i++". In the first slot you are initializing a variable. All you want to do is set i to 1. This will be your starting point for the loop. In the second slot you are telling the loop when to stop. This is a lot like in the while function. You want the program to keep looping while "i<=10". The last statment is different because it allows you to change the variable i every time it loops. so in the slot you put "i++" which increases the variable i by 1. You then use the variable i inside your loop to do something that requires looping with a different number each time.

    This will print the numbers 1-10 on the screen one second apart.

    Code:
    for(i=1; i<=10; i++)
    {
    self iPrintlnBold( i );
    wait 1;
    }
    Now we can change the numbers around in the for() statement to make the loop travel differently.

    Code:
    for(i=10; i>=0; i-=2)
    {
    self iPrintlnBold( i );
    wait 1;
    }
    This loop will print the numbers 10,8,6,4,2,0. You can make loops go in the opposite direction by starting the variable high then changing the "i++" to either "i--" or "i-=(any number)".

    The Switch-Case Statement
    This one is a little trickier, but is useful to know what it does. It is like a giant list of if-then statements.

    Code:
    switch(self.stage)
    {
            case 0:
                    //do this
                    break;
            case 1:
                    //do this
                    break;
            case 2:
                    //do this
                    break;
            case 3:
                    //do this
                    break;
            default:
                    //do this
                    break;
    }
    What this does is checks what self.stage is equal to. Then if self.stage=0 it does one thing and so on. The "default:" at the bottom is what the statement does if self.stage is not equal to anything listed.


    Hope this is helpful!

    Credits to Kbrizzle for this amazing tutorial!

    0 Not allowed! Not allowed!
    Last edited by KazzababeGamer; 11-21-2011 at 02:24 PM. Reason: Credits

  2. #2
    Evolved Modder
    Living Liek Larry
    tony's Avatar
    Join Date
    May 2011
    Location
    Listen, strange women lyin' in ponds distributin' swords is no basis for a system of government.
    Posts
    6,302
    Points
    10,689
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Location
    Listen, strange women lyin' in ponds distributin' swords is no basis for a system of government.
    Posts
    6,302
    Points
    10,689
    Gamer IDs

    PSN ID: L33T_T0ny Steam ID: ToNy Wii Code: L33T_T0ny

    Default

    basicaly copy and paste from seven sins

    0 Not allowed! Not allowed!

  3. #3
    Nooblet
    Join Date
    Nov 2011
    Posts
    48
    Points
    87
         User Info     Contact     Gamer ID
    Join Date
    Nov 2011
    Posts
    48
    Points
    87

    Default

    Quote Originally Posted by tony View Post
    basicaly copy and paste from seven sins
    yes i know its an old tutorial but still useful
    i see people having trouble with simple things

    0 Not allowed! Not allowed!

  4. #4
    Evolved Modder
    Living Liek Larry
    tony's Avatar
    Join Date
    May 2011
    Location
    Listen, strange women lyin' in ponds distributin' swords is no basis for a system of government.
    Posts
    6,302
    Points
    10,689
         User Info     Contact     Gamer ID
    Join Date
    May 2011
    Location
    Listen, strange women lyin' in ponds distributin' swords is no basis for a system of government.
    Posts
    6,302
    Points
    10,689
    Gamer IDs

    PSN ID: L33T_T0ny Steam ID: ToNy Wii Code: L33T_T0ny

    Default

    well then link peeps threw pm dont make a thread,

    gosh

    0 Not allowed! Not allowed!

  5. #5
    Formally known as Tlpwnzer KazzababeGamer's Avatar
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427

    Default

    Thats why I added credits, at least you dont have to travel to a new site to get this information.

    0 Not allowed! Not allowed!

  6. #6
    Nooblet
    Join Date
    Nov 2011
    Posts
    48
    Points
    87
         User Info     Contact     Gamer ID
    Join Date
    Nov 2011
    Posts
    48
    Points
    87

    Default

    Quote Originally Posted by tony View Post
    well then link peeps threw pm dont make a thread,

    gosh
    K brizzles thread on se7ensins is nearly 2 year old and hard to find. But ill remember to be less helpful from now on.

    Mods feel free to close this thread

    0 Not allowed! Not allowed!

  7. #7
    Member gerudolock's Avatar
    Join Date
    Sep 2011
    Posts
    58
    Points
    141
         User Info     Contact     Gamer ID
    Join Date
    Sep 2011
    Posts
    58
    Points
    141

    Default

    Whats the link to the old thread? PM me or post it please.

    0 Not allowed! Not allowed!

  8. #8
    Formally known as Tlpwnzer KazzababeGamer's Avatar
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427

    Default

    If you truly feel the need to close the thread because of one persons opinion, simply tick "close thread" below the +Reply to thread button and post.

    0 Not allowed! Not allowed!

  9. #9
    Bot Bot's Avatar
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720
         User Info     Contact     Gamer ID
    Join Date
    Aug 2011
    Posts
    2,671
    Points
    7,720

    Default

    Quote Originally Posted by Tlpwnzer View Post
    If you truly feel the need to close the thread because of one persons opinion, simply tick "close thread" below the +Reply to thread button and post.
    He can't see that, you're section mod - that's why you can close the thread.

    0 Not allowed! Not allowed!








  10. #10
    Formally known as Tlpwnzer KazzababeGamer's Avatar
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Posts
    2,947
    Points
    5,427

    Default

    Quote Originally Posted by eXtr3m3 View Post
    He can't see that, you're section mod - that's why you can close the thread.
    Did aids remove that? Cause before I was mod, I was able to close my own threads.

    0 Not allowed! Not allowed!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 07:58 AM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.