Post: Tutorial: How to code GSC. Section 1: the basics
01-07-2012, 04:18 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Now you have started to read this because you are wanted to code your own mods in gsc. This will be chapter 1, and may be updated.

Basic Information Needed to Know
There are 3 type of pre-definited variables, or "world variables".

    Level

This refers to the game when it loads, it's the whole "world" so to speak. It affects everything in game.

    Player

is in level.players. to call a player such thing would be like.
    
foreach(player in level.players)
{
player doThread();
}


    Self

This refers to the object that was in execution. It means that if you/object executed a thread/function and it used the self variable only you/object called could see it.

Here are some good codes to also know

    name

This retrieves a player's name on the server. It can be used as player.name, self.name or a custom variable.name if it is defined.

    isHost

This is nice to know, and only allows if user is host. such as:
self isHost()

Symbols and Includes
    
> means more than
< means less than
= means equals
>= means more than or equal
<= means less than or equals
!= means not equal
|| means or
&& means and


More Words/Commands
    
break; means terminate/end
return; means terminate and reurn to called function
continue; means continue


Creating Threads
Threads are pieces of coding, used to define/execute code, or to create a function.

In this example, we will tell the code to execute a thread.

    
OnPlayerSpawned();
self thread customthread();


now this mean when the player is spawned it run run a custom thread for "yourself"

Now this can be created anywhere in a blank space of your patch.

    
customthread()
{
self iPrintlnBold(self.name);
}


Now at the top is the thread name. Anything inside the brackets define what the thread does. in chronological order. This code in the case prints your name out on the middle of the screen. the ";" ends the command.

Creating Variables
The next thing were going to be learning is variables. Variables are a defined piece of code that can be called, and retrieved.

There are 3 types of values that can be assigned to variables.

    Numeric

This assign's a value only retrievable by a number.
ex: self.age = 17;

    Character

This assigns a value of text
ex: self.name = "satanichispanic";

    True/False

This assigns a true false value (mostly used in toggles)
ex: self.vip = false;

Naming your variables is quite easy, just make sure you call and retrieve the same variable you want to use. for example.

    
OnPlayerSpawned();
self.vip = false;
self thread VIP();


    
VIP()
{
self.vip = true;
}


Assigned controlled variables to a function
Now this can be a quite tricky but is very easy once you get the hang of it. These are defined by the patch creator, but can easily be used in later stuff :p

to start off this will be a function

we will use a basic text display, the variable we will be using is "text", and "title"

    
message( title, text ) // this tells what the variables will be when called.
{
message = spawnstruct();
message.titleText = title;
message.notifyText = text;
message.glowColor = (256, 256, 256);
self thread maps\mp\gametypes\_hud_message::notifyMessage( message );
}


that is just the function lets say on player spawned again..

    
OnPlayerSpawned();
self thread message( "Hello There", "This is the sub text" );


Hello there is the title, and sub text is the sub text Smile That way you can use it more than once.

If then statements
If then statements are only used if it is a certain thing you want to happen

Equal to statemtents
These are basic statements.

    
if (self.name == "Bob" || self.name == "Ryan" || self.name == level.host)
{
self.host = true;
}else{
self.host = false;
}


This checks if your name is one of them, or the host. If it is true you are admin.

