VERC: Beheading Zombies Last edited 20 years ago2004-01-19 16:44:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

This article was recovered from an archive and needs to be reviewed

  1. The formatting may be incorrect as it was automatically converted to WikiCode from HTML, it needs to be revised and reformatted
  2. Some information may be out of date as it was written before Half-Life was available on Steam
  3. After the article is re-formatted and updated for Steam HL, remove this notice
  4. Please do not remove the archive notice from the bottom of the article.
  5. Some archive articles are no longer useful, or they duplicate information from other tutorials and entity guides. In this case, delete the page after merging any relevant information into other pages. Contact an admin to delete a page.
After hearing that the zombies in HL2 will have the headcrabs jump off them when it's killed, I decided to try it out, and it's not hard either...

First you'll need to get the modified zombie model here (Link: zombie.zip) . It's not the HD one, just the good 'ol normal zombie. Got it? OK, now go into MSVC++ 6.0 (or whatever you use) and open zombie.cpp .

The Code

At the top there should be these #defines:

/=========================================================/ Monster's Anim Events Go Here//=========================================================
#define ZOMBIE_AE_ATTACK_RIGHT 0x01
#define ZOMBIE_AE_ATTACK_LEFT 0x02
#define ZOMBIE_AE_ATTACK_BOTH 0x03

Just add these ones:

// headcrab jumps from zombie
#define ZOMBIE_AE_CRAB1 0x04
#define ZOMBIE_AE_CRAB2 0x05
#define ZOMBIE_AE_CRAB3 0x06
// headcrab jumps from zombie

Those just define the animation events used in the model for this, now just a few lines lower (after ZOMBIE_FLINCH_DELAY), add this:

#define ZOMBIE_CRAB "monster_headcrab" // headcrab jumps from zombie

That defines the ZOMBIE_CRAB, which will be used later to spawn a headcrab of all things.

Now add this line in the public definitions (right under int IgnoreConditions):

void SpawnCrab( void ); // headcrab jumps from zombie

Now plop this piece of code at the end of the file:

/=========================================================/ Spawn Headcrab - headcrab jumps from zombie//=========================================================
void CZombie :: SpawnCrab( void )
{
CBaseEntity *pCrab = CBaseEntity::Create( ZOMBIE_CRAB, pev->origin, pev->angles, edict() ); // create the crab

pCrab->pev->spawnflags |= SF_MONSTER_FALL_TO_GROUND; // make the crab fall
}

That top line just spawns a crab (notice the ZOMBIE_CRAB), and that second line makes the crab fall to the ground.

Almost done, now go to HandleAnimEvents function, at the bottom of it (before the default :)add this:

// headcrab jumps from zombie
case ZOMBIE_AE_CRAB1:
{
ALERT( at_console, "Crab1 spawned! n" );
pev->body = 1; // set the head to a skull
SpawnCrab(); // spawn a headcrab
}
break ;

case ZOMBIE_AE_CRAB2:
{
ALERT( at_console, "Crab2 spawned! n" );
pev->body = 1; // set the head to a skull
SpawnCrab(); // spawn a headcrab
}
break ;

case ZOMBIE_AE_CRAB3:
{
ALERT( at_console, "Crab3 spawned! n" );
pev->body = 1; // set the head to a skull
SpawnCrab(); // spawn a headcrab
}
break ;
// headcrab jumps from zombie

The 'pev->body = 1' line sets the body to the skull found in the modified zombie model, and the 'SpawnCrab()' simply calls that function.

Now you may be thinking,"Why do I have three events that are the exact same?". Well that is so you can add different effects for the headcrab when it spawns (like the TE_IMPLOSION effect).

Finally, go to the Precache area of the code and add this:

UTIL_PrecacheOther( ZOMBIE_CRAB ); // headcrab jumps from zombie

Now compile it and run a test map, you may notice that the crab will only spawn when it isn't a headshot kill, makes the effect more realistic. Well, enjoy beheading those zombies!

The Model

For those of you that want to find out what's different about the model (besides a new head), read on, however, I'm not going to explain how to actually do the modeling part, this is about the .QC file.

When I made the zombie model I simply added new events to the .QC file, I'll explain a little about what does what in the .QC.

$bodygroup body
{
studio "Zom3_Template_Biped(White_Suit)1"
studio "skullhead"
}

If you open up normal zombies .QC file, you'll notice this bit isn't there. What this does it make the two bodygroups that the new zombie has. The new one here is skullhead , which 'pev->body = 1' is linked to, while 'pev->body = 0' would be the White_Suit.

$sequence dieheadshot "dieheadshot" X fps 20 ACT_DIE_HEADSHOT 1 { event 2001 19 }
$sequence dieheadshot2 "dieheadshot2" fps 22 ACT_DIE_GUTSHOT 1 { event 2001 18 }
$sequence diesimple "diesimple" X fps 20 ACT_DIESIMPLE 1 { event 2001 13 } { event 4 8 }
$sequence diebackward "diebackward" fps 18 ACT_DIEBACKWARD 1 { event 2001 10 } { event 5 2 }
$sequence dieforward "dieforward" X fps 18 ACT_DIEFORWARD 1 { event 2001 21 } { event 6 18 }

Those are the zombie's death animations. The only relevent parts here are the { event ## ##} .
The first number calls the event that cooresponds to the number in the code, while the second one tells it what frame to do it on.

For example:

------------QC file------------
$sequence diesimple "diesimple" X fps 20 ACT_DIESIMPLE 1 { event 2001 13 } { event 4 8 }

------------cpp file------------
#define ZOMBIE_AE_CRAB1 0x04

As you can see, event 4 is called on frame 8. Event 4 is refered to in zombie.cpp as 0x04 with the name ZOMBIE_AE_CRAB1 (where the code is called).

$sequence dieheadshot "dieheadshot" X fps 20 ACT_DIE_HEADSHOT 1 { event 2001 19 }
$sequence dieheadshot2 "dieheadshot2" fps 22 ACT_DIE_GUTSHOT 1 { event 2001 18 }

As you can see here, there are no new events for these two, this is what makes it so the crab won't jump off when its a headshot or a gutshot.

Well, now you know how the model is important for this effect as well as learning about the relationship between model events and the code.
This article was originally published on the Valve Editing Resource Collective (VERC).
TWHL only archives articles from defunct websites. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.