Monsters Fighting Each-Other

Like monsters? Want them to hate each other? This is for you! Fun fun fun!

Posted by on - Basic Client Side Coding

[page=Introduction]
Hello!

Today, I'll be sharing with you a code I made for monsters to fight each other. Wether you like the Stroggos, or hate them, it'll be fun!

[page=The Code.]

Here we go!

Go to FindTarget. Above it, add this new function.

``````edict_t *FindM&#111;nster &#40;edict_t *self&#41;
{
edict_t	*ent = NULL;
edict_t	*best = NULL;

while &#40;&#40;ent = findradius&#40;ent, self-&#62;s.&#111;rigin, 1024&#41;&#41; &#33;= NULL&#41;
{
if &#40;ent == self&#41;
c&#111;ntinue;
if &#40;&#33;&#40;ent-&#62;svflags & SVF_MONSTER&#41;&#41;
c&#111;ntinue;
if &#40;&#33;ent-&#62;health&#41;
c&#111;ntinue;
if &#40;ent-&#62;health &#60; 1&#41;
c&#111;ntinue;
if &#40;&#33;visible&#40;self, ent&#41;&#41;
c&#111;ntinue;
if &#40;&#33;best&#41;
{
best = ent;
c&#111;ntinue;
}
if &#40;ent-&#62;max_health &#60;= best-&#62;max_health&#41;
c&#111;ntinue;
best = ent;
}

return best;
}``````

That will look for monsters. (Similar to the Medic's check for deaddies ;))

Now, go to FindTarget, change the beginning to this:

``````qb&#111;&#111;lean FindTarget &#40;edict_t *self&#41;
{
edict_t		*client;
qb&#111;&#111;lean	heardit;
int			r;
edict_t *m&#111;nster;

if &#40;self-&#62;m&#111;nsterinf&#111;.aiflags & AI_GOOD_GUY&#41;
{
if &#40;self-&#62;g&#111;alentity && self-&#62;g&#111;alentity-&#62;inuse && self-&#62;g&#111;alentity-&#62;classname&#41;
{
if &#40;strcmp&#40;self-&#62;g&#111;alentity-&#62;classname, &#34;target_act&#111;r&#34;&#41; == 0&#41;
return false;
}

return false;
}

//L&#111;&#111;k f&#111;r m&#111;nsters&#33;
m&#111;nster = FindM&#111;nster&#40;self&#41;;
if &#40;m&#111;nster&#41;
{
self-&#62;enemy = m&#111;nster;
F&#111;undTarget &#40;self&#41;;
return true;
}

&#40;the rest......&#41;``````

..Have fun!

You can just run around them and then they shoot each-other. Not saying that is pointless.

Tutorial
##### Share
Related Games
Quake 2 First Person Shooter
Related Engines
id Tech 2 GPL
Related Groups
Activision Developer & Publisher
id Software Developer & Publisher