Skip to content

Commit

Permalink
feat: added toggable weapon holster with command player input
Browse files Browse the repository at this point in the history
  • Loading branch information
FeiRoN23 committed Jan 16, 2024
1 parent a6f0c32 commit 6b5ab22
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
11 changes: 11 additions & 0 deletions cl_dll/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ kbutton_t in_alt1;
kbutton_t in_score;
kbutton_t in_break;
kbutton_t in_graph; // Display the netgraph
kbutton_t in_holster;

typedef struct kblist_s
{
Expand Down Expand Up @@ -476,6 +477,8 @@ void IN_DuckDown()
void IN_DuckUp() { KeyUp(&in_duck); }
void IN_ReloadDown() { KeyDown(&in_reload); }
void IN_ReloadUp() { KeyUp(&in_reload); }
void IN_HolsterUp() { KeyUp(&in_holster); }
void IN_HolsterDown(){ KeyDown(&in_holster); }
void IN_Alt1Down() { KeyDown(&in_alt1); }
void IN_Alt1Up() { KeyUp(&in_alt1); }
void IN_GraphDown() { KeyDown(&in_graph); }
Expand Down Expand Up @@ -845,6 +848,11 @@ int CL_ButtonBits(bool bResetState)
bits |= IN_RELOAD;
}

if ((in_holster.state & 3) != 0)
{
bits |= IN_HOLSTER;
}

if ((in_alt1.state & 3) != 0)
{
bits |= IN_ALT1;
Expand Down Expand Up @@ -877,6 +885,7 @@ int CL_ButtonBits(bool bResetState)
in_reload.state &= ~2;
in_alt1.state &= ~2;
in_score.state &= ~2;
in_holster.state &= ~2;
}

return bits;
Expand Down Expand Up @@ -968,6 +977,8 @@ void InitInput()
gEngfuncs.pfnAddCommand("-graph", IN_GraphUp);
gEngfuncs.pfnAddCommand("+break", IN_BreakDown);
gEngfuncs.pfnAddCommand("-break", IN_BreakUp);
gEngfuncs.pfnAddCommand("+holster", IN_HolsterDown);
gEngfuncs.pfnAddCommand("-holster", IN_HolsterUp);

lookstrafe = gEngfuncs.pfnRegisterVariable("lookstrafe", "0", FCVAR_ARCHIVE);
lookspring = gEngfuncs.pfnRegisterVariable("lookspring", "0", FCVAR_ARCHIVE);
Expand Down
3 changes: 2 additions & 1 deletion common/in_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
#define IN_RUN (1 << 12)
#define IN_RELOAD (1 << 13)
#define IN_ALT1 (1 << 14)
#define IN_SCORE (1 << 15) // Used by client.dll for when scoreboard is held down
#define IN_HOLSTER (1 << 15)
#define IN_SCORE (1 << 16) // Used by client.dll for when scoreboard is held down
1 change: 1 addition & 0 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,7 @@ void CBasePlayer::SelectItem(const char* pstr)
m_pActiveItem->m_ForceSendAnimations = true;
m_pActiveItem->Deploy();
m_pActiveItem->m_ForceSendAnimations = false;
m_pActiveItem->GetWeaponPtr()->m_holstered = false;
m_pActiveItem->UpdateItemInfo();
}
}
Expand Down
10 changes: 10 additions & 0 deletions dlls/silencedglock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool CSilencedGlock::GetItemInfo(ItemInfo* p)
bool CSilencedGlock::Deploy()
{
// pev->body = 1;
m_holstered = false;
return DefaultDeploy("models/v_silencedglock.mdl", "models/p_silencedglock.mdl", GLOCK_DRAW, "onehanded");
}
void CSilencedGlock::SecondaryAttack()
Expand Down Expand Up @@ -173,3 +174,12 @@ void CSilencedGlock::WeaponIdle()
SendWeaponAnim(iAnim);
}
}

void CSilencedGlock::Holster()
{
ALERT(at_console, "SIlenced glock holster func called \n");
m_holstered = true;
SendWeaponAnim(GLOCK_HOLSTER);
}


2 changes: 1 addition & 1 deletion dlls/silencedglock.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CSilencedGlock: public CBasePlayerWeapon
bool Deploy() override;
void Reload() override;
void WeaponIdle() override;
void Holster() override;

bool UseDecrement() override
{
Expand All @@ -35,5 +36,4 @@ class CSilencedGlock: public CBasePlayerWeapon
unsigned short m_usFireGlock1;
unsigned short m_usFireGlock2;


};
1 change: 1 addition & 0 deletions dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ void CBasePlayerWeapon::Holster()
m_fInReload = false; // cancel any reload in progress.
m_pPlayer->pev->viewmodel = 0;
m_pPlayer->pev->weaponmodel = 0;
m_holstered = true;
}

void CBasePlayerAmmo::Spawn()
Expand Down
1 change: 1 addition & 0 deletions dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class CBasePlayerWeapon : public CBasePlayerItem
int m_iClientClip; // the last version of m_iClip sent to hud dll
int m_iClientWeaponState; // the last version of the weapon state sent to hud dll (is current weapon, is on target)
bool m_fInReload; // Are we in the middle of a reload;
bool m_holstered;

int m_iDefaultAmmo; // how much ammo you get when you pick up this weapon as placed by a level designer.

Expand Down
22 changes: 19 additions & 3 deletions dlls/weapons_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ void CBasePlayerWeapon::ItemPostFrame()
m_flLastFireTime = 0.0f;
}

if((m_pPlayer->m_afButtonPressed & IN_HOLSTER) != 0 && !m_fInReload)
{
ALERT(at_console, "Holster key pressed\n");
if(m_holstered)
{
m_holstered = false;
Deploy();
}
else
Holster();
return;
}

if(m_pPlayer->pev->button & (IN_ATTACK2 | IN_ATTACK) && m_holstered) {
return;
}

if ((m_pPlayer->pev->button & IN_ATTACK2) != 0 && CanAttack(m_flNextSecondaryAttack, gpGlobals->time, UseDecrement()))
{
if (pszAmmo2() && 0 == m_pPlayer->m_rgAmmo[SecondaryAmmoIndex()])
Expand All @@ -164,7 +181,7 @@ void CBasePlayerWeapon::ItemPostFrame()
// reload when reload is pressed, or if no buttons are down and weapon is empty.
Reload();
}
else if ((m_pPlayer->pev->button & (IN_ATTACK | IN_ATTACK2)) == 0)
else if ((m_pPlayer->pev->button & (IN_ATTACK | IN_ATTACK2)) == 0 && !m_holstered)
{
// no fire buttons down

Expand All @@ -190,13 +207,12 @@ void CBasePlayerWeapon::ItemPostFrame()
return;
}
}

WeaponIdle();
return;
}

// catch all
if (ShouldWeaponIdle())
if (ShouldWeaponIdle() && !m_holstered)
{
WeaponIdle();
}
Expand Down

0 comments on commit 6b5ab22

Please sign in to comment.