Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

game_player_equip fixes/enhancement #618

Merged
merged 6 commits into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dep/cppunitlite/msvc/cppunitlite.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
17 changes: 10 additions & 7 deletions regamedll/dlls/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -580,6 +577,12 @@ void CGamePlayerEquip::EquipPlayer(CBaseEntity *pEntity)
return;

CBasePlayer *pPlayer = static_cast<CBasePlayer *>(pEntity);

if (RemoveWeapons())
{
pPlayer->RemoveAllItems(FALSE);
}

for (int i = 0; i < MAX_EQUIP; i++)
{
if (FStringNull(m_weaponNames[i]))
Expand Down
13 changes: 13 additions & 0 deletions regamedll/dlls/maprules.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class CGameCounterSet: public CRulePointEntity
#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
Expand All @@ -256,6 +257,18 @@ class CGamePlayerEquip: public CRulePointEntity

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);
Expand Down
13 changes: 10 additions & 3 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9888,11 +9888,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;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@
spawnflags(flags) =
[
1: "Use Only" : 0
2: "Remove Weapons" : 0
]
weapon_knife (choices) : "Give Knife" : 0 =
[
Expand Down