Posted by: ScoBra7
Date posted: Apr 07 2003 User Rating: 5 out of 5.0 | Number of views: 2366 Number of comments: 0 | Description: How nasty can you get! |
In this tutorial we will add a new type of Satchel using the weapons box as a model. What is the first thing people run to pick up? The weapons box! So we are going to equip this booby trap with a proximity fuse.
First open the mp.dll workspace. Open the satchel.cpp and add the following after this CSatchelCharge class
| | class CBoobyTrap: public CSatchelCharge { public: void Spawn( void ); void Precache( void ); void EXPORT BoobyThink( void ); private: float m_flActivateProximity; bool m_bPlaySound; bool CheckProx(int iRaduis); float m_flProximityCheckInterval;
}; LINK_ENTITY_TO_CLASS( monster_booby, CBoobyTrap );
void CBoobyTrap::Spawn(void) { Precache( ); // motor pev->movetype = MOVETYPE_BOUNCE; pev->solid = SOLID_BBOX;
SET_MODEL(ENT(pev), "models/w_weaponbox.mdl"); //UTIL_SetSize(pev, Vector( -16, -16, -4), Vector(16, 16, 32)); // Old box -- size of headcrab monsters/players get blocked by this UTIL_SetSize(pev, Vector( -4, -4, -4), Vector(4, 4, 4)); // Uses point-sized, and can be stepped over UTIL_SetOrigin( pev, pev->origin );
SetTouch( SatchelSlide ); SetUse( DetonateUse ); SetThink( BoobyThink ); pev->nextthink = gpGlobals->time + 0.1;
pev->gravity = 0.5; pev->friction = 0.8;
pev->dmg = gSkillData.plrDmgSatchel; // ResetSequenceInfo( ); pev->sequence = 1;
m_flActivateProximity = gpGlobals->time + 5.0; //The 5.0 is the # of Seconds m_flProximityCheckInterval = m_flActivateProximity; //First check when activated. m_bPlaySound = false; }
void CBoobyTrap::Precache( void ) { PRECACHE_MODEL("models/w_weaponbox.mdl"); //booby trap PRECACHE_SOUND("weapons/g_bounce1.wav"); PRECACHE_SOUND("weapons/g_bounce2.wav"); PRECACHE_SOUND("weapons/g_bounce3.wav"); }
bool CBoobyTrap::CheckProx(int iRaduis) { CBaseEntity *pOther = NULL; //Just declare this variable if( gpGlobals->time >= m_flActivateProximity) { if(!m_bPlaySound) { m_bPlaySound = true; EMIT_SOUND( ENT(pev), CHAN_VOICE, "buttons/blip2.wav", 1.0, ATTN_NORM ); } if(gpGlobals->time >= m_flProximityCheckInterval) { m_flProximityCheckInterval = gpGlobals->time + 0.5; //Check every 0.5 seconds while((pOther = UTIL_FindEntityInSphere( pOther, pev->origin , iRaduis)) != NULL) { if ( pOther->pev->takedamage != DAMAGE_NO ) { return true; } } } } return false; }
void CBoobyTrap :: BoobyThink( void ) { StudioFrameAdvance( ); pev->nextthink = gpGlobals->time + 0.1;
if (!IsInWorld()) { UTIL_Remove( this ); return; }
if (pev->waterlevel == 3) { pev->movetype = MOVETYPE_FLY; pev->velocity = pev->velocity * 0.8; pev->avelocity = pev->avelocity * 0.9; pev->velocity.z += 8; } else if (pev->waterlevel == 0) { pev->movetype = MOVETYPE_BOUNCE; } else { pev->velocity.z -= 8; } if(CheckProx(32)) { SetThink( Detonate ); } }
|
We have inherited most of the functionality of the normal CSatchelCharge. We override the Spawn and the Precache functions. The Spawn function is overridden to set the model and the think for the booby trap. The Precache function is overridden to set the model for the booby trap. We create new functions, BoobyThink and CheckProx. The BoobyThink is much like the SatchelThink except that it calls CheckProx to see if it should detonate. The CheckProx first evaluate the time to see if it should activate the booby trap. When activating the booby trap a sound will play (once) to indicate that it activated. Next, this function looks for entities in a sphere that can take damage. The radius of the sphere is supplied as a parameter. We set the radius small (32) so that the satchel only explodes when a player steps on it.
We have to make the functions that we override from CSatchelCharge public. C++s default is not public. So find class CSatchelCharge : public CGrenade and move the public keyword to the top of the class definition. (From before Deactivate to before Spawn.)
In void CSatchel::Precache( void ) add the following:
| | PRECACHE_SOUND("buttons/blip2.wav"); | . NOTE: For some reason, Half-life does not want to precache this in the CBoobyTrap::Precache function. Editors note: UTIL_PrecacheOther("monster_booby"); in weapons.cpp to make this entities precache function get called.
We will use the secondary fire to throw booby traps. First find class CSatchel : public CBasePlayerWeapon and add
Next create the function:
| | void CSatchel::ThrowBT( void ) { if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) { Vector vecSrc = m_pPlayer->pev->origin;
Vector vecThrow = gpGlobals->v_forward * 274 + m_pPlayer->pev->velocity;
CBaseEntity *pSatchel = Create( "monster_booby", vecSrc, Vector( 0, 0, 0), m_pPlayer->edict() ); pSatchel->pev->velocity = vecThrow; pSatchel->pev->avelocity.y = 400;
m_pPlayer->pev->viewmodel = MAKE_STRING("models/v_satchel_radio.mdl"); m_pPlayer->pev->weaponmodel = MAKE_STRING("models/p_satchel_radio.mdl"); SendWeaponAnim( SATCHEL_RADIO_DRAW );
// player "shoot" animation m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_chargeReady = 1; m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_flNextPrimaryAttack = gpGlobals->time + 1.0; m_flNextSecondaryAttack = gpGlobals->time + 0.5; } }
|
Now we can change the Secondary fire to throw booby traps. Find void CSatchel::SecondaryAttack( void ) and replace the body of the function with
To enable the booby trap to explode when pressing the radios button (primary attack after deploying) we need to change void CSatchel::PrimaryAttack(). Find in this function | | if (FClassnameIs( pSatchel->pev, "monster_satchel")) | and change it to | | if ((FClassnameIs( pSatchel->pev, "monster_satchel")) || (FClassnameIs( pSatchel->pev, "monster_booby"))) |
You can change or add new classes using different types of models. Save satchel.cpp
That's all, Enjoy! Thats all folks. You can e-mail me at scobra@ananzi.co.za for comments and questions. |
|
User Comments
No User Comments
You must register to post a comment. If you have already registered, you must login.
|
Any money that is donated will go towards the server costs that I incur for running our server. Don't feel you HAVE to donate, but the link is there if you want to help us out a little. Thanks :)
|
296 Approved Articless
3 Pending Articles
3940 Registered Members
0 People Online (11 guests)
|
|