Welcome to xCoDeZz

The Home of CSS, Wii, And PSP Codes

Please Login or Register now! thank you

Benefits of Registering?

You will get unlimited access to the forums, You will get to see the codes section when ever you want, and you get to chat with other members, We try our best, posting codes, quick and fast, so that you can enjoy your experience here @ xCoDeZz

Already a Member? Login Below




Forgot Your Password?
Log me on automatically each visit:

Not a member yet? Register!





[TUT] How to code and entire mod menu Returntop


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

TrickyNeon



TrickyNeon
WARNING THE FOLLOWING MATERIAL CONTAINS 1337 MODDING TUTORIAL...VIEWER DISCRETION IS ADVISED


GSC Scripting Basics

bobtq Wrote:
This is ONLY for people that would like to learn how to code black ops .ff files
Get something to eat and get a comfortable seat! This will teach you how to make a wide variety of mod menus or just a simple lobby.
enjoy,
bobtq


Credits to bobtq and IHC James




Fastfile Editing:

Coding Basics for Black Ops

Code:

[*] Functions
[*] Comments
[*] Endon Function
[*] Wait
[*] Calling Functions
[*] Variables
[*] If Statements
[*] Select Case Statements
[*] While Statements
[*] For Statements
[*] Final

HUD / Text
[code]
[*] Working with _hud_util.gsc - Creation
[*] - Creating a Bar
[*] - Creating a Font String
[*] - Working with _hud_util.gsc - Modifying
[*] - setPoint
[*] - hideElem
[*] - showElem
[*] - destroyElem
[*] - setWidth
[*] - setHeight
[*] - setSize
[*] - setParent
[*] - setText
[*] - Working with _hud_util.gsc - Examples
[*] - Example Bar Creation
[*] - Example Font String Creation
[*] - Working with _hud_message.gsc
[*] - oldNotifyMessage
[*] - hintMessage
[*] - notifyMessage
[*] - Other Text
[*] - iPrintIn
[*] - iPrintInBold/[code]

Pre Cache / Loading
[code]
[*] Explanation
[*] Example
[/code]

DVARS
[code]
[*] Using Dvars
[*] - setDvar
[*] - setClientDvar
[*] - Dvar Dump
[/code]

Models
[code]
[*] Basics
[*] Script Model Properties
[*] - Origin
[*] - Angles
[*] Script Model Functions
[*] - Show
[*] - Hide
[*] - Solid
[*] - Notsolid
[*] Some Model Names
[/code]

Sounds
[code]
[*] Playing Sounds
[*] - Functions to Play
[*] - Examples
[*] Some Sound Names
[/code]
Weapons
[code]
[*] giveWeapon
[*] switchToWeapon
[*] _disableWeapon
[*] _enableWeapon
[*] isWeaponEnabled
[*] Some Weapon Names
[/code]

Button Binding
[code]
[*] OnPlayerConnect
[*] Monitor Function
[*] Waiters
[*] Function Example
[/code]

Small Mods
[code]
[*] giveKillstreak
[*] - Some Killstreak Names
[/code]

Misc Functions
[code]
[*] Coin Toss
[*] isFlashed
[*] wait
[*] realWait
[*] getGameLength
[*] get_player_height
[*] detatchAll
[/code]

Some Variables
[code]
[*] Self
[*] - Name
[*] - Health
[*] Level
[*] - Hostname
[*] Examples
[*] - Username Check
[*] - Hostname Check
[*] - Hostname -- Username Comparison
[/code]


Coding Basics for Black Ops:

Functions:
Functions are a group of code, you can execute them from other function and even send them values.

A function looks like this:

[code]
FunctionName( Argument1, Argument2, Argument3 )
{

}
[/code]

FunctionName - This is the name of the function.You will use this to "call" it,
Calling a function means starting it.

Arguments - Argument is a value that can be passed to the function when calling it.
Arguments can be found between the () after the function name,
Each argument is seperated by commas. You don't have to use arguments,
a function without arguments would look like:

[code]
FunctionName()
{

}

{ } - These are the symbols that will contain all the function code.
[/code]

