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-08-2012, 03:48 AM #29
AndreeU
+cM TeamCM GFX 4 Lifee<3
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!


Really good and very informational but i wonder whether you did this or found this. Credit to C++
01-08-2012, 12:33 PM #30
bonyskullz
NextGenUpdate Elite
Originally posted by Blackstorm View Post
It's better than your sig..


that is also why i dont have one.... because i have not made one good enough to stick on..... yours..............No
01-08-2012, 06:25 PM #31
Blackstorm
Veni. Vidi. Vici.
Originally posted by bonyskullz View Post
that is also why i dont have one.... because i have not made one good enough to stick on..... yours..............No


lmao. You're a retard. My sig is a joke.
01-08-2012, 06:41 PM #32
thank you so much i learned something newYes but if i had more post i would of thank and like :(
01-08-2012, 07:25 PM #33
Originally posted by SatanicHispanic View Post
I almost got my first rep star.

hope you enjoyed this tut!


Good effort.

I would say this though

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


Should be written like this..

    {
if(!self.host)
self iPrintLnBold("You are not host!");}
01-08-2012, 09:37 PM #34
Thanks really helped bro!
01-08-2012, 09:45 PM #35
yeah I know, but some people wouldn't understand that (beginners)

I tried to make as simple as possible, but for you that read that.

! = not so

if(!self isHost())
self thread dontDoHost

if not self is host, if that makes sense Happy
01-08-2012, 10:07 PM #36
Vanz
Z32 Love <3
This should be sticked!
01-08-2012, 11:23 PM #37
DEREKTROTTER
You're Goddamn Right
Originally posted by SatanicHispanic View Post
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!


nice writeup :y:

when i saw the title i expected to see a copy/paste of K-Brizzles tutorial, this is more up to date

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo