1 #include "multivibrator.qh"
3 void multivibrator_send(entity this)
8 cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
10 newstate = (time < cyclestart + this.wait);
12 if(this.state != newstate)
13 SUB_UseTargets(this, this, NULL);
14 this.state = newstate;
17 this.nextthink = cyclestart + this.wait + 0.01;
19 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
22 void multivibrator_send_think(entity this)
24 multivibrator_send(this);
27 void multivibrator_toggle(entity this, entity actor, entity trigger)
29 if(this.nextthink == 0)
31 multivibrator_send(this);
37 SUB_UseTargets(this, actor, trigger);
44 void multivibrator_reset(entity this)
46 if(!(this.spawnflags & START_ENABLED))
47 this.nextthink = 0; // wait for a trigger event
49 this.nextthink = max(1, time);
52 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ENABLED
53 "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
54 -------- KEYS --------
55 target: trigger all entities with this targetname when it goes off
56 targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
57 phase: offset of the timing
58 wait: "on" cycle time (default: 1)
59 respawntime: "off" cycle time (default: same as wait)
60 -------- SPAWNFLAGS --------
61 START_ENABLED: assume it is already turned on (when targeted)
63 spawnfunc(trigger_multivibrator)
68 this.respawntime = this.wait;
71 this.use = multivibrator_toggle;
72 setthink(this, multivibrator_send_think);
73 this.nextthink = max(1, time);
76 multivibrator_reset(this);