|

For those who are searching for a tutorial on how to modify gametypes in CoD4....
ShabbaStoney wrote one and when you click on READ MORE you can find out how coding in CoD4 is done.
Ok so now we're gonna start some coding.
First thing is to go to rawmapsmpgametypes and copy sab.gsc into your mod folder.

Now you can open sab.gsc in notepad / wordpad / visual studio / programmers notepad etc...
So now we have the gsc opened up we can start changing the game type.
Go to the function called onSpawnPlayer(), just above this function create a new function called updateGameType() and within this function put a while loop into it ( see pic ).

This function will be where all your game logic happens.
The next step is to thread this function from onSpawnPlayer(), using self thread updateGameType();

Now we have a function that will be called when the player spawns, lets start some coding!
In this example I am going to make it so that the player drops their weapon when they jump and shoot, it doesnt work perfectly but don't worry about that.
Add this within the while loop:
// Get the players weapon
weapon = self GetCurrentWeapon();
if( self IsOnGround() == false )
{
if( self AttackButtonPressed() )
{
if( RandomInt( 100 ) == 50 )
{
self sayall( "My weapon back fired. How about that!" );
self suicide();
}
else
{
self DropItem( weapon );
}
}
}

Now all thats left is to fast file this baby and go to test it!
If you want to, you can download my sab.gsc file for reference:
http://rapidshare.com/files/103145509/sab.gsc
I was doing some messing around and found out you can add variables to self. So in the above sab.gsc I have self.pickedUpBomb = 0; at the start of onSpawnPlayer(), then when the player picks up the bomb, in onPickuP() I do self.pickedUpBomb = 1;. Within the updateGameType() function you can use this variable to test if the player has picked up the bomb. Not quite sure if this is the way you're supposed to do it, but it seems to work.
I hope someone finds this useful.
~ShabbaStoney
Note:
- When entering the while loop, I always test if the player is alive, if they are dead you should break from the while loop
Example:
while(1)
{
// If the player is dead we don't want to update do we?
if( !isAlive( self ) )
{
onDrop( self );
break;
}
}
|