Alternate Zombies in Your Mod

Tutorial collection, comprehensive listings on main site.

Alternate Zombies in Your Mod

Postby Tutorial on Wed Dec 23, 2009 4:56 pm

category
Miscellaneous

description
How to add more than one type of 'classic' zombie to your mod.

keywords
coding, zombie, classic, adding zombie, model.

Description

In this tutorial, i'm going to show you how to add more than one type of 'classic' zombie to your mod. We're going to be coding so i assume you have everything setup already. If not here's some links to get you started:
Link to Valve Developer Community:http://developer.valvesoftware.com/wiki/Category:Programming
Link to compiler:http://developer.valvesoftware.com/wiki/Compiler_Choices

Tutorial

Open up your Game_HL2-2008.sln file, or whatever it's name is on your end, might be 2003 or 2005, it depends.
Locate and open the npc_zombie.cpp file. Path in VC++: server_hl2/Source files/HL2 dll/npc_zombie.cpp

In npc_zombie.cpp find " class CZombie : public CAI_BlendingHost<CNPC_BaseZombie> " - Should be near line 81
Then scroll down and find where it says " private: " and under that add:
Code: Select all
int                             m_iSkin;

As you probably already know, C++ is CASE SENSITIVE.
What it looks like on my end:
Image

Then search for " BEGIN_DATADESC( CZombie ) " - No Quotation marks.
In here we'll add the keyvalue so we can change m_iSkin's value in hammer.
After " DEFINE_FIELD( m_flDoorBashYaw, FIELD_FLOAT ), " add:
Code: Select all
DEFINE_KEYFIELD( m_iSkin, FIELD_INTEGER, "skin" ),

What it looks like on my end:
Image

Now we'll get to the 'Selecting model' part.
Find: ' CZombie::SetZombieModel ( void ) '
and replace it with:
Code: Select all
void CZombie::SetZombieModel( void )
{
   Hull_t lastHull = GetHullType();

   if ( m_fIsTorso )
   {
      SetModel( "models/zombie/classic_torso.mdl" );
      SetHullType( HULL_TINY );
   }

   if ( !m_fIsTorso && m_iSkin == 1)
   {
      SetModel( "models/zombie/classic.mdl" );
      SetHullType (HULL_HUMAN);
   }
   else if( !m_fIsTorso && m_iSkin == 2)
   {
      SetModel( "models/zombie/zclassic_01.mdl" );
      SetHullType (HULL_HUMAN);
   }
   else if( !m_fIsTorso && m_iSkin == 3)
   {
      SetModel( "models/zombie/zclassic_03.mdl" );
      SetHullType (HULL_HUMAN);
   }




   SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless );

   SetHullSizeNormal( true );
   SetDefaultEyeOffset();
   SetActivity( ACT_IDLE );

   // hull changed size, notify vphysics
   // UNDONE: Solve this generally, systematically so other
   // NPCs can change size
   if ( lastHull != GetHullType() )
   {
      if ( VPhysicsGetObject() )
      {
         SetupVPhysicsHull();
      }
   }
}


Image

You can add as many other models as you want - Just remember to precache them too!
Which we'll do right now!

Find: ' void CZombie::Precache( void ) ' and add your model names.
Mine are:
Code: Select all
   PrecacheModel( "models/zombie/classic.mdl" );
   PrecacheModel( "models/zombie/zclassic_01.mdl" );
        PrecacheModel( "models/zombie/zclassic_03.mdl" );
   PrecacheModel( "models/zombie/classic_torso.mdl" );
   PrecacheModel( "models/zombie/classic_legs.mdl" );


