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);
15 this.state = newstate;
18 this.nextthink = cyclestart + this.wait + 0.01;
20 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
24 void multivibrator_send_think(entity this)
26 multivibrator_send(this);
29 void multivibrator_toggle(entity this, entity actor, entity trigger)
31 if (this.nextthink == 0) {
32 multivibrator_send(this);
35 SUB_UseTargets(this, actor, trigger);
42 void multivibrator_reset(entity this)
44 if (!(this.spawnflags & 1)) {
45 this.nextthink = 0; // wait for a trigger event
47 this.nextthink = max(1, time);
51 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON
52 "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
53 -------- KEYS --------
54 target: trigger all entities with this targetname when it goes off
55 targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
56 phase: offset of the timing
57 wait: "on" cycle time (default: 1)
58 respawntime: "off" cycle time (default: same as wait)
59 -------- SPAWNFLAGS --------
60 START_ON: assume it is already turned on (when targeted)
62 spawnfunc(trigger_multivibrator)
67 if (!this.respawntime) {
68 this.respawntime = this.wait;
72 this.use = multivibrator_toggle;
73 setthink(this, multivibrator_send_think);
74 this.nextthink = max(1, time);
77 multivibrator_reset(this);