From 20b66b95fab24b867667673de27676f59c6ab593 Mon Sep 17 00:00:00 2001 From: Justin <95296300+Toodles2You@users.noreply.github.com> Date: Sat, 19 Aug 2023 12:43:35 -0700 Subject: [PATCH] Have clients select weapons by ID, rather than by name --- cl_dll/ammo.cpp | 4 +-- cl_dll/hl/hl_baseentity.cpp | 2 ++ cl_dll/hl/hl_weapons.cpp | 33 ------------------------ dlls/client.cpp | 6 +++++ dlls/player.cpp | 50 +++++++++++++++++++++++++++++++++++++ dlls/player.h | 1 + network/delta.lst | 3 ++- 7 files changed, 63 insertions(+), 36 deletions(-) diff --git a/cl_dll/ammo.cpp b/cl_dll/ammo.cpp index 26c1c56d1..65b937476 100644 --- a/cl_dll/ammo.cpp +++ b/cl_dll/ammo.cpp @@ -372,7 +372,7 @@ void CHudAmmo::Think() { if (gpActiveSel != (WEAPON*)1) { - ServerCmd(gpActiveSel->szName); + // ServerCmd(gpActiveSel->szName); g_weaponselect = gpActiveSel->iId; } @@ -445,7 +445,7 @@ void WeaponsResource::SelectSlot(int iSlot, bool fAdvance, int iDirection) WEAPON* p2 = GetNextActivePos(p->iSlot, p->iSlotPos); if (!p2) { // only one active item in bucket, so change directly to weapon - ServerCmd(p->szName); + // ServerCmd(p->szName); g_weaponselect = p->iId; return; } diff --git a/cl_dll/hl/hl_baseentity.cpp b/cl_dll/hl/hl_baseentity.cpp index 1e0c94004..b53b50295 100644 --- a/cl_dll/hl/hl_baseentity.cpp +++ b/cl_dll/hl/hl_baseentity.cpp @@ -258,6 +258,8 @@ bool CBasePlayer::Restore(CRestore& restore) { return false; } void CBasePlayer::SelectNextItem(int iItem) {} bool CBasePlayer::HasWeapons() { return false; } void CBasePlayer::SelectPrevItem(int iItem) {} +void CBasePlayer::SelectItem(const char* pstr) {} +void CBasePlayer::SelectItem(int iId) {} bool CBasePlayer::FlashlightIsOn() { return false; } void CBasePlayer::FlashlightTurnOn() {} void CBasePlayer::FlashlightTurnOff() {} diff --git a/cl_dll/hl/hl_weapons.cpp b/cl_dll/hl/hl_weapons.cpp index 94705ccb2..1865dbd79 100644 --- a/cl_dll/hl/hl_weapons.cpp +++ b/cl_dll/hl/hl_weapons.cpp @@ -256,39 +256,6 @@ Vector CBaseEntity::FireBulletsPlayer(unsigned int cShots, Vector vecSrc, Vector return Vector(x * vecSpread.x, y * vecSpread.y, 0.0); } -/* -===================== -CBasePlayer::SelectItem - - Switch weapons -===================== -*/ -void CBasePlayer::SelectItem(const char* pstr) -{ - if (!pstr) - return; - - CBasePlayerItem* pItem = NULL; - - if (!pItem) - return; - - - if (pItem == m_pActiveItem) - return; - - if (m_pActiveItem) - m_pActiveItem->Holster(); - - m_pLastItem = m_pActiveItem; - m_pActiveItem = pItem; - - if (m_pActiveItem) - { - m_pActiveItem->Deploy(); - } -} - /* ===================== CBasePlayer::Killed diff --git a/dlls/client.cpp b/dlls/client.cpp index 145ff0fe2..961e96770 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -1809,6 +1809,12 @@ void CmdStart(const edict_t* player, const struct usercmd_s* cmd, unsigned int r if (!pl) return; + if (cmd->weaponselect != 0) + { + pl->SelectItem(cmd->weaponselect); + ((usercmd_t*)cmd)->weaponselect = 0; + } + if (pl->pev->groupinfo != 0) { UTIL_SetGroupTrace(pl->pev->groupinfo, GROUP_OP_AND); diff --git a/dlls/player.cpp b/dlls/player.cpp index 6b3161f94..cc5788daa 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -3097,6 +3097,56 @@ void CBasePlayer::SelectItem(const char* pstr) } } +void CBasePlayer::SelectItem(int iId) +{ + if (iId <= WEAPON_NONE) + return; + + CBasePlayerItem* pItem = NULL; + + for (int i = 0; i < MAX_ITEM_TYPES; i++) + { + if (m_rgpPlayerItems[i]) + { + pItem = m_rgpPlayerItems[i]; + + while (pItem) + { + if (pItem->m_iId == iId) + break; + pItem = pItem->m_pNext; + } + } + + if (pItem) + break; + } + + if (!pItem) + return; + + + if (pItem == m_pActiveItem) + return; + + ResetAutoaim(); + + // FIX, this needs to queue them up and delay + if (m_pActiveItem) + m_pActiveItem->Holster(); + + m_pLastItem = m_pActiveItem; + m_pActiveItem = pItem; + + if (m_pActiveItem) + { + m_pActiveItem->m_ForceSendAnimations = true; + m_pActiveItem->Deploy(); + m_pActiveItem->m_ForceSendAnimations = false; + m_pActiveItem->UpdateItemInfo(); + } +} + //============================================== // HasWeapons - do I have any weapons at all? //============================================== diff --git a/dlls/player.h b/dlls/player.h index 9cdd9ea3b..f6bebcd4b 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -288,6 +288,7 @@ class CBasePlayer : public CBaseMonster void SelectNextItem(int iItem); void SelectLastItem(); void SelectItem(const char* pstr); + void SelectItem(int iId); void ItemPreFrame(); void ItemPostFrame(); void GiveNamedItem(const char* szName); diff --git a/network/delta.lst b/network/delta.lst index a73a7b276..c25a677d0 100644 --- a/network/delta.lst +++ b/network/delta.lst @@ -222,7 +222,8 @@ usercmd_t none DEFINE_DELTA( impact_index, DT_INTEGER, 6, 1.0 ), DEFINE_DELTA( impact_position[0], DT_SIGNED | DT_FLOAT, 16, 8.0 ), DEFINE_DELTA( impact_position[1], DT_SIGNED | DT_FLOAT, 16, 8.0 ), - DEFINE_DELTA( impact_position[2], DT_SIGNED | DT_FLOAT, 16, 8.0 ) + DEFINE_DELTA( impact_position[2], DT_SIGNED | DT_FLOAT, 16, 8.0 ), + DEFINE_DELTA( weaponselect, DT_BYTE, 6, 1.0 ) } weapon_data_t none