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:

  1. code calls trigger_event
  2. trigger_event then swaps the entity's values of trigOn* and target.
  3. then the code calls SUB_UseTargets(); which is a Quake 1 original, this finds every entity where targetname matches the trig value.
  4. the found entities have their use() function called.
  5. if the entity had an existing target value, this is restored at the end of trigger_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 where targetname == aName
  • each unit_* you add, set their trigOnDeath value to aName
  • voila! when the unit is killed (their self.th_die() function is called), they will also call the trigger_counter.use(), just as if they were a target/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.