I want to create an item that doubles all the damage done by the player, but I don't know how to achieve that.
As far as I know, there is nothing in the Half-Life source code that looks like the item I want to create, so that's why I'm asking for your help.
The concept is simple but at the same time complicated: Once you pick up the item, for 15 seconds all the damage you do with your weapons will be double. After 15 seconds, the item will be removed from your inventory, and the effect will end. Now you can pick up another item of these.
Oh, Lords of Coding, I invoke you!
I have only written the basic structure of my item, at the bottom of
items.cpp
:
// An item that doubles all the damage done.
class CDamageDoubler : public CItem
{
void CDamageDoubler :: Spawn( void )
{
Precache();
SET_MODEL(ENT(pev), "models/w_rad.mdl");
CItem::Spawn();
}
void CDamageDoubler :: Precache( void )
{
PRECACHE_MODEL("models/w_rad.mdl");
PRECACHE_SOUND("scientist/sci_pain3.wav"); // stahp sound
}
BOOL CDamageDoubler :: MyTouch( CBasePlayer *pPlayer )
{
if ( pPlayer->m_fDamageDoubler ) // If the player owns this item, then he cannot take another.
{
return FALSE;
}
if ( ( pPlayer->pev->weapons & (1<<WEAPON_SUIT) ) ) // The player can take this item only if he is wearing the HEV suit
{
ALERT( at_console, "You have picked up the damage doubler\n" ); // Display a message on the console.
EMIT_SOUND(ENT(pPlayer->pev), CHAN_ITEM, "scientist/sci_pain3.wav", 1, ATTN_NORM); // play the stahp sound
pPlayer->m_fDamageDoubler = TRUE;
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( item_damage_doubler, CDamageDoubler );
m_fDamageDoubler
is declared somewhere in player.h
:
BOOL m_fDamageDoubler; // For my item that doubles the damage done
Thanks in advance!!!