This is my crowbar code:
I have declared all variables:
void CCrowbar::Spawn( )
{
Precache( );
m_iId = WEAPON_CROWBAR;
m_iClip = -1;
m_iCall = 0;// NUEVO. Limitador del uso de boton de recarga
FallInit();// get ready to fall down.
}
Added the secondary Ammo
int CCrowbar::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = NULL;
p->iMaxAmmo1 = -1;
p->pszAmmo2 = "ARgrenades";
p->iMaxAmmo2 = 10;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 0;
p->iPosition = 0;
p->iId = WEAPON_CROWBAR;
p->iFlags = 0;//Nuevo
p->iWeight = CROWBAR_WEIGHT;
return 1;
}
Here´s the rest of the ammo part:
//=========================================================
int CCrowbar::SecondaryAmmoIndex( void )
{
return m_iSecondaryAmmoType;
}
//=========================================================
And this is the reload function. It has no modifications different from the rest of weapons (and they work) :
void CCrowbar::Reload( void )
{
//========================================================================================================
// New RELOAD call. It will activates the monstermakers from distance.
//--------------------------------------------------------------------------------------------------------
// (c) Solokiller & Shepard62700FR
//=========================================================================================================
if ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 100 || m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] <= 0 || !TriggerReleased /*Nuevo!!*/|| m_iCall >= 1 /*Nuevo!!*/ )
return;
//Limitador del uso del boton de recarga
else if ( ( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= 500) )
{
m_iCall -=1;
}
edict_t *pPlayer = m_pPlayer->edict( );
CBaseEntity *pEntity = NULL;
//Pass pEntity as the start entity to search through all entities properly. - Solokiller
while ((pEntity = UTIL_FindEntityInSphere( pEntity, m_pPlayer->pev->origin, 500000.0f)) !=NULL)
{
//Check if the targetname matches the owning player's team to filter monstermakers. - Solokiller
if ( FClassnameIs( pEntity->pev, "monstermaker" ) && FStrEq( STRING( pEntity->pev->targetname ), m_pPlayer->TeamID() ) )
{
pEntity->Use( m_pPlayer, m_pPlayer, USE_ON, 0.0f );
}
}
ALERT( at_console, "RELOAD!!\n" );
m_pPlayer->m_rgAmmo[m_iSecondaryAmmoType] -= 1;
TriggerReleased = FALSE;
EMIT_SOUND(ENT(pev), CHAN_ITEM, "weapons/reload.wav", 1, ATTN_NORM);//Aqui va lo del sonido
m_iCall +=1;//Nuevo
}
And in weapons.h I have done all stuf afaik:
class CCrowbar : public CBasePlayerWeapon
{
public:
void Spawn( void );
void Precache( void );
int iItemSlot( void ) { return 1; }
void EXPORT SwingAgain( void );
void EXPORT Smack( void );
int GetItemInfo(ItemInfo *p);
void PrimaryAttack( void );
int Swing( int fFirst );
BOOL Deploy( void );
void Holster( int skiplocal = 0 );
int m_iSwing;
TraceResult m_trHit;
int m_iCall;
// Añadida recarga al CROWBAR
int SecondaryAmmoIndex( void );
void Reload( void );
BOOL TriggerReleased;// Limitador de tiempo para recarga
virtual BOOL UseDecrement( void )
{
#if defined( CLIENT_WEAPONS )
return TRUE;
#else
return FALSE;
#endif
}
private:
float m_flFreezeTime; // Freeze Player Timer
unsigned short m_usCrowbar;
};
The weapon works flawlessly, sprites are shown, but the RELOAD does not work at all. I have compiled both hl.dll and client.dll with no problems at all. In the rest of weapons it works, but not in the Crowbar. I have added this code to make the BOTS can use the crowbar and call for RELOAD when they run out of ammo. Did I miss something? (apart of reading more C++ book, I know that, please be merciful... XD )Thanks in anticipation.