Skip to content

Commit

Permalink
Have clients select weapons by ID, rather than by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Toodles2You committed Aug 19, 2023
1 parent 0285a6e commit 20b66b9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 36 deletions.
4 changes: 2 additions & 2 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void CHudAmmo::Think()
{
if (gpActiveSel != (WEAPON*)1)
{
ServerCmd(gpActiveSel->szName);
// ServerCmd(gpActiveSel->szName);
g_weaponselect = gpActiveSel->iId;
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/hl/hl_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
33 changes: 0 additions & 33 deletions cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 50 additions & 0 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
//==============================================
Expand Down
1 change: 1 addition & 0 deletions dlls/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion network/delta.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20b66b9

Please sign in to comment.