CGrenade *CGrenade::ShootContact( entvars_t *pevOwner, Vector vecStart, Vector vecVelocity ) { CGrenade *pGrenade = GetClassPtr( (CGrenade *)NULL ); pGrenade->Spawn(); // contact grenades arc lower pGrenade->pev->gravity = 0.5;// lower gravity since grenade is aerodynamic and engine doesn't know it. UTIL_SetOrigin( pGrenade, vecStart ); pGrenade->SetLocalVelocity( vecVelocity ); pGrenade->SetLocalAngles( UTIL_VecToAngles( pGrenade->GetLocalVelocity( ))); pGrenade->pev->owner = ENT(pevOwner); // make monsters afaid of it while in the air pGrenade->SetThink( &CGrenade::DangerSoundThink ); pGrenade->SetNextThink( 0 ); // Tumble in air Vector avelocity( RANDOM_FLOAT ( 100, 500 ), 0, 0 ); pGrenade->SetLocalAvelocity( avelocity ); // Explode on contact pGrenade->SetTouch( &CGrenade::ExplodeTouch ); pGrenade->pev->dmg = gSkillData.plrDmgM203Grenade; return pGrenade; }
CGrenade * CGrenade:: ShootTimed( entvars_t *pevOwner, Vector vecStart, Vector vecVelocity, float time ) { CGrenade *pGrenade = GetClassPtr( (CGrenade *)NULL ); pGrenade->Spawn(); UTIL_SetOrigin( pGrenade, vecStart ); pGrenade->SetAbsVelocity( vecVelocity ); pGrenade->SetLocalAngles( UTIL_VecToAngles( pGrenade->GetAbsVelocity( ))); pGrenade->pev->owner = ENT( pevOwner ); pGrenade->SetTouch( &CGrenade::BounceTouch ); // Bounce if touched // Take one second off of the desired detonation time and set the think to PreDetonate. PreDetonate // will insert a DANGER sound into the world sound list and delay detonation for one second so that // the grenade explodes after the exact amount of time specified in the call to ShootTimed(). pGrenade->pev->dmgtime = gpGlobals->time + time; pGrenade->SetThink( &CGrenade::TumbleThink ); pGrenade->SetNextThink( 0.1 ); if( time < 0.1 ) { pGrenade->SetNextThink( 0 ); pGrenade->SetLocalVelocity( g_vecZero ); } pGrenade->pev->sequence = RANDOM_LONG( 3, 6 ); pGrenade->pev->framerate = 1.0; pGrenade->pev->gravity = 0.5; pGrenade->pev->friction = 0.8; SET_MODEL( pGrenade->edict(), "models/w_grenade.mdl" ); pGrenade->pev->dmg = 100; return pGrenade; }