r/SourceEngine • u/Maleficent_Risk_3159 • 10d ago
HELP How does this function work?
I have this thing that needs to check if the player already has this weapon in the Deploy(); function, and if the player does have the weapon (e.g. AK-47) then it doesn't do anything but otherwise it's supposed to do something. The function I'm referring to is pPlayer->GetWeapon(); .
The code block:
bool CBaseHLCombatWeapon::Deploy( void )
{
// If we should be lowered, deploy in the lowered position
// We have to ask the player if the last time it checked, the weapon was lowered
if ( GetOwner() && GetOwner()->IsPlayer() )
{
CHL2_Player *pPlayer = assert_cast<CHL2_Player*>( GetOwner() );
//if (pPlayer->GetWeapon() <--- right here ) {
//here be something
//}
if ( pPlayer->IsWeaponLowered() )
{
if ( SelectWeightedSequence( ACT_VM_IDLE_LOWERED ) != ACTIVITY_NOT_AVAILABLE )
{
if ( DefaultDeploy( (char*)GetViewModel(), (char*)GetWorldModel(), ACT_VM_IDLE_LOWERED, (char*)GetAnimPrefix() ) )
{
m_bLowered = true;
// Stomp the next attack time to fix the fact that the lower idles are long
pPlayer->SetNextAttack( gpGlobals->curtime + 1.0 );
m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
m_flNextSecondaryAttack= gpGlobals->curtime + 1.0;
return true;
}
}
}
}
m_bLowered = false;
return BaseClass::Deploy();
}
Thank you for your help!
2
Upvotes
1
u/DimasDSF 10d ago
Not sure if you want to do that in `Deploy()` since it can only be called if you have the weapon and are trying to switch to it. But here is how Valve checked for an existing weapon in the pickup code for the cut weapon_molotov
https://github.com/ValveSoftware/source-sdk-2013/blob/77567eb4bce8d7b6b7f73e929fcde3a331c0216e/src/game/server/hl2/weapon_molotov.cpp#L99-L103
```
// ------------------------------------------------
// If already owned weapon of this type remove me
// ------------------------------------------------
CBaseCombatCharacter* pBCC = ToBaseCombatCharacter( pOther );
CWeaponMolotov* oldWeapon = (CWeaponMolotov*)pBCC->Weapon_OwnsThisType( GetClassname() );
```