Mapping Trigger Logic and new API. - Subject9x/battleMETAL GitHub Wiki
Quake's Triggering system
Quake has an existing system for triggering in-game events and map-logic that is fairly well-established. Many ents utilize the target
/ targetname
convention. This is tied to, in Quake C code to an entity's .void() use
function which must be defined by the programmer.
Most Quakedef
documentation will show what fields are available to the mapper such as target
and targetname
.
BattleMETAL
In battleMETAL I've expanded this simple functionality slightly. The following extensions have been added to select entities.
trigOnDeath
trigOnSpawn
trigOnAttack
trigOnTarget
These are then called by void( entity active, string event) trigger_event
in /qsrc/triggers.qc
Used in context
When used as they've been setup, these should be pointed at the targetname
of other entities in the map.
What happens when they're called:
- code calls
trigger_event
trigger_event
then swaps the entity's values oftrigOn*
andtarget
.- then the code calls
SUB_UseTargets();
which is a Quake 1 original, this finds every entity wheretargetname
matches thetrig
value. - the found entities have their
use()
function called. - if the entity had an existing
target
value, this is restored at the end oftrigger_event
.
Entities that use this
- all
unit_*
AI units. - all
building_*
ents.
A common setup that vanilla battleMETAL is to wire AI deaths to an objective counter.
- create a
trigger_counter
wheretargetname == aName
- each
unit_*
you add, set theirtrigOnDeath
value toaName
- voila! when the unit is killed (their
self.th_die()
function is called), they will also call thetrigger_counter.use()
, just as if they were atarget
/targetname
pair.
extending
If you'd like to extend this functionality, its pretty easy. Simply drop trigger_event
into whichever function you feel appropriate for that particular trigger event.
You will have to do this any time you'd like to add more trigger_event
fields to an entity - entities do not normally call trigOn*
values unless they have the trigger_event
hooked up as well.