Post tutorial Report article RSS Feed Monsters Fighting Each-Other

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

Posted by Paril on Jun 17th, 2006
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 *FindMonster (edict_t *self)
{
	edict_t	*ent = NULL;
	edict_t	*best = NULL;

	while ((ent = findradius(ent, self->s.origin, 1024)) != NULL)
	{
		if (ent == self)
			continue;
		if (!(ent->svflags & SVF_MONSTER))
			continue;
		if (!ent->health)
			continue;
		if (ent->health < 1)
			continue;
		if (!visible(self, ent))
			continue;
		if (!best)
		{
			best = ent;
			continue;
		}
		if (ent->max_health <= best->max_health)
			continue;
		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:

qboolean FindTarget (edict_t *self)
{
	edict_t		*client;
	qboolean	heardit;
	int			r;
	edict_t *monster;

	if (self->monsterinfo.aiflags & AI_GOOD_GUY)
	{
		if (self->goalentity && self->goalentity->inuse && self->goalentity->classname)
		{
			if (strcmp(self->goalentity->classname, "target_actor") == 0)
				return false;
		}

		return false;
	}

		//Look for monsters!
		monster = FindMonster(self);
		if (monster)
		{
			self->enemy = monster;
			FoundTarget (self);
			return true;
		}
                                           
                                           (the rest......)

..Have fun!

Post comment Comments
flobblob
flobblob Jul 28 2010 says:

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

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Tutorial
Browse
Tutorials
Report Abuse
Report article
Share
Related Games
Quake 2
Quake 2 Single & Multiplayer First Person Shooter
Related Engines
id Tech 2
id Tech 2 GPL Released Dec 1997
Related Groups
Activision
Activision Developer & Publisher
id Software
id Software Developer & Publisher with 2 members