Wayback Machine
JAN MAY Jun
Previous capture 5 Next capture
2004 2006 2007
17 captures
6 Oct 02 - 5 May 06
sparklines
Close Help

# menu
 
http://www.planethalflife.com/hlprogramming > tutorials > database 

news
 
current
 
submit

tutorials
 
database
  -
mp
  -
client
 
submit
 
search

forum
 
main

contact
 
email

Proximity Satchels UPDATED
Created by Tony



HalfLife's Code is BLUE
Tony's Code is RED
Tony's Commentary is GREEN


FOR SDK VERSION 2.2!
I have remade this for version 2.2. Make sure you use the right version! I will still support this code is you are having problems making it work. These days, the main reason is that people are using a different version of the SDK than when I wrote the original.


This does a couple of things:
Sets a proximity fuse on the satchel pack so when some one steps with in range of the satchel, it automatically detonates. It also allows for the deployer to press the button and blow up the satachel. Also, it makes the satchels persistent between the owners deaths. That way the satchels dont just disappear when the owner dies. Also, it allows the owner to pick up more satchels after they have deployed some.

This is a very mean mod. Well placed Satchels become very deadly!!


First changes to the CSatchelCharge class in the satchel.cpp. We need to add a timer for when the proximity fuse activates. If we activate it too soon, it will blow up the person who deployes it. I normally set the timer for 5 seconds.


class CSatchelCharge : public CGrenade
{
float m_flActivateProximity;
void Spawn( void );
void Precache( void );
void BounceSound( void );

void EXPORT SatchelSlide( CBaseEntity *pOther );
void EXPORT SatchelThink( void );

public:
void Deactivate( void );

};


Now to actually set the 5 second deley


void CSatchelCharge :: Spawn( void )
{
Precache( );
// motor
pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_BBOX;

SET_MODEL(ENT(pev), "models/w_satchel.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( SatchelThink );

pev->nextthink = gpGlobals->time + 0.1;
m_flActivateProximity = gpGlobals->time + 5.0; //The 5.0 is the # of Seconds

pev->gravity = 0.5;
pev->friction = 0.8;

pev->dmg = gSkillData.plrDmgSatchel;
// ResetSequenceInfo( );
pev->sequence = 1;
}


Now comes the proximity code. If the proximity fuse timer is up, Wait for a damageable entity to enter sphere.


void CSatchelCharge :: SatchelThink( void )
{

CBaseEntity *pOther = NULL; //Just declare this variable


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( gpGlobals->time >= m_flActivateProximity)
{
if((pOther = UTIL_FindEntityInSphere( pOther, pev->origin , 128)) != NULL)
{
if ( pOther->pev->takedamage != DAMAGE_NO )
SetThink( Detonate );
}
}

}


Thats it for the CSatchelCharge class. The proximity fuse is installed. Now we need to change a few things about the CSatchel so we can pick up more satchels


int CSatchel::AddDuplicate( CBasePlayerItem *pOriginal )
{
CSatchel *pSatchel;

#ifdef CLIENT_DLL
if ( bIsMultiplayer() )
#else
if ( g_pGameRules->IsMultiplayer() )
#endif
{
pSatchel = (CSatchel *)pOriginal;

if ( pSatchel->m_chargeReady != 0 )
{
// player has some satchels deployed. Refuse to add more.

// return FALSE;

}
}

return CBasePlayerWeapon::AddDuplicate ( pOriginal );
}


Now, dont reset the m_chargeReady when we pick up a new satchel pack.


int CSatchel::AddToPlayer( CBasePlayer *pPlayer )
{
int bResult = CBasePlayerItem::AddToPlayer( pPlayer );

pPlayer->pev->weapons |= (1<

// m_chargeReady = 0;



if ( bResult )
{
return AddWeapon( );
}
return FALSE;
}


Thats it for the actual satchel classes. Now we need to stop the satchels from disappearing after they die. This is a rule in the multiplay_gamerules.cpp, line 585 or so. Under:

void CHalfLifeMultiplay :: PlayerKilled

Find these lines at the end of this function


#ifndef HLDEMO_BUILD
if ( pVictim->HasNamedPlayerItem("weapon_satchel") )
{
DeactivateSatchels( pVictim );
}
#endif

and rem them out
#ifndef HLDEMO_BUILD
/*
if ( pVictim->HasNamedPlayerItem("weapon_satchel") )
{
DeactivateSatchels( pVictim );
}
*/

#endif
And there you have the proximity satchel pack