Navigation

 Disabling Items Feature Type: Coding Tutorials     Added: 04/02  
  Author: Corven 

How to disbale things like weapons/powerups/health/armor and any other items in the map.

Code to be Deleted or Commented out
Code to be Added or Changed

g_spawn.c

Find G_CallSpawn, this is where it will check what items and objects to spawn in the map.

if( item->giType == IT_TEAM && g_gametype.integer != GT_CTF ) {
return qfalse;
}
G_SpawnItem( ent, item );
return qtrue;

This nice bit of code tells the game to spawn(create) the item. We want to adds some checks first before it just automatically spawns the items. We're going to create a new function to hold the checking, so replace the code above with the following:

if( item->giType == IT_TEAM && g_gametype.integer != GT_CTF ) {
if( !S_CheckItem(item) ) {
return qfalse;
}
G_SpawnItem( ent, item );
return qtrue;

That will now look for the CheckItem function first and then decide which items to spawn depending on what it returns. So let's now setup that CheckItem function, add the following below the G_CallSpawn:

qboolean S_CheckItem(gitem_t *checkeditem) {

switch (checkeditem->giType)
{
case IT_WEAPON:
return qtrue;
case IT_AMMO:
return qtrue;
case IT_ARMOR:
return qtrue;
case IT_HEALTH:
return qtrue;
case IT_POWERUP:
return qtrue;
case IT_HOLDABLE:
return qtrue;
case IT_TEAM:
if (g_gametype.integer == GT_CTF)
return qtrue;
}
return qfalse;
}


What this does is run through all the different items in the map and check which it should or should not spawn, returning "qtrue" means yes go ahead and spawn that item, but returning "qfalse" means no don't spawn it.

Now, what I did was create a series of cvars, one for each of the item types, then expanded the check funtion slightly so I could turn on/off each item type individually using the different cvars, here's the weapon example:

case IT_WEAPON:
if (s_disableweapons.integer==1) {
return qfalse;
} else {

return qtrue;
}

There you go, just put in place the other cvars in a similiar fashion for each item type. Then remember to add the cvars to your server config, choosing which should be able to spawn and which should be disabled.

Comments »



  Page 1

  Comments ( 0 )


  Features Index

  Home

Copyright 2001 MGON International AB - Privacy statement