From b624a618979a1cb40422e3afbfd962c5b866b331 Mon Sep 17 00:00:00 2001 From: Sam V Date: Wed, 3 Aug 2022 15:27:20 +0200 Subject: [PATCH] Add keyvalue to disable item dropping SamVanheer/halflife-op4-updated#72 --- dlls/basemonster.h | 8 +++++++- dlls/monsters.cpp | 12 +++++++++++- fgd/halflife.fgd | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dlls/basemonster.h b/dlls/basemonster.h index 2b04642..8121325 100644 --- a/dlls/basemonster.h +++ b/dlls/basemonster.h @@ -109,6 +109,8 @@ public: float m_flLastYawTime; + bool m_AllowItemDropping = true; + bool Save(CSave& save) override; bool Restore(CRestore& restore) override; @@ -356,5 +358,9 @@ public: bool ExitScriptedSequence(); bool CineCleanup(); - CBaseEntity* DropItem(const char* pszItemName, const Vector& vecPos, const Vector& vecAng); // drop an item. + /** + * @brief Drop an item. + * Will return @c nullptr if item dropping is disabled for this NPC. + */ + CBaseEntity* DropItem(const char* pszItemName, const Vector& vecPos, const Vector& vecAng); }; diff --git a/dlls/monsters.cpp b/dlls/monsters.cpp index af48098..b70ec54 100644 --- a/dlls/monsters.cpp +++ b/dlls/monsters.cpp @@ -100,6 +100,7 @@ TYPEDESCRIPTION CBaseMonster::m_SaveData[] = DEFINE_FIELD(CBaseMonster, m_scriptState, FIELD_INTEGER), DEFINE_FIELD(CBaseMonster, m_pCine, FIELD_CLASSPTR), + DEFINE_FIELD(CBaseMonster, m_AllowItemDropping, FIELD_BOOLEAN), }; //IMPLEMENT_SAVERESTORE( CBaseMonster, CBaseToggle ); @@ -2977,6 +2978,10 @@ bool CBaseMonster::KeyValue(KeyValueData* pkvd) m_iTriggerCondition = atoi(pkvd->szValue); return true; } + else if (FStrEq(pkvd->szKeyName, "allow_item_dropping")) + { + m_AllowItemDropping = atoi(pkvd->szValue) != 0; + } return CBaseToggle::KeyValue(pkvd); } @@ -3411,7 +3416,12 @@ CBaseEntity* CBaseMonster::DropItem(const char* pszItemName, const Vector& vecPo if (!pszItemName) { ALERT(at_console, "DropItem() - No item name!\n"); - return NULL; + return nullptr; + } + + if (!m_AllowItemDropping) + { + return nullptr; } CBaseEntity* pItem = CBaseEntity::Create(pszItemName, vecPos, vecAng, edict()); diff --git a/fgd/halflife.fgd b/fgd/halflife.fgd index 04705bd..88db304 100644 --- a/fgd/halflife.fgd +++ b/fgd/halflife.fgd @@ -180,6 +180,12 @@ 256: "Pre-Disaster" : 0 512: "Fade Corpse" : 0 ] + + allow_item_dropping(choices) : "Allow Item Dropping" : 1 : "This controls whether this NPC will drop items on death" = + [ + 0 : "No" + 1 : "Yes" + ] ] @BaseClass = TalkMonster