
|
Created By: |
Robert Elsner |
|
eMail: |
|
|
Difficulty Scale: |
Medium/Hard |
|
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
Goto line 19 and append this code after the definition of Weapon_BFG.qboolean Pickup_Ammo_Pack (edict_t *ent, edict_t *other);
Open g_save.c and goto line 6. Insert the following code. {"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.
Open g_spawn.c and at line 126 append this code.void SP_item_ammo_pack (edict_t *self); At line 136, insert this code. {"item_ammo_pack", SP_item_ammo_pack},
Create a new file named ammo.c and add it to the project file. Insert the following code into ammo.c.#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
{ "classname" "item_ammo_pack" "origin" "-120 -256 300" "ammo" "rockets" "ammo_amount" "15"
} |