Post: Learning the GSC language.
01-15-2012, 12:55 PM #1
Correy
I'm the Original
(adsbygoogle = window.adsbygoogle || []).push({});
The functioning of GSC
Anyone feel free to submit a tutorial, just quote me. i'll add it in.

there's not much things to post these days, might aswell create this to update when there's nothing else to do.
i will be putting alot of time into this, so i would appretiate as much as you do.

Sorry for any spelling mistakes.
Thanks to everyone who contributes.


[multipage=Variables - Data Storage]
The variable


The variable is a basically a string which stores data.
here's how you will see it.
    
Variable = "learning variables";


now, the string 'Variable' now equals "learning variables".
if i now was to println this, like 'self iPrintln( Variable );
it will output 'learning variables;.

this is probably the most basic thing in GSC, there's also more to it but that comes into arrays which will be explained later on.
[multipage=Threading - Calling a function]
Threading


Threading is pretty much every function which you will find, without this your code snippet will not act.
also again, this is pretty basic.. but it can be mistaken.

here's a basic snippet.
    
self thread Tutorial();


now, if i was just to put that into my patch it will error.
the game will look for the thread 'Tutorial', which at the minute is not functioned; this error will be 'Unknown function'
therefore i will need to add my function somehwere.

    
Tutorial()
{
self iPrintln( "hi" );
}


now up on threading that, say if i threaded it up on player spawn my output will be a line print of 'hi'.
yes, this is how your god mode ect are called, however you need to coding for them.

you see how i have the 'self', thats really self explanitory.. it will act up on myself, but that can be changed..
    
level.players[ 1 ] Tutorial();


that will function for the level.player (player) which has the entity number of 1.

now you might see '<self> thread Something();'
the 'thread' is only needed if it's inputing data from/ into another thread, so if i was to doo..
    
printText( text )
{
self iPrintln( text );
}


'self thread printText( "hi" );'
which now leads us onto arguements
[multipage=The strTok - Split Statement]
The strTok


The strTok is a split statement, it will split every statement given up on the char which it should be split at.
here's a syntax version of how it should be used.

    
< new string to input > = strTok( < string to input > , < split char > );


- New string to input
this is will set the statement's too, remember.. if there's more than one statement it will need to be set at an array.

- String to input
this is the string/ text which needs to be inputted then split, remember it must contain the split char or it wont be split.

- Split char
this goes for aboth, it's a single char placed in a ".. for every 'split char' in the input string it will split it, then carry on splitting until it will no longer can be splitten.

here's a full example of usage.
    
printlines( texts )
{
output = strTok( texts, "|" );
self iPrintln( output );
}


there i've set the input string to an arguement, it works the same just called differently.
so here's how i would call it.

    
self printlines( "this|is|a|tutorial" );


that will print a new line for this, is, a, tutorial.. so it will look something like..
    
this
is
a
tutorial


strTok is pretty useful and can compress your code much more than over statement.
if your having trouble of don't understand how to use this then message me, i'll help you out with it.

but i hope i explained as best as i can.
[multipage=The 'If' Statement]
The "If" statement- By .Choco
[/center]

