Dynamic Entity Spawning

This is to my mind the most useful map hack there is. It lets us dynamically create an entity in the map, in response to a trigger.

To understand what happens here we need to know something technical about classes and functions in QuakeC. When the engine starts a map, it needs to spawn all of the entities the mapper has added. It imports all the values that the mapper sets on an entity, but the mapper doesn’t need to set the model, or health, or many other properties of the entities. These are all set by the “spawn function” of the entity class. The important fact for today is that the classname of the entity corresponds to the name of the spawn function in QuakeC.

Create an entity as follows:

"classname" "info_notnull"
"use" "monster_ogre"
"targetname" "spawn"

Our plan is to make an ogre spawn mid-map by running the spawn function called monster_ogre when we trigger this entity (see this post for an explanation of the use hack). Make a trigger with "target" "spawn" and try out your map. Disappointed? The map ought to crash when you try – unfortunately the ogre does something called precaching which is not permitted mid-map.

Although lots of classes are ruled out by this precache rule, there are several important kinds of entity we can use it with. The most important is trigger_multiple. Build a new test map, this time with a trigger_multiple which operates a door. Once you have this working, return to your editor and change the classname of the trigger_multiple to info_notnull*. Add these fields as well

"use" "trigger_multiple"
"targetname" "spawn"

Build your map now and you’ll find the door no longer opens. Back to the editor one last time to add a button which targets “spawn”. You should end up with a map where your door cannot be opened until you press the button to “activate it”. This is the simplest way to create func_ objects like doors and platforms which can be locked until the player completes some task. This trick works with most trigger_ classes and some func_ classes as well, so have a play!

*If you are using worldcraft or hammer you may run into a problem where your brush-based entity collapses into a point entity when you change the classname to info_notnull. If this happens I recommend editing your .fgd file to remove the entry for info_notnull. You can now name both point entities and brush entities info_notnull, although you will have to type it manually.


One thought on “Dynamic Entity Spawning

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s