| |
Killing
Monsters: How to Award Points to Players
In combat.cpp,
find the CBaseMonster_Killed method:
void CBaseMonster
:: Killed( entvars_t *pevAttacker, int iGib )
{
unsigned int cCount = 0;
BOOL fDone = FALSE;
if ( HasMemory( bits_MEMORY_KILLED ) )
{
if ( ShouldGibMonster( iGib ) )
CallGibMonster();
return;
}
Remember( bits_MEMORY_KILLED );
// Now
add this NEW CODE ----------------------------------
// Main points indicated in boldface - see details below
CBaseEntity *ep = CBaseEntity::Instance( pevAttacker );
if ( ep && ep->Classify() == CLASS_PLAYER )
{
CBasePlayer *PK = (CBasePlayer*)ep;
if (FClassnameIs(pev, "monster_hornet")) {/* no points
for hornets*/}
else if (FClassnameIs(pev, "monster_alien_controller"))
{
UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s got
the drop on %s ... \n",
( pevAttacker->netname && STRING(pevAttacker->netname)[0]
!= 0 ) ? STRING(pevAttacker->netname) : "unconnected"
), STRING(pev->classname));
PK->AddPoints(5, false);
}
else if (FClassnameIs(pev, "monster_alien_grunt"))
{
UTIL_ClientPrintAll( HUD_PRINTNOTIFY, UTIL_VarArgs( "%s eliminated
%s ... \n",
( pevAttacker->netname && STRING(pevAttacker->netname)[0]
!= 0 ) ? STRING(pevAttacker->netname) : "unconnected"
),
STRING(pev->classname));
PK->AddPoints(5, false);
}
else if (FClassnameIs(pev, "monster_alien_slave"))
// ETC ETC. ... check as many different monsters as you like
Else { }
}
Compile your HL.DLL (or
whatever file name you use for your mod) and start up a multiplayer
game. Players will score points for killing monsters.
Main Points:
- Instance::(pevAttacker)
... who is the attacker that killed this monster?
- Classify() == CLASS_PLAYER
... is the attacker a player?
- *PK ... a pointer
to the player who is the attacker
- FClassNameIs(pev,
"monster_whatever") ... is the Class Name of pev (the
killed monster) equal to "monster_whatever"?
- UTIL_ClientPrintAll
... prints HUD message to all players -- e.g. "Player_Whoever
got the drop on Monster_Whatever"
- PK->AddPoints(x,false)
... adds x points to the killer's frag count
- Else{ } ... empty
default for the end, catch anything that doesn't fit the defined
class names.
|