|| means or, and == means absolutely equal too (that's what I think of it as)


Other if then statements

not equal
    
if (self.host != true)
{
self iPrintlnBold("You are not host!");
}


equal or greater
    
if (self.age <= 12)
{
self thread message( "GTFO", "Your 12 or under" );
}else if (self.age >= 13){
self thread message( "Congrats", "Your 13 or over" );
}



Loops
Loops allow something to repeat any amount of times.

It's is used with the while command. which is kinda like saying do this while doing that.

    
self thread message( "Hello There", "Welcome" );
while(1)
{
self iPrintlnBold("Hello NOOB");
}
//more coding


This prints hello noob, while doing the upper command

Arrays

Arrays are good, and can be used to create many things. To start off (yes this is how mod menu's work, and how gun game works, I can re-code gun game ;O )

    
arraythingy()
{
i = 0; //this is the variable

self.name[0] = "Bob";
self.name[1] = "Ryan";
self.name[2] = "Jenna";
self.name[3] = "Jessica"; //these are the what happens when the variable is changed.

self notifyOnPlayerCommand("change", "+actionslot 4");

for(;Winky Winky
{
self waittill("change"); //when he pressess actionslot 4
i++; //this will increate by 1 value of the array
self iPrintlnBold(self.name[i]); //this will print self.name and i is the variable 0 - 3.
}
}


Cases
Cases are easier to manager rather than have 1000000+ if/then statements

we will use the self.name example from before
    
case()
{
switch(self.name)
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


as you can see you can make it returns value, and it changes like that.

You can even get more advanced using a random integer
    
case()
{
switch(randomint(20)) //picks a random number between 1 - 20
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


But lets say you want a "range" of something it can also be returned that way.

    
switch(randomintrange(2, 4)) //picks only between 2 and 4
{
case 0:
//do something
case 1:
//do something
case 2:
// picked by randomint range
case 3:
// etc..
}


Edit:
The script of the array and the case, are right, but not practical. Here are better examples:

Array:
    
arraythingy()
{
self.array = [];
self.array[0] = "Value 1";
self.array[1] = "Value 2";
self.array[2] = "Value 3";
for(i = 0; i < 3Winky Winky //sets the default value for i as 0. It makes sure i doesn't go over 3.
{
self waittill("up");
i++;
self iPrintlnBold("Your Value" + i);
}
}


New Case:
    
//dvars can be monitored and changed as well
casethingy()
{
switch(getDvar("mapname")) //don't know if mapname is exact or if it's level.map w/e we can't remember everything :p
{
case "mp_afghan":
self thread Modz::afghan();
break;
case "mp_rust":
self thread Modz::rust();
break;
}
}


Now im going to more in depth on this.

break; ends the code. The thread is done, untill it's reloaded. This is mainly used for map mods. To shorten map creation you can use the return or continue function.

for example if you wanted to get a specific value you would use return to shorten code. For example.

    
caseStatus()
{
switch(self.name)
{
case SatanicHispanic:
self.status = "host";
return;

case otherUser:
self.status = "vip";
return;
}

if(self.status == "host")
{
self thread hostOnly();
}else if(self.status == "vip"){
self thread vipOnly();
}else{
self thread noStatus();
}

}


as you can see that is like 2-3 functions in 1. It gets a value, and then returns to the function to finish it up. Easily used for status's, or however you want. I think that explained things a little more. Smile

Now I hoped you enjoyed this tutorial, and it helped you a little. If you have any questions ask me.

I will update with anymore you think I should include/ you need help with.

Hope you enjoyed this!
Last edited by Jakes625 ; 02-26-2012 at 02:35 AM.

The following 30 users say thank you to Jakes625 for this useful post:

ResistTheMoon, 247Yamato, aerosoul94, BAMF, Ben, BvB-09r-_-N!c0, Clouds, Darth Maul, DEREKTROTTER, FAKA_ELITE, Freezinskull, GodDrinksPepsi, HDMODDER, zL_j8hnb, KCxFTW, KingcreekS, Kush Friendly, User23434, NeedaLifeSoon, o-xDaMaGeDx-o, PussayPatrol, Rainbow Gravity, Teamrider, Tidus., Vampytwistッ, Vanz, xChronicModz, xVz, zUnboundPatcher
01-07-2012, 05:37 AM #2
Originally posted by SatanicHispanic View Post
Now you have started to read this because you are wanted to code your own mods in gsc. This will be chapter 1, and may be updated.

Basic Information Needed to Know
There are 3 type of pre-definited variables, or "world variables".

    Level

This refers to the game when it loads, it's the whole "world" so to speak. It affects everything in game.

    Player

This refers to the common "player". Basically it means only the player selected from a function can only see this.

    Self

This refers to yourself. It means that if you executed a thread/function and it used the self variable only you could see it.

Here are some good codes to also know

    name

This retrieves a player's name on the server. It can be used as player.name, self.name or a custom variable.name if it is defined.

    isHost

This is nice to know, and only allows if user is host. such as:
self isHost()

Symbols and Includes
    
> means more than
< means less than
= means equals
>= means more than or equal
<= means less than or equals
!= means not equal
|| means or
&& means and


More Words/Commands
    
break; means terminate/end
return; means terminate and reurn to called function
continue; means continue


Creating Threads
Threads are pieces of coding, used to define/execute code, or to create a function.

In this example, we will tell the code to execute a thread.

    
OnPlayerSpawned();
self thread customthread();


now this mean when the player is spawned it run run a custom thread for "yourself"

Now this can be created anywhere in a blank space of your patch.

    
customthread()
{
self iPrintlnBold(self.name);
}


Now at the top is the thread name. Anything inside the brackets define what the thread does. in chronological order. This code in the case prints your name out on the middle of the screen. the ";" ends the command.

Creating Variables
The next thing were going to be learning is variables. Variables are a defined piece of code that can be called, and retrieved.

There are 3 types of values that can be assigned to variables.

    Numeric

This assign's a value only retrievable by a number.
ex: self.age = 17;

    Character

This assigns a value of text
ex: self.name = "satanichispanic";

    True/False

This assigns a true false value (mostly used in toggles)
ex: self.vip = false;

Naming your variables is quite easy, just make sure you call and retrieve the same variable you want to use. for example.

    
OnPlayerSpawned();
self.vip = false;
self thread VIP();


    
VIP()
{
self.vip = true;
}


Assigned controlled variables to a function
Now this can be a quite tricky but is very easy once you get the hang of it. These are defined by the patch creator, but can easily be used in later stuff :p

to start off this will be a function

we will use a basic text display, the variable we will be using is "text", and "title"

    
message( title, text ) // this tells what the variables will be when called.
{
message = spawnstruct();
message.titleText = title;
message.notifyText = text;
message.glowColor = (256, 256, 256);
self thread maps\mp\gametypes\_hud_message::notifyMessage( message );
}


that is just the function lets say on player spawned again..

    
OnPlayerSpawned();
self thread message( "Hello There", "This is the sub text" );


Hello there is the title, and sub text is the sub text Smile That way you can use it more than once.

If then statements
If then statements are only used if it is a certain thing you want to happen

Equal to statemtents
These are basic statements.

    
if (self.name == "Bob" || self.name == "Ryan" || self.name == level.host)
{
self.host = true;
}else{
self.host = false;
}


This checks if your name is one of them, or the host. If it is true you are admin.

|| means or, and == means absolutely equal too (that's what I think of it as)


Other if then statements

not equal
    
if (self.host !== true)
{
self iPrintlnBold("You are not host!");
}


equal or greater
    
if (self.age <= 12)
{
self thread message( "GTFO", "Your 12 or under" );
}else if (self.age >= 13){
self thread message( "Congrats", "Your 13 or over" );
}



Loops
Loops allow something to repeat any amount of times.

It's is used with the while command. which is kinda like saying do this while doing that.

    
self thread message( "Hello There", "Welcome" );
while(1)
{
self iPrintlnBold("Hello NOOB");
}
//more coding


This prints hello noob, while doing the upper command

Arrays

Arrays are good, and can be used to create many things. To start off (yes this is how mod menu's work, and how gun game works, I can re-code gun game ;O )

    
arraythingy()
{
i = 0; //this is the variable

self.name[0] = "Bob";
self.name[1] = "Ryan";
self.name[2] = "Jenna";
self.name[3] = "Jessica"; //these are the what happens when the variable is changed.

self notifyOnPlayerCommand("change", "+actionslot 4");

for(;Winky Winky
{
self waittill("change"); //when he pressess actionslot 4
i++; //this will increate by 1 value of the array
self iPrintlnBold(self.name[i]); //this will print self.name and i is the variable 0 - 3.
}
}


Cases
Cases are easier to manager rather than have 1000000+ if/then statements

we will use the self.name example from before
    
case()
{
switch(self.name)
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


as you can see you can make it returns value, and it changes like that.

You can even get more advanced using a random integer
    
case()
{
switch(randomint(20)) //picks a random number between 1 - 20
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


But lets say you want a "range" of something it can also be returned that way.

    
switch(randomintrange(2, 4)) //picks only between 2 and 4
{
case 0:
//do something
case 1:
//do something
case 2:
// picked by randomint range
case 3:
// etc..
}


Now I hoped you enjoyed this tutorial, and it helped you a little. If you have any questions ask me.

I will update with anymore you think I should include/ you need help with.


If this gets 25 thanks, I'll release how to create a mod menu, and you won't have to rely on stealing it off of craigschrist, or elite mossy, dconners... etc..

Hope you enjoyed this!

Did you write this yourself?
Also don't ask 4 thanks
01-07-2012, 05:40 AM #3
PussayPatrol
I'm a neat monster...
Originally posted by SatanicHispanic View Post
Now you have started to read this because you are wanted to code your own mods in gsc. This will be chapter 1, and may be updated.

Basic Information Needed to Know
There are 3 type of pre-definited variables, or "world variables".

    Level

This refers to the game when it loads, it's the whole "world" so to speak. It affects everything in game.

    Player

This refers to the common "player". Basically it means only the player selected from a function can only see this.

    Self

This refers to yourself. It means that if you executed a thread/function and it used the self variable only you could see it.

Here are some good codes to also know

    name

This retrieves a player's name on the server. It can be used as player.name, self.name or a custom variable.name if it is defined.

    isHost

This is nice to know, and only allows if user is host. such as:
self isHost()

Symbols and Includes
    
> means more than
< means less than
= means equals
>= means more than or equal
<= means less than or equals
!= means not equal
|| means or
&& means and


More Words/Commands
    
break; means terminate/end
return; means terminate and reurn to called function
continue; means continue


Creating Threads
Threads are pieces of coding, used to define/execute code, or to create a function.

In this example, we will tell the code to execute a thread.

    
OnPlayerSpawned();
self thread customthread();


now this mean when the player is spawned it run run a custom thread for "yourself"

Now this can be created anywhere in a blank space of your patch.

    
customthread()
{
self iPrintlnBold(self.name);
}


Now at the top is the thread name. Anything inside the brackets define what the thread does. in chronological order. This code in the case prints your name out on the middle of the screen. the ";" ends the command.

Creating Variables
The next thing were going to be learning is variables. Variables are a defined piece of code that can be called, and retrieved.

There are 3 types of values that can be assigned to variables.

    Numeric

This assign's a value only retrievable by a number.
ex: self.age = 17;

    Character

This assigns a value of text
ex: self.name = "satanichispanic";

    True/False

This assigns a true false value (mostly used in toggles)
ex: self.vip = false;

Naming your variables is quite easy, just make sure you call and retrieve the same variable you want to use. for example.

    
OnPlayerSpawned();
self.vip = false;
self thread VIP();


    
VIP()
{
self.vip = true;
}


Assigned controlled variables to a function
Now this can be a quite tricky but is very easy once you get the hang of it. These are defined by the patch creator, but can easily be used in later stuff :p

to start off this will be a function

we will use a basic text display, the variable we will be using is "text", and "title"

    
message( title, text ) // this tells what the variables will be when called.
{
message = spawnstruct();
message.titleText = title;
message.notifyText = text;
message.glowColor = (256, 256, 256);
self thread maps\mp\gametypes\_hud_message::notifyMessage( message );
}


that is just the function lets say on player spawned again..

    
OnPlayerSpawned();
self thread message( "Hello There", "This is the sub text" );


Hello there is the title, and sub text is the sub text Smile That way you can use it more than once.

If then statements
If then statements are only used if it is a certain thing you want to happen

Equal to statemtents
These are basic statements.

    
if (self.name == "Bob" || self.name == "Ryan" || self.name == level.host)
{
self.host = true;
}else{
self.host = false;
}


This checks if your name is one of them, or the host. If it is true you are admin.

|| means or, and == means absolutely equal too (that's what I think of it as)


Other if then statements

not equal
    
if (self.host !== true)
{
self iPrintlnBold("You are not host!");
}


equal or greater
    
if (self.age <= 12)
{
self thread message( "GTFO", "Your 12 or under" );
}else if (self.age >= 13){
self thread message( "Congrats", "Your 13 or over" );
}



Loops
Loops allow something to repeat any amount of times.

It's is used with the while command. which is kinda like saying do this while doing that.

    
self thread message( "Hello There", "Welcome" );
while(1)
{
self iPrintlnBold("Hello NOOB");
}
//more coding


This prints hello noob, while doing the upper command

Arrays

Arrays are good, and can be used to create many things. To start off (yes this is how mod menu's work, and how gun game works, I can re-code gun game ;O )

    
arraythingy()
{
i = 0; //this is the variable

self.name[0] = "Bob";
self.name[1] = "Ryan";
self.name[2] = "Jenna";
self.name[3] = "Jessica"; //these are the what happens when the variable is changed.

self notifyOnPlayerCommand("change", "+actionslot 4");

for(;Winky Winky
{
self waittill("change"); //when he pressess actionslot 4
i++; //this will increate by 1 value of the array
self iPrintlnBold(self.name[i]); //this will print self.name and i is the variable 0 - 3.
}
}


Cases
Cases are easier to manager rather than have 1000000+ if/then statements

we will use the self.name example from before
    
case()
{
switch(self.name)
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


as you can see you can make it returns value, and it changes like that.

You can even get more advanced using a random integer
    
case()
{
switch(randomint(20)) //picks a random number between 1 - 20
{
case 0:
iPrintlnBold("Bob");
break;
case 1:
giveWeapon("Ryan");
break;
case default:
}
}


But lets say you want a "range" of something it can also be returned that way.

    
switch(randomintrange(2, 4)) //picks only between 2 and 4
{
case 0:
//do something
case 1:
//do something
case 2:
// picked by randomint range
case 3:
// etc..
}


Now I hoped you enjoyed this tutorial, and it helped you a little. If you have any questions ask me.

I will update with anymore you think I should include/ you need help with.


If this gets 25 thanks, I'll release how to create a mod menu, and you won't have to rely on stealing it off of craigschrist, or elite mossy, dconners... etc..

Hope you enjoyed this!


This was pretty help full for once a good GSC Tut i am not very good with GSC this is a big help :p Thank you.
01-07-2012, 05:41 AM #4
Originally posted by xRazbaz View Post
Did you write this yourself?
Also don't ask 4 thanks


Yes I wrote this myself. no copy pasta.

and It's kind of like a youtube thing. likes n I'll release it cool Smile

just cause I almost got my first rep star.

hope you enjoyed this tut!
01-07-2012, 05:41 AM #5
PussayPatrol
I'm a neat monster...
Originally posted by xRazbaz View Post
Did you write this yourself?
Also don't ask 4 thanks


That is what i was wonderingstare

i bet it wasn't him stare
01-07-2012, 05:44 AM #6
Originally posted by PussayPatrol View Post
That is what i was wonderingstare

i bet it wasn't him stare

I bet it was Fallen :carling:
Last edited by Rainbow Gravity ; 01-07-2012 at 05:47 AM.
01-07-2012, 05:44 AM #7
Originally posted by PussayPatrol View Post
That is what i was wonderingstare

i bet it wasn't him stare


I did too write it myself :( honest to god, I was trying to help people, because I was clueless but then I learned.

The following user thanked Jakes625 for this useful post:

PussayPatrol
01-07-2012, 05:48 AM #8
Originally posted by SatanicHispanic View Post
I did too write it myself :( honest to god, I was trying to help people, because I was clueless but then I learned.

Nah we're joking mate Smile
It's just because the tut's really good :y:

The following user thanked Rainbow Gravity for this useful post:

01-07-2012, 05:53 AM #9
Originally posted by xRazbaz View Post
Nah we're joking mate Smile
It's just because the tut's really good :y:


Thanks but this is just the basics. Enought to make your own patch to a decent amount.

There is still model manipulation, and newer things that were being wored on at the end of 1.11 days.
Its fairly easy, and IW included a bunch of functions built in game to make a cool methods and functions Smile
01-07-2012, 06:37 AM #10
Blackstorm
Veni. Vidi. Vici.
Some of this info is incorrect but I'm glad you're contributing, seems like you took a lot of time. Good job Smile

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo