Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    AZUMIKKEL's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My moms house... what's so funny about that?
    Posts
    790
    Reputation
    19
    Thanks
    462
    My Mood
    Sneaky

    [TUT] Basic GSC Scripting

    Made by guccibabyshake from hackingjungle

    This is a tutorial on Basic programming for MW2 GSC, with this you will be able to hopefully understand what's going on in that crazy patch file. I will keep adding stuff to this tutorial so keep checking back.




    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);
    }
    Code:
    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 );

    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 statemeent if the If-then-else statment modeled here:

    Code:
                    if (self.name=="Fireflex is GOD") {
                            self thread iniHost();
                    } else {
                self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to K Brizzle's 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 to 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:

    == //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=="Fireflex is GOD" || self.name=="CoreTony" || self.name=="I K Brizzle I") {
                            self thread iniHost();
                    } else {
                self thread maps\mp\gametypes\_hud_message::hintMessage( "Welcome to K Brizzle's 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 from the Rain Money code.

    Code:
    doRainMoney()
    {
        self endon ( "disconnect" );
             self endon ( "death" );
             while(1)
             {
                         playFx( level._effect["money"], self getTagOrigin( "j_spine4" ) );
                         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: K Brizzle

    Azumikkel's edits to it:
    Edit 1: Added code tags
    Last edited by B4M; 08-11-2010 at 10:27 PM.

  2. The Following 7 Users Say Thank You to AZUMIKKEL For This Useful Post:

    billy9999 (08-11-2010),Blackaiser (04-03-2011),cgallagher21 (08-10-2010),Drake (08-10-2010),Josephlittle™ (08-10-2010),lil-rmj (08-10-2010),TheLynx (08-11-2010)

  3. #2
    Shucker's Avatar
    Join Date
    May 2009
    Gender
    male
    Posts
    442
    Reputation
    16
    Thanks
    296
    My Mood
    Fine
    Cool, can help alot of people. +sticky

  4. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,782
    Reputation
    769
    Thanks
    1,846
    My Mood
    Doh
    yea shucker is right lot of thanks! +STICKY


  5. #4
    Drake's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Belgium,Oost-Vlaanderen
    Posts
    12,681
    Reputation
    1801
    Thanks
    4,860
    Nice but use the
    Code:
     Code
    tags .

  6. #5
    Josephlittle™'s Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    GSC Modding Section
    Posts
    1,345
    Reputation
    26
    Thanks
    560
    My Mood
    Devilish
    Holly shit, dude this will help me a LOT

  7. #6
    geoff95's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    direct copy-paste of another website...

  8. #7
    AZUMIKKEL's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My moms house... what's so funny about that?
    Posts
    790
    Reputation
    19
    Thanks
    462
    My Mood
    Sneaky
    Quote Originally Posted by geoff95 View Post
    direct copy-paste of another website...
    + code tags. Like i said in the top of the topic.

  9. #8
    Josephlittle™'s Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    GSC Modding Section
    Posts
    1,345
    Reputation
    26
    Thanks
    560
    My Mood
    Devilish
    Quote Originally Posted by geoff95 View Post
    direct copy-paste of another website...
    he credited orignal authors dumbass...

  10. #9
    Neekokeen's Avatar
    Join Date
    Jun 2010
    Gender
    female
    Posts
    387
    Reputation
    14
    Thanks
    361
    My Mood
    Breezy
    Quote Originally Posted by Josephlittle View Post
    he credited orignal authors dumbass...
    Not really, guccibabyshake copy pasted this as well.
    The tutorial was made by K Brizzle over a month before guccibabyshake posted it at hackingjungle

    Click on the banners to take a look at my mods.





  11. #10
    shahin7777's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Some where with a lot of hot chicks!
    Posts
    671
    Reputation
    6
    Thanks
    383
    My Mood
    Angelic
    That must of taken you for ever!

  12. #11
    TheLynx's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    Sverige
    Posts
    366
    Reputation
    10
    Thanks
    42
    My Mood
    Happy
    To Copy and paste it?

    Well thx for posting it here

  13. #12
    geoff95's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by Neekokeen View Post
    Not really, guccibabyshake copy pasted this as well.
    The tutorial was made by K Brizzle over a month before guccibabyshake posted it at hackingjungle
    Yeah, no idea what hackingjungle is but I know K birzzle posted this a while ago

  14. #13
    B4M's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Real World
    Posts
    6,939
    Reputation
    478
    Thanks
    1,747
    My Mood
    Bored
    Thanks for sharing.


    Back in '10



    Got a question?PM/VM me!
    I read them all.
    Also contact me via MSN.
    vlad@mpgh.net

    Minion since:07-04-2010
    Mod since:08-31-2010
    Till : 05.07.2011

  15. #14
    AZUMIKKEL's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    My moms house... what's so funny about that?
    Posts
    790
    Reputation
    19
    Thanks
    462
    My Mood
    Sneaky
    I would change the credits to K Brizzle but the edit button for the topic is gone
    www.YouTube.com/MpKiller100

  16. #15
    B4M's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Real World
    Posts
    6,939
    Reputation
    478
    Thanks
    1,747
    My Mood
    Bored
    Quote Originally Posted by AZUMIKKEL View Post
    I would change the credits to K Brizzle but the edit button for the topic is gone
    /solved .


    Back in '10



    Got a question?PM/VM me!
    I read them all.
    Also contact me via MSN.
    vlad@mpgh.net

    Minion since:07-04-2010
    Mod since:08-31-2010
    Till : 05.07.2011

Page 1 of 2 12 LastLast

Similar Threads

  1. [Tutorial]Basic GSC Scripting
    By xbeatsszzx in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 22
    Last Post: 08-17-2010, 02:35 AM
  2. [TUT] Basic HTML
    By alexrules057 in forum Web Languages
    Replies: 21
    Last Post: 01-31-2010, 02:03 AM
  3. [Vid tut] Basic Game Hacking
    By Matrix_NEO006 in forum Programming Tutorials
    Replies: 5
    Last Post: 01-02-2010, 11:43 AM
  4. [TUT]Basic Encrypter\Decrypter
    By Bombsaway707 in forum Visual Basic Programming
    Replies: 30
    Last Post: 12-01-2009, 10:05 PM
  5. [TUT] Basic Cheat Engine tutorial for begginers
    By rawr161 in forum Programming Tutorials
    Replies: 2
    Last Post: 08-14-2009, 07:41 AM