Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    xbeatsszzx's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Behind a dumpster jerking off. xD jks
    Posts
    2,520
    Reputation
    13
    Thanks
    1,495
    My Mood
    Asleep

    [Tutorial]Basic GSC Scripting

    This is a tutorial on Basic programming for MW2 GSC, with this you will be able to hopefully understand what's going on in those .gsc files which should help you to create you own Mw2 Mods one day [IMG]http://www.i**********.com/forum/public/style_emoticons/default/smile.gif[/IMG]

    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 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:

    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=="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) 
    { 
            case0: 
                    //do this 
                    break; 
            case1: 
                    //do this 
                    break; 
            case2: 
                    //do this 
                    break; 
            case3: 
                    //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.

    That's it ! Now enjoy

    Remember to Thank if i helped u.
    I Am on this site for the mods for mw2 ONLY. Not hacks.

  2. The Following 3 Users Say Thank You to xbeatsszzx For This Useful Post:

    christophergonzalez (08-16-2010),govand95 (06-18-2011),tank2800 (08-16-2010)

  3. #2
    dheir's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    Florida
    Posts
    376
    Reputation
    13
    Thanks
    228
    My Mood
    Amused
    Nice tut, consider elaborating on the The Switch-Case Statement.
    Some may or may not know how to define each case.

  4. #3
    GrenadeLaunchers's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    88
    Reputation
    10
    Thanks
    10
    Must have taken you forever and your coloring... gj.

  5. #4
    xbeatsszzx's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Behind a dumpster jerking off. xD jks
    Posts
    2,520
    Reputation
    13
    Thanks
    1,495
    My Mood
    Asleep
    Quote Originally Posted by dheir View Post
    Nice tut, consider elaborating on the The Switch-Case Statement.
    Some may or may not know how to define each case.
    ye it kinda did take pretty long..but thnx
    I Am on this site for the mods for mw2 ONLY. Not hacks.

  6. #5
    tank2800's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Posts
    23
    Reputation
    10
    Thanks
    3
    My Mood
    Fine
    good job this helped a lot

  7. #6
    Crazyelfjj's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Different from the last time.
    Posts
    111
    Reputation
    10
    Thanks
    10
    My Mood
    Relaxed
    I remember seeing this on nextgenupdate/im00... Are you the said thread owner?

    *Edit* Found said copy and paste with 2 mins of searching... Here (First one)
    Last edited by Crazyelfjj; 08-16-2010 at 01:27 PM.





    Afraid to ask a question? Did you did your research? If so, ask away! If not... you should be afraid.

  8. #7
    christophergonzalez's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Posts
    154
    Reputation
    10
    Thanks
    8
    Helped me alot thx..

  9. #8
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,820
    Reputation
    781
    Thanks
    1,857
    My Mood
    Doh
    lol in im00 is the same!!!!!

  10. #9
    Crazyelfjj's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Different from the last time.
    Posts
    111
    Reputation
    10
    Thanks
    10
    My Mood
    Relaxed
    Quote Originally Posted by AcE.bu50t View Post
    lol in im00 is the same!!!!!
    Thanks for hitching the ride wit me





    Afraid to ask a question? Did you did your research? If so, ask away! If not... you should be afraid.

  11. #10
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,820
    Reputation
    781
    Thanks
    1,857
    My Mood
    Doh
    Quote Originally Posted by Crazyelfjj View Post
    Thanks for hitching the ride wit me
    lol np.....

  12. #11
    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
    www.YouTube.com/MpKiller100

  13. #12
    Crazyelfjj's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Different from the last time.
    Posts
    111
    Reputation
    10
    Thanks
    10
    My Mood
    Relaxed


    (Invisible filler, +1 thank if you find this)





    Afraid to ask a question? Did you did your research? If so, ask away! If not... you should be afraid.

  14. #13
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,820
    Reputation
    781
    Thanks
    1,857
    My Mood
    Doh
    Quote Originally Posted by Crazyelfjj View Post


    (Invisible filler, +1 thank if you find this)
    i found the invisible filler!!!!!

  15. The Following User Says Thank You to ♪~ ᕕ(ᐛ)ᕗ For This Useful Post:

    Crazyelfjj (08-16-2010)

  16. #14
    Crazyelfjj's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Different from the last time.
    Posts
    111
    Reputation
    10
    Thanks
    10
    My Mood
    Relaxed
    Quote Originally Posted by AcE.bu50t View Post
    i found the invisible filler!!!!!
    Fine, you got your reward as promised.





    Afraid to ask a question? Did you did your research? If so, ask away! If not... you should be afraid.

  17. #15
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    8,820
    Reputation
    781
    Thanks
    1,857
    My Mood
    Doh
    Quote Originally Posted by Crazyelfjj View Post
    Fine, you got your reward as promised.
    yeaaaaaaaa

Page 1 of 2 12 LastLast

Similar Threads

  1. [TUT] Basic GSC Scripting
    By AZUMIKKEL in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 18
    Last Post: 08-12-2010, 08:04 AM
  2. [Tutorial]Basic Spammer
    By Spook in forum Visual Basic Programming
    Replies: 31
    Last Post: 08-09-2010, 05:31 PM
  3. [Tutorial] Basic C++ Console hack
    By Erinador in forum C++/C Programming
    Replies: 12
    Last Post: 02-27-2010, 01:44 AM
  4. Creating a Basic Captcha script
    By Ugleh in forum Web Languages
    Replies: 5
    Last Post: 02-22-2010, 01:28 PM
  5. [Tutorial] Basic user I/O
    By PlSlYlClHlO in forum C++/C Programming
    Replies: 6
    Last Post: 06-18-2009, 01:47 AM