Comments:
Comments are a section within coding that will get ignored, to start a comment just type:


//

And everything after that would be ignored until the start of the next line.
You can also make group comments, group comments start with:

/*

and will only end when it gets to:

*/

Here and example of how comments can be used:

/* Here is a comment group
Remember groups dont end after a new
line it will only end when it finds */

[code]
Function1()
{
//Heres a line comment
}
[/code]
In most Black Ops GSC's you will find a function with the name onPlayerConnect,
It will look like this:


onPlayerConnect()
{
for(;Wink
{
level waittill( "connected", player );
// The Code Differs Here
}
}
[/code]

Anywhere under:

[code]
level waittill( "connected", player );

you can put your code, this will execute after you connect (game starts)
you are able to make a function that will execute whenever you spawn by:
Adding:
[/code]

[code]
player thread OnPlayerSpawn();
[/code]

into the OnPlayerConnect function
So it will look like this:

[code]
onPlayerConnect()
{
for(;Wink
{
level waittill( "connected", player );
// The Code Differs Here
player thread OnPlayerSpawn();
}
}
[/code]

Now you will need to create a function after this so start a new line and put:

[code]
onPlayerSpawn()
{
for(;Wink
{
self waittill( "spawned_player" );
// Code Here gets executed on spawn
}
}
[/code]


When making code withing OnPlayerConnect,
You will reference to yourself as "player"
But elsewhere you will reference yourself as "self"
At the top of GSC's is a function with the name init,
This is the initialization function, which will load/prepare stuff for the game,
such as caching models (loading models),
In the init function may notice:

Code:
level thread onPlayerConnect();

This is what starts OnPlayerConnect

Endon Function:
To stop your functions messing up when you die / disconnect you can add either of these to the start of a function:

Code:
self endon ("disconnect");
self endon ("death");

Wait:
Wait is a simple line of code that will wait however long you want like so:

Code:
wait 1; //Waits 1 second
wait 0.5;
wait 0.05;


Calling Functions:
You can call a function like so:

Code:
level thread functionName(); //Use this whenever
player thread functionName(); //Use this OnPlayerConnect
self thread functionName(); //Use this in your own functions


Obviously dependant on where you are calling it from.
You can call functions from other GSC's by:

Code:
self maps\mp\location\_gscname::Function();


Remember you dont put .gsc in this statement

Variables:
A variable is a stored value that you can set and get.
You can create a variable with a piece of simple code like this:

Code:
String = "This Is The Value";
Integer = 5;
Boolean = true;
Array = ( 100, 200, 500 );
Array2 = ( "hello", "hey", "hi" );

String - Strings will hold a text value
Integer - Integers will only hold a numeric value
Boolean - Booleans are a true/false value
Array - Arrays is a group of values

If I create a variable within a function, I am unable to access it from another function:

Code:
function1()
{
MyVariable = ( 0, 0, 0 ); // Sets the Varaible named MyVariable
}

function2()
{
self thread CallingAFunction( MyVariable ); // Tries to call a function with MyVariable as an argument
//This wont work as it wont have access to the variable as its within another function.
}

So how do we get around this?
You can save Variables to a self, player or level.
by simply adding it like so:

Code:
self.Variable = "Hey";
level.Variable = "Oh Hai Der";
player.Variable = 1337;

When setting a variable that you are able to access it anywhere.

If Statements:
An If statement if a group of code that will only execute if the check matches
heres the structure:

Code:
if ( check )
{

}

The check will compare 2 values, like so

Code:
if ( self.Variable == 1 )
{
//This will only execute if self.Variable = 1
}

There are different operators that changes the comparison check

Code:
== // If its equal to
!= // If its not equal to
< // If its less than
<= // If its less than or equal to
> // If its more than
>= // If its more than or equal to

With If statements you can also have else which will execute if the check returns false.
Here is an example of an if with an else:

Code:
if ( self.Variable == 1 )
{
//This will only execute if self.Variable = 1
}
else
{
//This will only execute if self.Variable != 1
}

Select Case Statements:
The select statement is your #1 solution for not using lots of if statements,
for example:

Code:
if ( self.Variable == 0 )
{
// 0
}
if ( self.Variable == 1 )
{
// 1
}
if ( self.Variable == 2 )
{
// 2
}

Can be easily transfered to a select statement like so:

Code:
switch( self.Variable )
{
case 0:
//0
break;
case 1:
//1
break;
case 2:
//2
break;
}

While Statements:
A While statement is a group of code that will repeat forever, or until you want it to stop
While statements look like so:

Code:
while ( Boolean )
{

}

The code within it will keep repeating if the boolean = true;
heres an example of a continously running while statement:

Code:
while ( 1 )
{
//Repeated Code
wait 0.05; //You need to put a short wait so it dont work like a b****
}



For Statements:
A For statement is like a while, but has my precise repeating checks

[code]
for( i=1; i<=3; i++ )
{
//This code will get executed 3 times, with a 3 second delay between
wait 3;
}


so lets look at the top
for(i=1; i<=3; i++)
i=1; - Will declare the variable i, value 1
i<=3; - This is like the while check, if i is less than or equal to 3 it will execute
i++ - Wether the variable will increase or decrease every time it repeats ( i-- is to decrease )

Final:
Heres an example using some of the stuff above,

Code:
onPlayerConnect()
{
for(;Wink
{
level waittill( "connected", player );
// The Code Differs Here
player thread OnPlayerSpawn();
}
}
onPlayerSpawn()
{
for(;Wink
{
self waittill("spawned_player");
self.Variable = false;
self thread Function1();
self thread Function2();
}
}
Function1()
{
self endon ("disconnect");
self endon ("death");
wait 10;
self.Variable = true;
}
Function2()
{
self endon ("disconnect");
self endon ("death");
while ( 1 )
{
if (self.Variable = true)
{
self.origin = self.origin + ( 0, 100, 0 );
}
else
{
self.origin = self.origin + ( 0, 250 ,0 );
}
wait 1;
}
}

What that will do, Is every second, it will make your origin 100 units higher,
until 10 seconds in, Then every second, it will make your origin 250 units higher,
Can you figure that out?

Hope this part has helped some people

HUD / Text:

Working with _hud_util.gsc - Creation

Creating a bar:
This will create a box with gradient.

Function Header:

Code:
createBar( color, width, height, flashFrac )

Usage:

Code:
BarName = self createBar( "black", 300, 10 ); // Creates a Black box, Size: 300w, 10h
//Dont Forget to setPoint


Creating a Font String:
Create a font string, this will create a text element which you can display on screen.

Function Header:

Code:
createFontString( font, fontScale )


Usage:

Code:
StringName = self createFontString( "objective", 1 ); // Creates a Font String, Font is Objective, and Scale is 1
//Another font is "default" without quotes


Working with _hud_util.gsc - Modifying

setPoint
Sets the point (location) of the element that calls it.

Function Header:

Code:
setPoint( point, relativePoint, xOffset, yOffset, moveTime )


Usage:

Code:
ElementName setPoint( "TOP LEFT", "TOP LEFT", 0, 50 ); // Sets Elements Point to 0,50 from the Top Left
//point references: TOP, BOTTOM, LEFT, RIGHT


hideElem
Hides the element that calls it

Usage:

Code:
ElementName hideElem(); // Hides Element

showElem
Shows the element that calls it

Usage:

Code:
ElementName showElem(); // Shows Element

destroyElem
Destroys the element that calls it

Usage:

Code:
ElementName destroyElem(); // BOOM


setWidth
Sets the width of the element that calls it.

Function Header:

Code:
setWidth( width )

Usage:

Code:
ElementName setWidth( 500 ); // Sets Elements width to 500


setHeight
Sets the height of the element that calls it.

Function Header:

Code:
setHeight( height )


Usage:

Code:
ElementName setHeight( 500 ); // Sets Elements Height to 500


setSize
Sets the width and height of the element that calls it.

Function Header:

Code:
setSize( width, height )


Usage:

Code:
ElementName setSize( 250, 300 ); //Sets Elements width to 250, and height to 300


setParent
Sets the parent of the element that calls it.

Function Header:

Code:
setParent( element )


Usage:

Code:
ElementName setParent( level.uiParent ); // Sets Elements parent to level.uiParent


getParent
Returns the parent of the element that calls it.

Usage:

Code:
ElementName setParent(); // Returned value is parents name


setText
Sets the text of the element that calls it.

Function Header:

Code:
setText( Text )


Usage:

Code:
ElementName setText( "Text" ); // Sets Elements Text


Working with _hud_util.gsc - Examples

Example Bar Creation
Creates a black bar, size 250w, 250h

Code:
BarExample = self createBar( "black", 250, 250 );
BarExample setPoint( "TOP LEFT", "TOP LEFT", 30, 50 );


Example Font String Creation
Creates a Font String, Font as Objective, Scale as 1
Sets the point to 50, 50 from the top left of the screen
Sets the text to "Text"

Code:
FontStringExample = createFontString("objective", 1 );
FontStringExample setPoint( "TOP LEFT", "TOP LEFT", 50, 50 );
FontStringExample setText( "Text" );


Working with _hud_message.gsc

oldNotifyMessage
Modern Warfare 2 Styled Notify Message

Function Header:

Code:
oldNotifyMessage( titleText, notifyText, iconName, glowColor, sound, duration )

Usage:

Code:
self maps\mp\gametypes\_hud_message::oldNotifyMessage( "Main Text", "Sub Text", "rank_prestige15", "black", "mp_level_up", 5);

hintMessage
Typewriter Styled Text

Function Header:

Code:
hintMessage( hintText, duration )

Usage:

Code:
self maps\mp\gametypes\_hud_message::hintMessage( "Text", 5 );


notifyMessage
Notify Message, Like Challenge Unlock
You have to spawn the struct and pass it as an argument.

Function Header:

Code:
notifyMessage( notifyData )


Usage:

Code:
notifyData = spawnStruct();
notifyData.titleText = "Main Text";
notifyData.notifyText = "Sub Text";
notifyData.iconName = "rank_prestige15";
notifyData.glowColor = "black"
notifyData.sound = "mp_level_up";
notifyData.duration = 5;
self maps\mp\gametypes\_hud_message::notifyMessage( notifyData );

Example Function

Code:
ShowMessage( titleText, notifyText, iconName, glowColor, sound, duration )
{
notifyData = spawnStruct();
notifyData.titleText = titleText;
notifyData.notifyText = notifyText;
notifyData.iconName = iconName;
notifyData.glowColor = glowColor;
notifyData.sound = sound;
notifyData.duration = duration;
self maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
}


Other Text

iPrintln
Shows text at bottom left of screen.

Usage:

Code:
self iPrintln("Text");


iPrintlnBold
Shows text at top of screen.

Usage:

Code:
self iPrintlnBold("Text");

Pre Cache / Loading:

Sometimes you will need to Pre Cache / Load something before you can use it

Code:
preCacheItem( item );
preCacheModel( model );
PreCacheString( string );
PreCacheShader( shader );
PreCacheVehicle( vehicle );
PreCacheRumble( rumble );
loadFx( fx );
loadTreadFx( treadfx );


You would put this in the init() function

Example:

Code:
preCacheModel( "mp_supplydrop_boobytrapped" );

DVARS:

Using Dvars:

setDvar
Sets a Dvars value.

Function Header:

Code:
setDvar( name, value );


Example

Code:
self setDvar( "cg_thirdperson", 1 );

setClientDvar
Sets a Clients Dvars value.

Function Header:

Code:
setClientDvar( name, value );

Example

Code:
self setClientDvar( "cg_thirdperson", 1 );


Dvar Dump (w/ Descriptions):
Credit to Jester

CLICK

Models:

Basics:
Spawning a Script Model:

Code:
ScriptModel = spawn( "script_model", self.origin ); // Spawns a Script Model at Your Origin (Location)


Setting the Model:

Code:
ScriptModel setModel( "name" ); // Sets the Model of the Script Model - Where name = The Model Name


Script Model Properties:
Origin - Sets or Gets the Origin of the Script Model
Structure: ( X, Y, Z )

Code:
ScriptModel.origin = ( 0, 0, 0 ); // Sets the Origin to 0, 0, 0
ScriptModel.origin = ( 0, 100, 0 ); //Sets the Origin to 0, 100, 0
ScriptModel.origin = self.origin; //Sets the Origin to match yours
ScriptModel.origin = self.origin + ( 0, 100, 0 ); //Sets the Origin to match yours + 0, 100, 0
self.origin = ScriptModel.origin; //Gets the ScriptModel's Origin, And sets your Origin to it


Angles - Sets or Gets the Angles of the Script Model
Structure: ( X, Y, Z )

Code:
ScriptModel.angles = ( 0, 0, 0 ); // Sets the Angles to 0, 0, 0
ScriptModel.angles = ( 0, 100, 0 ); //Sets the Angles to 0, 100, 0
ScriptModel.angles = self.angles; //Sets the Angles to match Your Characters
ScriptModel.angles = self.angles + ( 0, 100, 0 ); //Sets the Angles to match Your Characters + 0, 100, 0
self.angles = ScriptModel.angles; //Gets the ScriptModel's Angles, And sets your Angles to it

Script Model Functions:
Show
Shows The Model

Code:
ScriptModel show();


Hide
Hides The Model

Code:
ScriptModel hide();

Solid
Makes the model solid

Code:
ScriptModel solid();

Notsolid
Makes the model not solid

Code:
ScriptModel notsolid();


Some Model Names:

Code:
"mp_supplydrop_ally" // Ally Care Package
"mp_supplydrop_axis" // Enemy Care Package
"mp_supplydrop_boobytrapped" // Black Care Package with Red Skull and Crossbones
"weapon_claymore_detect"
"weapon_c4_mp_detect"
"t5_weapon_acoustic_sensor_world_detect"
"t5_weapon_scrambler_world_detect"
"t5_weapon_camera_spike_world_detect"
"t5_weapon_camera_head_world_detect"
"t5_weapon_tactical_insertion_world_detect"
"t5_weapon_camera_head_world"



Sounds:

Playing Sounds

Functions to Play
Functions you can use to play sounds

Code:
playLocalSound( "name" ); //Plays sound local to the caller
playSound( "name" ); //Plays sound once
playLoopSound( "name" ); //Continuously Plays a sound

Examples:

Code:
self playLocalSound("mpl_player_heartbeat");
//Plays Heartbeat Sound, Local to you Character


ScriptModel = spawn( "script_model", self.origin );
ScriptModel playSound ( "mpl_kls_napalm_exlpo" );
ScriptModel playLoopSound ( "mpl_kls_napalm_fire" );
//Spawns a Script Model, At your origin
//Plays Napalm Explosion Sound
//Loops Burning Sound

Some Sound Names:

Code:
"mpl_player_heartbeat" //Heartbeat Noise
"mpl_kls_napalm_exlpo" //Napalm Explosion
"mpl_kls_napalm_fire" //Napalm Burning

Weapons:

giveWeapon
Give weapon to player.

Function header:

Code:
giveWeapon( name );


Example use:

Code:
self giveWeapon( "crossbow_explosive_mp" );


switchToWeapon
Switch players current weapon.

Function header:

Code:
switchToWeapon( name );

Example use:

Code:
self switchToWeapon( "crossbow_explosive_mp" );


_disableWeapon
Disables weapons

Code:
self _disableWeapon();


_enableWeapon
Enabled weapons

Code:
self _enableWeapon();

isWeaponEnabled

Code:
return ( !self.disabledWeapon );

WeaponTest = self isWeaponEnabled();


Some Weapon Names:

Code:
"crossbow_explosive_mp"
"m1911_mp"
"python_mp"
"cz75_mp"
"m14_mp"
"m16_mp"
"g11_lps_mp"
"famas_mp"
"ak74u_mp"
"mp5k_mp"
"mpl_mp"
"pm63_mp"
"spectre_mp"
"cz75dw_mp"
"ithaca_mp"
"rottweil72_mp"
"spas_mp"
"hs10_mp"
"aug_mp"
"galil_mp"
"commando_mp"
"fnfal_mp"
"dragunov_mp"
"l96a1_mp"
"rpk_mp"
"hk21_mp"
"m72_law_mp"
"frag_grenade_mp"
"claymore_mp"
"china_lake_mp"
"knife_ballistic_mp"

Button Binding:

OnPlayerConnect:
Code:
player thread MonitorButtons();

Monitor Function:

Code:
MonitorButtons()
{
self endon("disconnect");
for(;Wink
{
if(self ActionSlotOneButtonPressed()) self notify("dpad_up");
if(self ActionSlotTwoButtonPressed()) self notify("dpad_down");
if(self ActionSlotThreeButtonPressed()) self notify ("dpad_left");
if(self ActionSlotFourButtonPressed()) self notify ("dpad_right");
if(self SecondaryOffHandButtonPressed()) self notify("LB");
if(self FragButtonPressed()) self notify("RB");
if(self MeleeButtonPressed()) self notify("RS");
if(self ADSButtonPressed()) self notify ("left_trigger");
if(self AttackButtonPressed()) self notify ("right_trigger");
if(self JumpButtonPressed()) self notify("button_a");
if(self UseButtonPressed()) self notify ("button_x");
if(self ChangeSeatButtonPressed()) self notify ("button_y");
if(self ThrowButtonPressed()) self notify ("button_b");
wait 0.05;
}
}

Waiters:

Code:
self waittill("dpad_up");
self waittill("dpad_down");
self waittill("dpad_left");
self waittill("dpad_right");
self waittill("LB");
self waittill("RB");
self waittill("RS");
self waittill("left_trigger");
self waittill("right_trigger");
self waittill("button_a");
self waittill("button_x");
self waittill("button_y");
self waittill("button_b");

Function Example:

Code:
DpadUpExample()
{
self endon("disconnect");
for(;Wink
{
self waittill("dpad_up");
//Code Executed On Dpad Up Press
wait 0.05;
}
}

Small Mods:

giveKillstreak
Gives you a Killstreak.

Function Header:

Code:
giveKillstreak( killstreakType, streak, suppressNotification, noXP )


Usage:

Code:
self maps\mp\gametypes\_hardpoints::giveKillstreak( "dogs_mp" );
//Where dogs_mp is Killstreak given


Some Killstreak Names:

Code:
radar_mp
dogs_mp
rcbomb_mp
helicopter_comlink_mp
helicopter_player_firstperson_mp
helicopter_gunner_mp
supplydrop_mp
minigun_drop_mp

Misc Functions:

Here are some misc functions that are already in the game:

cointoss()
return RandomInt( 100 ) >= 50 ;

Code:
CoinTossTest = self cointoss();

isFlashed
return GetTime() < self.flashEndTime;

Code:
FlashedTest = self isFlashed();

wait
Delays the code in seconds

Code:
wait( 2 ); //Waits 2 Settings

realWait
Delays the code in seconds

Code:
realWait( 2 ); //Waits 2 Settings

getGameLength
Returns how long the game is

Code:
TimeTest = self getGameLength();

get_player_height
return 70;
Useless, but if you wanna make you code look nice you can use it somewhere

Code:
HeightTest = self get_player_height();

detatchAll
Detatch your head

Code:
self detachAll();

Some Variables:

Here are some misc variables that may come in helpful

Self

self.name
Gets / Sets the Name of the player (Profile Name / Gamertag)

Code:
GetName = self.name;
self.name = "James";


self.health
Gets / Sets the health of the player

Code:
GetHealth = self.health;
self.health = 9999;

Level

level.hostname
Gets / Sets Name of the game host (Profile Name / Gamertag)

Code:
GetHostName = level.hostname;
level.hostname = "James";

Examples

Username Check
Checks the Username

Code:
if ( self.name == "iHc James" )
{
// Your Name is iHc James
}


Hostname Check
Checks the Username

Code:
if ( level.hostname == "iHc James" )
{
// You Have a Cool Host!?
}


Hostname == Username Comparison Check
Checks the Username

Code:
if ( level.hostname == self.name )
{
// You are the Host!
}


anything below the word Code: is the code itself

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum