.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Random monsters - the call (Groups : qc : Forum : vault() : Random monsters - the call) Locked
Thread Options
numbersix
numbersix quake-c coder++
Oct 23 2014 Anchor

The wandering monster is a concept from roleplaying games - an unplanned encounter with random consequences.

With a slight retool of quake-c you can have random monsters in singleplayer or deathmatch.
(eventually a full tutorial will be posted on this subject!)

The first thing you need is a spawn function. For all the standard monsters - the code is almost done!

Why almost?

When a map monster is spawned, vintage quake engines had to do something called precache.

This thread explains precache in detail: Moddb.com

Suffice to say if you wanted to use a model or sound in quake, you had to tell the engine so it could pre-load the resource and index it.

So, you might have:
void() monster_knight =
{
precache_model ("progs/knight.mdl");
precache_model ("progs/h_knight.mdl");

precache_sound ("knight/kdeath.wav");
precache_sound ("knight/khurt.wav");
precache_sound ("knight/ksight.wav");
precache_sound ("knight/sword1.wav");
precache_sound ("knight/sword2.wav");
precache_sound ("knight/idle.wav");

// code to set up monster in qc follows

};

If you call that function after map load in most quake engines - they will crash.

With an engine like Darkplaces, you could simply comment out all precache.
(If you plan on releasing your code you will want to leave the precache statements there.
If you use fteqcc you could also use:
#ifdef inclprecache
// precache statements
#endifdef
qualifiers that compile the code if you have:
#define inclprecache
somewhere in a defs.qc
)

If your mod or game is darkplaces only, that is a good idea.
Maps will load a lot faster as well - Darkplaces has this great "on the fly" precache.

For many other engines, however, you need precache, so you need qualifier code:

void(float ign) monster_knight =
{
// map spawned monsters will call this with ign = 0, or we can use a specific code, like 666
// so when random spawn code comes here, use "monster_knight(666);"
if (ign != 666)
{
precache_model ("progs/knight.mdl");
precache_model ("progs/h_knight.mdl");

precache_sound ("knight/kdeath.wav");
precache_sound ("knight/khurt.wav");
precache_sound ("knight/ksight.wav");
precache_sound ("knight/sword1.wav");
precache_sound ("knight/sword2.wav");
precache_sound ("knight/idle.wav");
}

// may want to obey server var nomonsters
// normally the engine does this - but with random spawns we have to check
if (cvar("nomonsters"))
{
remove(self);
return;
}

// code to set up monster in qc follows

};

Update:

Since darkplaces has dynamic precache, I decided to null out the precache function.

I found out I already put a "wrapper" on it.

Go here: Moddb.com to see how it works.

What does this mean?
Darkplaces will likely crash if you call a precache after map load - just like any other quake engine!

And with some maps (those with minimal items and monsters) dynamic precache loads them like lightning.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.