Now compile and remember to copy the dlls into your bin folder in your mod folder!
(My compiler stopped doing that somewhere along the line and it really really foiled my plans for quite awhile, since i didn't realize that it had stopped, so write a batch script to do it for you or manually copy them.)

One last thing before we're ready! We gotta get the new keyvalue into hammer!
So go here: C:\Steam\steamapps\USERNAME\sourcesdk\bin\ep1\bin\
Find the halflife2.fgd file and make a copy and name it after your mod(Or whatever you feel like really).
Now open the .fgd file you've just created and search for npc_zombie
You should find something like:

Image

What it SHOULD look like when we're done:

Image
Add this code:
Code: Select all
   skin(choices) : "Version" : 3 =
   [
      1 : "Version 1"
      2 : "Version 2"
                3 : "Version 3"
   ]


It has to be exactly like that above. You can however change the things in "" as you please and the number of "Version #" too of course. But everything else relates to the code we just wrote, so if you change it, it breaks.

Now save the .fgd file and add it in hammer and you should be done!

If i perhaps missed something, or i didn't explain something clearly enough please don't hesitate to let me know.

- Corewarp
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Re: Alternate Zombies in Your Mod

Postby shanemurphy on Wed Dec 23, 2009 6:45 pm

Excellent tutorial, a lot of mods need tutorials like these and you have done a great job at explaining and writing it.
shanemurphy
Dumpling
Dumpling
 
Joined: Thu Jun 25, 2009 3:38 pm

Re: Alternate Zombies in Your Mod

Postby chargers5583 on Thu Dec 24, 2009 7:03 am

would have been good if I knew how to code :P
User avatar
chargers5583
Member
Member
 
Joined: Thu Mar 12, 2009 3:22 am
Location: Home of the CHARGERS

Re: Alternate Zombies in Your Mod

Postby Gary on Thu Dec 24, 2009 7:22 am

Looks good, though I still have problems compiling in general.

This is very useful, when/if I start working with SDK, I've always hated how all of the zombies are the same.
Have a question related to modding or something I posted? Something that needs staff attention? I haven't been active lately, but feel free to PM me or message me on Steam(link below)

User avatar
Gary
Interlopers Staff
Interlopers Staff
 
Joined: Wed Dec 16, 2009 12:40 am
Location: USA, FL

Re: Alternate Zombies in Your Mod

Postby Surfa on Thu Dec 24, 2009 12:50 pm

You could also have added some code that allows the mapper to change the model on a per zombie bases which wouldn't have been too hard. But I suppose it is a good start.
Surfa
May Contain Skills
May Contain Skills
 
Joined: Sun Dec 30, 2007 3:04 pm

Re: Alternate Zombies in Your Mod

Postby Corewarp on Thu Dec 24, 2009 3:35 pm

Surfa wrote:You could also have added some code that allows the mapper to change the model on a per zombie bases which wouldn't have been too hard. But I suppose it is a good start.


I believe that's what i did.

The last part of the tutorial does just that.
You make a new .fgd file and then put that next to the half-life2.fgd in the sourcesdk folder.
Then in hammer you go into tools and remove the halflife2.fgd and add the one you just made. Didn't i make that clear enough? D:
User avatar
Corewarp
Been Here A While
Been Here A While
 
Joined: Thu Mar 13, 2008 6:29 pm

Re: Alternate Zombies in Your Mod

Postby Surfa on Thu Dec 24, 2009 4:25 pm

No you are adding to a list of models if you wanted to allow the mapper to change the model you would have a different fgd entry than that you wouldn't define the model. Also your are hard coding a model requirement in the set model. You are just changing skins and not models.
Surfa
May Contain Skills
May Contain Skills
 
Joined: Sun Dec 30, 2007 3:04 pm

Re: Alternate Zombies in Your Mod

Postby Corewarp on Thu Dec 24, 2009 10:31 pm

Pretty sure that what i did was change the model and not the skin. Seriously, guy..

There isn't a "skin" keyvalue in npc_zombie(pretty sure there's not)
What i showed was how to add a keyvalue called version that changed the MODEL of the npc_zombie and not just tell it to use different materials(a skin).

If you still don't get it then i can't help you.... .__.


EDIT: After reviewing the tutorial and looking at what i wrote in the .fgd i realize how you could be confused. I named it skin(choice) yes, but it doesn't work like that and it doesn't say that in Hammer it says: version.
Sorry for using it there and in the code. But it does use another different model, and not just change the skin.
User avatar
Corewarp
Been Here A While
Been Here A While
 
Joined: Thu Mar 13, 2008 6:29 pm

Re: Alternate Zombies in Your Mod

