THE HANDY VANDAL'S ALMANAC
Game Design Resources for Half-Life
Home : Topics : Menu : Reviews
Almanac 2 : Xen Rebels

Site no longer actively maintained ... HV

"Building Better Deathtraps -- For You!"
 

POINTS FOR MONSTERS
See also: Coding - Mods - Programming - Monsters
Updated July 17, 2001 - 12:06 AM

 

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.

 

 
Killing Monsters: How to Award Points to Players
Handy Vandal's Almanac Logo

"Handy Vandal" and "Handy Vandal's Almanac" copyright 2008 by Karl Gregory Jones
Almanac: Half-Life : Half-Life 2
Xen Rebels
karljones.com
Contact the Handy Vandal

Half-Life © 1998-99 Sierra On-line and Valve L.L.C. All rights reserved. Half-Life and the Half-Life logo are trademarks of Sierra On-Line. Valve and the Valve logo are trademarks of Valve L.L.C. Half-Life images, textures, music, sound effects, and other graphic or audio content © 1998-99 Valve L.L.C. All rights reserved.