|
![]() |
Intro
This is a one part tutorial that creates an entirely new entity, assigns new key/value pairs and sets it up for map authors to include in their own maps. |
![]() |
General Setup
A .MAP with the entity defined below included and positioned. |
![]() |
Tutorial Code
qboolean Pickup_Ammo_Pack (edict_t *ent, edict_t *other);
{"ammo", FOFS(ammo), F_LSTRING}, {"ammo_amount", FOFS(ammo_amount), F_INT}, ![]() Open g_local.h and goto line
977. Append this code to the edict_t definition.
void SP_item_ammo_pack (edict_t *self); At line 136, insert this code. {"item_ammo_pack", SP_item_ammo_pack},
#include "g_local.h" void droptofloor (edict_t *ent); // So we can have access to that func void SP_item_ammo_pack (edict_t *self) { self->model = "models/items/pack/tris.md2"; self->count = 100; SpawnItem (self, FindItem ("TW ammo pack")); } qboolean Pickup_Ammo_Pack (edict_t *ent, edict_t *other) { gitem_t *item; int index; if ( ent->ammo && ent->ammo_amount ) // Do we have an ammo amount and type? { if ( !Q_stricmp ( ent->ammo, "rockets" ) ) // Is it rockets or other things? { item = FindItem ( "Rockets" ); // It's rockets, find that Item if ( item ) // NOT null, so we must have something { index = ITEM_INDEX ( item ); // get it's index number other->client->pers.inventory[index] += ent->ammo_amount; // add ammo_amount } } else if ( !Q_stricmp ( ent->ammo, "shells" ) ) { item = FindItem ( "Shells" ); if ( item ) { index = ITEM_INDEX ( item ); other->client->pers.inventory[index] += ent->ammo_amount; } } else if ( !Q_stricmp ( ent->ammo, "slugs" ) ) { item = FindItem ( "Slugs" ); if ( item ) { index = ITEM_INDEX ( item ); other->client->pers.inventory[index] += ent->ammo_amount; } } else if ( !Q_stricmp ( ent->ammo, "cells" ) ) { item = FindItem ( "Cells" ); if ( item ) { index = ITEM_INDEX ( item ); other->client->pers.inventory[index] += ent->ammo_amount; } } else if ( !Q_stricmp ( ent->ammo, "grenades" ) ) { item = FindItem ( "Grenades" ); if ( item ) { index = ITEM_INDEX ( item ); other->client->pers.inventory[index] += ent->ammo_amount; } } SetRespawn ( ent, 20 ); return true; } return false; } |
![]() |
Ending
|