Navigation

 Team Weapons Feature Type: Coding Tutorials     Added: 24/01  
  Author: Corven 

How to give different weapons to different teams.

Rocket vs Rail

Code to be Added or Changed

g_client.c

Find the ClientSpawn function, all things in there are what happens when the player spawns in the game. Find the following lines:

client->ps.stats[STAT_WEAPONS] = ( 1 << WP_MACHINEGUN );
if ( g_gametype.integer == GT_TEAM ) {
client->ps.ammo[WP_MACHINEGUN] = 50;
} else {
client->ps.ammo[WP_MACHINEGUN] = 100;
}

Now this tells the game to give them the machinegun, and if the gametype is a team game, then choose its amount of ammo. We are going to change and add to this, like so:


if ( g_gametype.integer == GT_TEAM ) {
if ( client->sess.sessionTeam == TEAM_RED ) {
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_ROCKET_LAUNCHER );
client->ps.ammo[WP_ROCKET_LAUNCHER] = 20;
} else if ( client->sess.sessionTeam == TEAM_BLUE ) {
client->ps.stats[STAT_WEAPONS] |= ( 1 << WP_RAILGUN );
client->ps.ammo[WP_RAILGUN] = 10;
} else {
client->ps.stats[STAT_WEAPONS] = ( 1 << WP_MACHINEGUN );
client->ps.ammo[WP_MACHINEGUN] = 50;
}
} else {
client->ps.stats[STAT_WEAPONS] = ( 1 << WP_MACHINEGUN );
client->ps.ammo[WP_MACHINEGUN] = 100;
}


What we've done is first tell it to check if we're playing a team game, if so then check if the player is on TEAM_RED then give them the rocket launcher and ammo, else if they are on TEAM_BLUE give them the railgun and ammo, else give them the usual machinegun.

But usually the first weapon they have is the machinegun, so we have to tell the game to make them use the rocketlauncher or railgun first instead, so look further down the same function till you see:

client->ps.weapon = WP_MACHINEGUN;
client->ps.weaponstate = WEAPON_READY;

And now change that too:
if ( client->sess.sessionTeam == TEAM_RED ) {
client->ps.weapon = WP_ROCKET_LAUNCHER;
client->ps.weaponstate = WEAPON_READY;
} else if ( client->sess.sessionTeam == TEAM_BLUE ) {
client->ps.weapon = WP_RAILGUN;
client->ps.weaponstate = WEAPON_READY;
} else {
client->ps.weapon = WP_MACHINEGUN;
client->ps.weaponstate = WEAPON_READY;
}


Dont' forget if your planning on giving them different weapons like the rocket launcher or railgun that might not be in the map, it's a good idea to register those weapons as the game loads, so the needed weapon media is cache and ready to use.

g_items.c

Now find the ClearRegisteredItems funtion, these lines:

RegisterItem( BG_FindItemForWeapon( WP_MACHINEGUN ) );
RegisterItem( BG_FindItemForWeapon( WP_GAUNTLET ) );

Now add the following so it will register the weapons if we are playing a team game:

if (g_gametype.integer == GT_TEAM) {
RegisterItem( BG_FindItemForWeapon( WP_ROCKET_LAUNCHER) );
RegisterItem( BG_FindItemForWeapon( WP_RAILGUN) );
}


The above example is only for Team Deathmatch gametype, but ofcourse you could change the check so it does the same for every team based game using:
if (g_gametype.integer >= GT_TEAM) {

Comments »



  Page 1

  Comments ( 0 )


  Features Index

  Home

Copyright 2001 MGON International AB - Privacy statement