From d80d87366ac65466ccaedaadf73ff7afbca935f7 Mon Sep 17 00:00:00 2001
From: Vaqtincha <51029683+Vaqtincha@users.noreply.github.com>
Date: Sat, 22 May 2021 16:15:28 +0500
Subject: [PATCH] game_player_equip fixes/enhancement (#618)
* game_player_equip: Check UseOnly flag
* New flag SF_PLAYEREQUIP_REMOVEWEAPONS
---
dep/cppunitlite/msvc/cppunitlite.vcxproj | 2 +-
regamedll/dlls/maprules.cpp | 17 ++++++++++-------
regamedll/dlls/maprules.h | 13 +++++++++++++
regamedll/dlls/player.cpp | 13 ++++++++++---
.../Toolkit/GameDefinitionFile/regamedll-cs.fgd | 1 +
5 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/dep/cppunitlite/msvc/cppunitlite.vcxproj b/dep/cppunitlite/msvc/cppunitlite.vcxproj
index e3cb49a6..fbda29b7 100644
--- a/dep/cppunitlite/msvc/cppunitlite.vcxproj
+++ b/dep/cppunitlite/msvc/cppunitlite.vcxproj
@@ -102,4 +102,4 @@
-
\ No newline at end of file
+
diff --git a/regamedll/dlls/maprules.cpp b/regamedll/dlls/maprules.cpp
index b9e27fbc..2d73d2b4 100644
--- a/regamedll/dlls/maprules.cpp
+++ b/regamedll/dlls/maprules.cpp
@@ -565,13 +565,10 @@ void CGamePlayerEquip::KeyValue(KeyValueData *pkvd)
void CGamePlayerEquip::Touch(CBaseEntity *pOther)
{
- if (!CanFireForActivator(pOther))
- return;
-
- if (UseOnly())
- return;
-
- EquipPlayer(pOther);
+ if (CanEquipOverTouch(pOther))
+ {
+ EquipPlayer(pOther);
+ }
}
void CGamePlayerEquip::EquipPlayer(CBaseEntity *pEntity)
@@ -580,6 +577,12 @@ void CGamePlayerEquip::EquipPlayer(CBaseEntity *pEntity)
return;
CBasePlayer *pPlayer = static_cast(pEntity);
+
+ if (RemoveWeapons())
+ {
+ pPlayer->RemoveAllItems(FALSE);
+ }
+
for (int i = 0; i < MAX_EQUIP; i++)
{
if (FStringNull(m_weaponNames[i]))
diff --git a/regamedll/dlls/maprules.h b/regamedll/dlls/maprules.h
index 80da1c8d..1690795e 100644
--- a/regamedll/dlls/maprules.h
+++ b/regamedll/dlls/maprules.h
@@ -245,6 +245,7 @@ public:
#define MAX_EQUIP 32
#define SF_PLAYEREQUIP_USEONLY BIT(0) // If set, the game_player_equip entity will not equip respawning players,
// but only react to direct triggering, equipping its activator. This makes its master obsolete.
+#define SF_PLAYEREQUIP_REMOVEWEAPONS BIT(1) // Remove all weapons before give.
// Sets the default player equipment
class CGamePlayerEquip: public CRulePointEntity
@@ -256,6 +257,18 @@ public:
public:
bool UseOnly() const { return (pev->spawnflags & SF_PLAYEREQUIP_USEONLY) == SF_PLAYEREQUIP_USEONLY; }
+ bool RemoveWeapons() const { return (pev->spawnflags & SF_PLAYEREQUIP_REMOVEWEAPONS) == SF_PLAYEREQUIP_REMOVEWEAPONS; }
+
+ bool CanEquipOverTouch(CBaseEntity *pOther)
+ {
+ if (!CanFireForActivator(pOther))
+ return false;
+
+ if (UseOnly())
+ return false;
+
+ return true;
+ }
private:
void EquipPlayer(CBaseEntity *pPlayer);
diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp
index 44ab9a56..e3cac4fc 100644
--- a/regamedll/dlls/player.cpp
+++ b/regamedll/dlls/player.cpp
@@ -9889,11 +9889,18 @@ void EXT_FUNC CBasePlayer::__API_HOOK(OnSpawnEquip)(bool addDefault, bool equipG
{
if (equipGame)
{
- CBaseEntity *pWeaponEntity = nullptr;
+ CGamePlayerEquip *pWeaponEntity = nullptr;
while ((pWeaponEntity = UTIL_FindEntityByClassname(pWeaponEntity, "game_player_equip")))
{
- pWeaponEntity->Touch(this);
- addDefault = false;
+
+#ifdef REGAMEDLL_FIXES
+ if (pWeaponEntity->CanEquipOverTouch(this))
+#endif
+ {
+ pWeaponEntity->Touch(this);
+
+ addDefault = false;
+ }
}
}
diff --git a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
index 861a7f6a..50ca2b55 100644
--- a/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
+++ b/regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
@@ -1407,6 +1407,7 @@
spawnflags(flags) =
[
1: "Use Only" : 0
+ 2: "Remove Weapons" : 0
]
weapon_knife (choices) : "Give Knife" : 0 =
[