Check out Half-Life Re-imagined competition results!
Check out Skewing textures in Hammer, our newest tutorial!
Say hello to ellen123, our newest member!

logo

Site Stuff

Reference

Maps

Community

ShoutBOX

Poll

Feeling Blue

What's your favourite shade of blue?

Azure

15

Cobalt

32

Turquoise

10

Cyan

11

Royal

9

Teal

3

Onliners

1 mins

olograph

12 mins

Alberto309

18 mins

NineTnine

24 mins

Penguinboy

39 mins

Dimbeak

39 mins

Crollo

51 mins

potatis_invalid

Affiliates

A gaming and technology blog by TWHL admins Penguinboy and Ant. A music blog by TWHL users Ant and Hugh.

Adding new monster factions

By Caleb 'Ghoul' Delnay

Alrighty, this tutorial will show you how to add new factions to monsters. Ex. a human grunt uses a faction type of CLASS_HUMAN_MILITARY. Lets say you added in Black Ops from Op4. If they were CLASS_HUMAN_MILITARY then they would be friends with human grunts, but that isn''t the way it worked in Op4, so lets add a CLASS_BLACK_OP. First open up cbase.h, scroll down a little and you should see this:
// For CLASSIFY
#define CLASS_NONE 0
#define CLASS_MACHINE 1
#define CLASS_PLAYER 2
#define CLASS_HUMAN_PASSIVE 3
#define CLASS_HUMAN_MILITARY 4
#define CLASS_ALIEN_MILITARY 5
#define CLASS_ALIEN_PASSIVE 6
#define CLASS_ALIEN_MONSTER 7
#define CLASS_ALIEN_PREY 8
#define CLASS_ALIEN_PREDATOR 9
#define CLASS_INSECT 10
#define CLASS_PLAYER_ALLY 11
#define CLASS_PLAYER_BIOWEAPON 12 // hornets and snarks ...
#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks ...
#define CLASS_BARNACLE 99 // special because ...

Now, between CLASS_ALIEN_BIOWEAPON and CLASS_BARNACLE add in this:

#define CLASS_ALIEN_BIOWEAPON 13 // hornets and snarks ...
#define CLASS_BLACK_OP 14 // <-- new Black Op faction!
#define CLASS_BARNACLE 99 // special because ...

Now that we have our new class declared, we have to open up monsters.cpp. Find the IRelationship function for the class CBaseMonster. Close to the top of the function you should see a grid of code like this (only first part shown):

static int iEnemy[14][14] =
{     // NONE MACH      PLYR      HPASS
/*NONE*/     { R_NO     ,R_NO     ,R_NO     ,R_NO
/*MACHINE*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
/*PLAYER*/     { R_NO     ,R_DL     ,R_NO     ,R_NO
/*HUMANPASSIVE*/{ R_NO     ,R_NO     ,R_AL     ,R_AL
/*HUMANMILITAR*/{ R_NO     ,R_NO     ,R_HT     ,R_DL
/*ALIENMILITAR*/{ R_NO     ,R_DL     ,R_HT     ,R_DL
/*ALIENPASSIVE*/{ R_NO     ,R_NO     ,R_NO     ,R_NO
/*ALIENMONSTER*/{ R_NO     ,R_DL     ,R_DL     ,R_DL
/*ALIENPREY */{ R_NO     ,R_NO     ,R_DL     ,R_DL
/*ALIENPREDATO*/{ R_NO     ,R_NO     ,R_DL     ,R_DL
/*INSECT*/     { R_FR     ,R_FR     ,R_FR     ,R_FR
/*PLAYERALLY*/     { R_NO     ,R_DL     ,R_AL     ,R_AL
/*PBIOWEAPON*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
/*ABIOWEAPON*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
};

As you can see, not all the code for the grid is shown. Ok, next is the main part of the tutorial. Examine the grid, first, change the
iEnemy[14][14]

to...
iEnemy[15][15]

Now you need to add one row and one column to the code grid. Just copy and paste the last column and row onto the grid. Change the labels to /*BLACKOP*/ and BLKOP or whatever. Your grid should look like this:

static int iEnemy[15][15] =
{     // NONE MACH      PLYR      HPASS
/*NONE*/     { R_NO     ,R_NO     ,R_NO     ,R_NO
/*MACHINE*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
/*PLAYER*/     { R_NO     ,R_DL     ,R_NO     ,R_NO
/*HUMANPASSIVE*/{ R_NO     ,R_NO     ,R_AL     ,R_AL
/*HUMANMILITAR*/{ R_NO     ,R_NO     ,R_HT     ,R_DL
/*ALIENMILITAR*/{ R_NO     ,R_DL     ,R_HT     ,R_DL
/*ALIENPASSIVE*/{ R_NO     ,R_NO     ,R_NO     ,R_NO
/*ALIENMONSTER*/{ R_NO     ,R_DL     ,R_DL     ,R_DL
/*ALIENPREY */{ R_NO     ,R_NO     ,R_DL     ,R_DL
/*ALIENPREDATO*/{ R_NO     ,R_NO     ,R_DL     ,R_DL
/*INSECT*/     { R_FR     ,R_FR     ,R_FR     ,R_FR
/*PLAYERALLY*/     { R_NO     ,R_DL     ,R_AL     ,R_AL
/*PBIOWEAPON*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
/*ABIOWEAPON*/     { R_NO     ,R_NO     ,R_DL     ,R_DL
/*BLACKOP*/     { R_NO     ,R_NO     ,R_HT     ,R_DL
};

And the last part of the array...

PLRALY     PBWPN     ABWPN     BLKOP
R_NO,     R_NO,     R_NO,     R_NO     },
R_DL,     R_DL,     R_DL,     R_NO     },
R_NO,     R_DL,     R_DL,     R_DL     },
R_AL,     R_NO,     R_NO,     R_HT     },
R_HT,     R_NO,     R_NO,     R_NM     },
R_DL,     R_NO,     R_NO,     R_HT     },
R_NO,     R_NO,     R_NO,     R_HT     },
R_DL,     R_NO,     R_NO,     R_DL     },
R_DL,     R_NO,     R_NO,     R_DL     },
R_DL,     R_NO,     R_NO,     R_HT     },
R_FR,     R_NO,     R_NO,     R_NO     },
R_NO,     R_NO,     R_NO,     R_HT     },
R_DL,     R_NO,     R_DL,     R_DL     },
R_DL,     R_DL,     R_NO,     R_DL     },
R_HT,     R_NO,     R_NO,     R_NO     }
};

Now we are almost done. If you look at the grid you see a lot of R_ this and R_ that. In monsters.h take a look at this code:

// monster to monster relationship types
#define R_AL -2 // (ALLY) pals. Good alternative ...
#define R_FR -1// (FEAR)will run
#define R_NO 0// (NO RELATIONSHIP) disregard
#define R_DL 1// (DISLIKE) will attack
#define R_HT 2// (HATE)will attack ...
#define R_NM 3// (NEMESIS) A monster Will ...

Those are the monster relationship types. Using those defines set up your Black Op to have its enemies and friends. It works just like a normal grid, take ALIENMILITAR for example, going across it's grid section, it will dislike machines, hate players, dislike passive humans, etc. Now the only thing you have to do is go into your monsters Classify() function and have it return CLASS_BLACK_OP and your all set. I hope you learned from the tutorial. Now good luck. :)