The If statement is a major part of Call of Duty Scripting. It can be used in many ways. What it does is tell the game that if a certain condition is true, false, or equal to a value, do a certain thing. Here is an example of one:

    ExampleFunction()
{
if(<variable> == <value>Winky Winky
{
self iPrintln("poopy");
}
}


So let's break that down a bit.

    if(<variable> 

Any variable can be here, whether it is attached to yourself or the level.

     == 

"==" translates to "is equal to". There are other arguments that can be placed here:
"!=" - is not equal to
"<" - is less than
">" - is greater than
"<=" - is less than or equal to
">=" - is greater than or equal to

    <value>


Your value goes here. It can be a number, a string, true, or false.

After your if statement is declared, put a set of brackets under it and everything inside those will be executed if the statement is true (these brackets are not always needed, but for the purpose of this tutorial they will be).

Seem a bit confusing? It's not really. The if statement is one of the most commonly used scripts in all patches. One way it is very practically used is to determine who the host of a lobby is. The next script does just that:

    findHost()
{
if(self GetEntityNumber() == 0)
{
self.isHost = true;
}
}


GetEntityNumber() is a built-in function that returns your Client Number. Number 0 is the first to connect, which is always the host. So what this function says if that if your client number is 0, the variable "self.isHost" is attached to you and it is true.
[multipage=Using 'endon', 'waittill' & 'notify']
Using 'endon', 'waittill' & 'notify'- By .Choco


endon, waittill, and notify are very useful tools in CoD scripting. I will be breaking them down and explaining what they do and why it is useful.

Let's start with endon.
Here is a basic god mode script:

    
God()
{
self endon("disconnect");
self endon("death");
self.maxhealth = 90000;
self.health = self.maxhealth;
while( 1 )
{
if(self.health < self.maxhealth)
self.health = self.maxhealth;
wait 0.1;
}
}

Now I'm not going to break down the whole function, but let's look at the beginning of it.

    
self endon("disconnect");

This part tells the game that if you disconnect, terminate the God() thread. So if you lag out or leave, God Mode stops.

    
self endon("death");

This tells the game that if you die, terminate the thread. Simple enough right?

Now how does the game know what "death" and "disconnect" are? This is where notify comes in. In the game engine, if you die it automatically notifies the game with "death". If you disconnect, it notifies it with "disconnect". You can notify the game of something like this:

    
self notify("you_are_a_noob"); //This will notify your player's entity "you_are_a_noob"
level notify("you_are_all_noobs"); //This will notify every player "you_are_all_noobs"

The notify can be very practical for things like toggles. Example of a cg_drawFps toggle:

    
toggleFps()
{
self endon("disconnect"); //if the game ends or you leave stops the function
self endon("death"); //stops the function if you die
i = 0;
for(;Winky Winky
{
self waittill("toggle_fps"); //this will be explained shortly
self setClientDvar("cg_drawFps", i);
i++;
if(i == 4) i = 0;
}
}

To toggle the FPS counter, all you have to do is this:

    
self notify("toggle_fps");

It can be used like that to make your script much simpler.

Now on to waittill.

Go back and look at the Fps toggle script. See this part?
    
self waittill("toggle_fps");

Waittill tells the function to wait for something to be notified before continuing with the function. In the case of the FPS toggle, it tells the function to wait for "toggle_fps" before continuing. Very useful stuff

I hope I made this clear enough to help people out
[multipage=Updates]
15th January; 13:02
    
- thread created!
- variables
- threading
- strTok


15th January; 21:59
    
- the 'If' statement by .Choco
Last edited by Correy ; 01-16-2012 at 09:09 AM.

The following 10 users say thank you to Correy for this useful post:

/RunDos/, Geo, Ghost1990, ImAzazel, JamesSwagger, LBK, Cmd-X, RuszXMC, Uk_ViiPeR, xKtF
01-15-2012, 07:57 PM #20
Originally posted by IVI40A3Fusionz View Post
None of you know anything it's Plankalkül (Plan Calculus) Not Happy or Sad :carling:
If the game's written in American, how come people with foreign computers can still play it? eh ? :dumb:
01-15-2012, 07:59 PM #21
Taylor
Former Black Knight.
Originally posted by Correy View Post
The functioning of GSC
Anyone feel free to submit a tutoria

there's not much things to post these days, might aswell create this to update when there's nothing else to do.
i will be putting alot of time into this, so i would appretiate as much as you do.

Sorry for any spelling mistakes.


[multipage=Variables - Data Storage]
The variable


The variable is a basically a string which stores data.
here's how you will see it.
    
Variable = "learning variables";


now, the string 'Variable' now equals "learning variables".
if i now was to println this, like 'self iPrintln( Variable );
it will output 'learning variables;.

this is probably the most basic thing in GSC, there's also more to it but that comes into arrays which will be explained later on.
[multipage=Threading - Calling a function]
Threading


Threading is pretty much every function which you will find, without this your code snippet will not act.
also again, this is pretty basic.. but it can be mistaken.

here's a basic snippet.
    
self thread Tutorial();


now, if i was just to put that into my patch it will error.
the game will look for the thread 'Tutorial', which at the minute is not functioned; this error will be 'Unknown function'
therefore i will need to add my function somehwere.

    
Tutorial()
{
self iPrintln( "hi" );
}


now up on threading that, say if i threaded it up on player spawn my output will be a line print of 'hi'.
yes, this is how your god mode ect are called, however you need to coding for them.

you see how i have the 'self', thats really self explanitory.. it will act up on myself, but that can be changed..
    
level.players[ 1 ] Tutorial();


that will function for the level.player (player) which has the entity number of 1.

now you might see '<self> thread Something();'
the 'thread' is only needed if it's inputing data from/ into another thread, so if i was to doo..
    
printText( text )
{
self iPrintln( text );
}


'self thread printText( "hi" );'
which now leads us onto arguements
[multipage=The strTok - Split Statement]
The strTok


The strTok is a split statement, it will split every statement given up on the char which it should be split at.
here's a syntax version of how it should be used.

    
< new string to input > = strTok( < string to input > , < split char > );


- New string to input
this is will set the statement's too, remember.. if there's more than one statement it will need to be set at an array.

- String to input
this is the string/ text which needs to be inputted then split, remember it must contain the split char or it wont be split.

- Split char
this goes for aboth, it's a single char placed in a ".. for every 'split char' in the input string it will split it, then carry on splitting until it will no longer can be splitten.

here's a full example of usage.
    
printlines( texts )
{
output = strTok( texts, "|" );
self iPrintln( output );
}


there i've set the input string to an arguement, it works the same just called differently.
so here's how i would call it.

    
self printlines( "this|is|a|tutorial" );


that will print a new line for this, is, a, tutorial.. so it will look something like..
    
this
is
a
tutorial


strTok is pretty useful and can compress your code much more than over statement.
if your having trouble of don't understand how to use this then message me, i'll help you out with it.

but i hope i explained as best as i can.
[multipage=Updates]
15th January; 13:02
    
- thread created!
- variables
- threading
- strTok


No, Now A Bunch Of Little Kids Are Gunna Make Patchs No One Gives 2 Shits About! :(
01-15-2012, 08:00 PM #22
IVI40A3Fusionz
Former Gaming Squad Member
Originally posted by x. View Post
If the game's written in American, how come people with foreign computers can still play it? eh ? :dumb:


Because umm... wait a second let me think of something Winky Winky foreign computers have a special chip :carling: lols :p.
01-15-2012, 08:02 PM #23
Jacob-And-Britt
I’m too L33T
Originally posted by Correy View Post
The functioning of GSC
Anyone feel free to submit a tutoria

there's not much things to post these days, might aswell create this to update when there's nothing else to do.
i will be putting alot of time into this, so i would appretiate as much as you do.

Sorry for any spelling mistakes.


[multipage=Variables - Data Storage]
The variable


The variable is a basically a string which stores data.
here's how you will see it.
    
Variable = "learning variables";


now, the string 'Variable' now equals "learning variables".
if i now was to println this, like 'self iPrintln( Variable );
it will output 'learning variables;.

this is probably the most basic thing in GSC, there's also more to it but that comes into arrays which will be explained later on.
[multipage=Threading - Calling a function]
Threading


Threading is pretty much every function which you will find, without this your code snippet will not act.
also again, this is pretty basic.. but it can be mistaken.

here's a basic snippet.
    
self thread Tutorial();


now, if i was just to put that into my patch it will error.
the game will look for the thread 'Tutorial', which at the minute is not functioned; this error will be 'Unknown function'
therefore i will need to add my function somehwere.

    
Tutorial()
{
self iPrintln( "hi" );
}


now up on threading that, say if i threaded it up on player spawn my output will be a line print of 'hi'.
yes, this is how your god mode ect are called, however you need to coding for them.

you see how i have the 'self', thats really self explanitory.. it will act up on myself, but that can be changed..
    
level.players[ 1 ] Tutorial();


that will function for the level.player (player) which has the entity number of 1.

now you might see '<self> thread Something();'
the 'thread' is only needed if it's inputing data from/ into another thread, so if i was to doo..
    
printText( text )
{
self iPrintln( text );
}


'self thread printText( "hi" );'
which now leads us onto arguements
[multipage=The strTok - Split Statement]
The strTok


The strTok is a split statement, it will split every statement given up on the char which it should be split at.
here's a syntax version of how it should be used.

    
< new string to input > = strTok( < string to input > , < split char > );


- New string to input
this is will set the statement's too, remember.. if there's more than one statement it will need to be set at an array.

- String to input
this is the string/ text which needs to be inputted then split, remember it must contain the split char or it wont be split.

- Split char
this goes for aboth, it's a single char placed in a ".. for every 'split char' in the input string it will split it, then carry on splitting until it will no longer can be splitten.

here's a full example of usage.
    
printlines( texts )
{
output = strTok( texts, "|" );
self iPrintln( output );
}


there i've set the input string to an arguement, it works the same just called differently.
so here's how i would call it.

    
self printlines( "this|is|a|tutorial" );


that will print a new line for this, is, a, tutorial.. so it will look something like..
    
this
is
a
tutorial


strTok is pretty useful and can compress your code much more than over statement.
if your having trouble of don't understand how to use this then message me, i'll help you out with it.

but i hope i explained as best as i can.
[multipage=Updates]
15th January; 13:02
    
- thread created!
- variables
- threading
- strTok
Dude this is basicly what i made lol except your tut has a few different info but mine had the selfthread tut and precache tut and how to make a script.
01-15-2012, 08:20 PM #24
Originally posted by IVI40A3Fusionz View Post
Because umm... wait a second let me think of something Winky Winky foreign computers have a special chip :carling: lols :p.

American computers don't have chips, they have fries.. No

The following user thanked x_DaftVader_x for this useful post:

Docko412
01-15-2012, 08:25 PM #25
IVI40A3Fusionz
Former Gaming Squad Member
Originally posted by x. View Post
American computers don't have chips, they have fries.. No


I see what you did there Winky Winky i like it.

The following user thanked IVI40A3Fusionz for this useful post:

x_DaftVader_x
01-15-2012, 09:33 PM #26
Blackstorm
Veni. Vidi. Vici.
Originally posted by jbglitching View Post
Dude this is basicly what i made lol except your tut has a few different info but mine had the selfthread tut and precache tut and how to make a script.


You're not good enough to make tutorials yet. Half your scripts don't work. :b

The following 6 users say thank you to Blackstorm for this useful post:

247Yamato, aerosoul94, Amanda, Choco, KingcreekS, Vampytwistッ
01-15-2012, 09:35 PM #27
Choco
Respect my authoritah!!
Nice thread Smile I would go over for and while loops, also self & level notifies and endon's.
01-15-2012, 09:53 PM #28
Choco
Respect my authoritah!!
Originally posted by Correy View Post
blahblahblah




Here's my contribution to the thread:

The "If" statement

The If statement is a major part of Call of Duty Scripting. It can be used in many ways. What it does is tell the game that if a certain condition is true, false, or equal to a value, do a certain thing. Here is an example of one:

    ExampleFunction()
{
if(<variable> == <value>Winky Winky
{
self iPrintln("poopy");
}
}


So let's break that down a bit.

    if(<variable> 

Any variable can be here, whether it is attached to yourself or the level.

     == 

"==" translates to "is equal to". There are other arguments that can be placed here:
"!=" - is not equal to
"<" - is less than
">" - is greater than
"<=" - is less than or equal to
">=" - is greater than or equal to

    <value>


Your value goes here. It can be a number, a string, true, or false.

After your if statement is declared, put a set of brackets under it and everything inside those will be executed if the statement is true (these brackets are not always needed, but for the purpose of this tutorial they will be).

Seem a bit confusing? It's not really. The if statement is one of the most commonly used scripts in all patches. One way it is very practically used is to determine who the host of a lobby is. The next script does just that:

    findHost()
{
if(self GetEntityNumber() == 0)
{
self.isHost = true;
}
}


GetEntityNumber() is a built-in function that returns your Client Number. Number 0 is the first to connect, which is always the host. So what this function says if that if your client number is 0, the variable "self.isHost" is attached to you and it is true.
Last edited by Choco ; 01-15-2012 at 09:58 PM.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo