2 void multivibrator_send(entity this)
7 cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
9 newstate = (time < cyclestart + this.wait);
11 if(this.state != newstate)
12 SUB_UseTargets(this, this, NULL);
13 this.state = newstate;
16 this.nextthink = cyclestart + this.wait + 0.01;
18 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
21 void multivibrator_send_think(entity this)
23 multivibrator_send(this);
26 void multivibrator_toggle(entity this, entity actor, entity trigger)
28 if(this.nextthink == 0)
30 multivibrator_send(this);
36 SUB_UseTargets(this, actor, trigger);
43 void multivibrator_reset(entity this)
45 if(!(this.spawnflags & 1))
46 this.nextthink = 0; // wait for a trigger event
48 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 this.respawntime = this.wait;
70 this.use = multivibrator_toggle;
71 setthink(this, multivibrator_send_think);
72 this.nextthink = max(1, time);
75 multivibrator_reset(this);