Postby Surfa on Sat Dec 26, 2009 5:25 pm

Yews but you don't understand what I am saying. I know what you have done it is obvious in the code but you are still hard coding the model choices you could have easily just put it so that the mapper choose the model inside of hammer.
Surfa
May Contain Skills
May Contain Skills
 
Joined: Sun Dec 30, 2007 3:04 pm

Re: Alternate Zombies in Your Mod

Postby Corewarp on Sat Dec 26, 2009 6:02 pm

Surfa wrote:Yews but you don't understand what I am saying. I know what you have done it is obvious in the code but you are still hard coding the model choices you could have easily just put it so that the mapper choose the model inside of hammer.


Oh.. well yeah.
Like with a number?
User avatar
Corewarp
Been Here A While
Been Here A While
 
Joined: Thu Mar 13, 2008 6:29 pm

Re: Alternate Zombies in Your Mod

Postby omnicoder on Thu Mar 25, 2010 8:40 pm

Corewarp wrote:
Surfa wrote:Yews but you don't understand what I am saying. I know what you have done it is obvious in the code but you are still hard coding the model choices you could have easily just put it so that the mapper choose the model inside of hammer.


Oh.. well yeah.
Like with a number?

Phop_physics and the like have string keyvalues for the model name.
Image
If only the future implemented IForeseeable...
"whats threading? does it have to do with strings?" - stegarootbeer
User avatar
omnicoder
Been Here A While
Been Here A While
 
Joined: Sun Feb 07, 2010 8:35 am

Re: Alternate Zombies in Your Mod

Postby Corewarp on Thu Mar 25, 2010 10:02 pm

omnicoder wrote:
Corewarp wrote:
Surfa wrote:Yews but you don't understand what I am saying. I know what you have done it is obvious in the code but you are still hard coding the model choices you could have easily just put it so that the mapper choose the model inside of hammer.


Oh.. well yeah.
Like with a number?

Phop_physics and the like have string keyvalues for the model name.


This is not a prop_physics this is an npc. I've tried manually setting models for npc_citizen and npc_zombie and they didn't work. Which is why i wrote this tutorial. So please GTFO.
User avatar
Corewarp
Been Here A While
Been Here A While
 
Joined: Thu Mar 13, 2008 6:29 pm

Re: Alternate Zombies in Your Mod

Postby Jordash on Fri Mar 26, 2010 3:09 am

Have a look at the npc_combine_s code, whatever they use allows in hammer setting of whichever model the user wants
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia

Re: Alternate Zombies in Your Mod

Postby Corewarp on Fri Mar 26, 2010 6:53 am

Why are you people commenting on this now? I wrote this like a month ago. You CANNOT just set the NPC's model in hammer, i've tried it a thousand times and it didn't work, this is the only way that worked. And is much nicer for mappers.
User avatar
Corewarp
Been Here A While
Been Here A While
 
Joined: Thu Mar 13, 2008 6:29 pm

Re: Alternate Zombies in Your Mod

Postby Jordash on Fri Mar 26, 2010 8:29 am

What do you mean "you people" :P

No ones saying you can simply set it in hammer, what we're saying is there is a way to code it so the mapper may select it from hammer. Rather than relying on a coder to change the code everytime a new model is added.

Mappers will probably find this way is much nicer for them

This is from the combine_s code I mentioned, it probably will need some fiddling to get it working with the zombie npc, but its something to get people started

in ::Precache() put
Code: Select all
const char *pModelName = STRING( GetModelName() );
PrecacheModel( STRING( GetModelName() ) );


in the set model bit put
Code: Select all
SetModel( STRING( GetModelName() ) );


maybe this as well to avoid issues
Code: Select all
   if( !GetModelName() )
   {
      SetModelName( MAKE_STRING( "models/zombie/classic.mdl" ) );
   }



in the FDG
Code: Select all
model(studio) : "Model"


or

Code: Select all
model(choices) : "Model" : "models/zombie/classic.mdl" : "RegularZombie" =
   [
      "models/zombie/classic.mdl" : "RegularZombie"
      "models/zombie/classic_2.mdl" : "DifferentZombie"
   ]
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia
Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users

cron