2 void multivibrator_send()
7 cyclestart = floor((time + self.phase) / (self.wait + self.respawntime)) * (self.wait + self.respawntime) - self.phase;
9 newstate = (time < cyclestart + self.wait);
12 if(self.state != newstate)
14 self.state = newstate;
17 self.nextthink = cyclestart + self.wait + 0.01;
19 self.nextthink = cyclestart + self.wait + self.respawntime + 0.01;
22 void multivibrator_toggle()
24 if(self.nextthink == 0)
39 void multivibrator_reset()
41 if(!(self.spawnflags & 1))
42 self.nextthink = 0; // wait for a trigger event
44 self.nextthink = max(1, time);
47 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON
48 "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
49 -------- KEYS --------
50 target: trigger all entities with this targetname when it goes off
51 targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
52 phase: offset of the timing
53 wait: "on" cycle time (default: 1)
54 respawntime: "off" cycle time (default: same as wait)
55 -------- SPAWNFLAGS --------
56 START_ON: assume it is already turned on (when targeted)
58 void spawnfunc_trigger_multivibrator()
63 self.respawntime = self.wait;
66 self.use = multivibrator_toggle;
67 self.think = multivibrator_send;
68 self.nextthink = max(1, time);
71 multivibrator_reset();