-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added custom buttons entity that delivers different ammo type o…
…n impulse use
- Loading branch information
Showing
5 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,82 @@ | ||
#include "ammodispenser.h" | ||
|
||
LINK_ENTITY_TO_CLASS(ammo_dispenser, CAmmoDispenser) | ||
const char* CButtonDispenser::ammoTypesNames[] = | ||
{ | ||
"ammo_9mmclip", | ||
"ammo_9mmAR", | ||
"ammo_buckshot", | ||
}; | ||
|
||
void CAmmoDispenser::Spawn() | ||
void CObjectDispenser::Spawn() | ||
{ | ||
pev->solid = SOLID_NOT; | ||
pev->movetype = MOVETYPE_NONE; | ||
ALERT(at_console, "Ammo dispenser spawned\n"); | ||
//UTIL_SetSize(pev, Vector(0, 0, 0), Vector(0, 0, 0)); | ||
|
||
} | ||
|
||
void CAmmoDispenser::dispense_ammo() { | ||
ALERT(at_console, "dispensing 9mm ammo\n"); | ||
//Create("item_sodacan", pev->origin, pev->angles, edict()); | ||
void CObjectDispenser::dispense_ammo(string_t ammoType) { | ||
ALERT(at_console, "dispensing %s\n", STRING(ammoType)); | ||
edict_t* pent; | ||
pent = CREATE_NAMED_ENTITY(MAKE_STRING("ammo_9mmclip")); | ||
pent = CREATE_NAMED_ENTITY(ammoType); | ||
|
||
if (FNullEnt(pent)) | ||
{ | ||
ALERT(at_console, "NULL Ent in Create!\n"); | ||
return; | ||
} | ||
|
||
CBaseEntity* ammoEntity = Instance(pent); | ||
|
||
ammoEntity->pev->origin = pev->origin; | ||
ammoEntity->pev->origin = Vector(pev->origin.x, pev->origin.y, pev->origin.z - 2.5f); | ||
ammoEntity->pev->angles = pev->angles; | ||
ammoEntity->Spawn(); | ||
ammoEntity->pev->movetype = MOVETYPE_NONE; | ||
ammoEntity->pev->solid = SOLID_TRIGGER; | ||
|
||
} | ||
|
||
LINK_ENTITY_TO_CLASS(ammo_dispenser, CObjectDispenser) | ||
|
||
void CButtonDispenser::Spawn() | ||
{ | ||
pev->movetype = MOVETYPE_PUSH; | ||
pev->solid = SOLID_BSP; | ||
SET_MODEL(ENT(pev), STRING(pev->model)); | ||
SetUse(&CButtonDispenser::Use); | ||
} | ||
|
||
//Old method to spawn | ||
//Create("ammo_9mmclip", pev->origin, pev->angles, edict()); | ||
|
||
void CButtonDispenser::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) | ||
{ | ||
if(pActivator->IsPlayer()) | ||
{ | ||
|
||
CBaseEntity* dispBaseEnt = UTIL_FindEntityByTargetname(nullptr, STRING(pev->target)); | ||
|
||
if (dispBaseEnt) | ||
{ | ||
auto dispenserEnt = dynamic_cast<CObjectDispenser*>(dispBaseEnt); | ||
dispenserEnt->dispense_ammo(m_spawnAmmoName); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
void CAmmoDispenser::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) | ||
bool CButtonDispenser::KeyValue(KeyValueData* pkvd) | ||
{ | ||
ALERT(at_console, "using dispenser targeting %s\n", STRING(pev->target)); | ||
dispense_ammo(); | ||
if (FStrEq(pkvd->szKeyName, "ammoSpawn")) | ||
{ | ||
int object = atoi(pkvd->szValue); | ||
if (object >= 0 && object < ARRAYSIZE(ammoTypesNames)) | ||
m_spawnAmmoName = MAKE_STRING(ammoTypesNames[object]); | ||
return true; | ||
} | ||
} | ||
|
||
|
||
LINK_ENTITY_TO_CLASS(func_button_dispenser, CButtonDispenser); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.