Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
multivibrator.qc
Go to the documentation of this file.
1#include "multivibrator.qh"
2#ifdef SVQC
4{
5 float cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
6
7 float newstate = (time < cyclestart + this.wait);
8
9 if(this.state != newstate)
10 SUB_UseTargets(this, this, NULL);
11 this.state = newstate;
12
13 if(this.state)
14 this.nextthink = cyclestart + this.wait + 0.01;
15 else
16 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
17}
18
23
24void multivibrator_toggle(entity this, entity actor, entity trigger)
25{
26 if(this.nextthink == 0)
27 {
29 }
30 else
31 {
32 if(this.state)
33 {
34 SUB_UseTargets(this, actor, trigger);
35 this.state = 0;
36 }
37 this.nextthink = 0;
38 }
39}
40
42{
43 if(!(this.spawnflags & START_ENABLED))
44 this.nextthink = 0; // wait for a trigger event
45 else
46 this.nextthink = max(1, time);
47}
48
49/*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ENABLED
50"Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
51-------- KEYS --------
52target: trigger all entities with this targetname when it goes off
53targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
54phase: offset of the timing
55wait: "on" cycle time (default: 1)
56respawntime: "off" cycle time (default: same as wait)
57-------- SPAWNFLAGS --------
58START_ENABLED: assume it is already turned on (when targeted)
59*/
60spawnfunc(trigger_multivibrator)
61{
62 if(!this.wait)
63 this.wait = 1;
64 if(!this.respawntime)
65 this.respawntime = this.wait;
66
67 this.state = 0;
70 this.nextthink = max(1, time);
71
72 if(this.targetname && this.targetname != "")
74}
75#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float wait
Definition items.qc:17
int spawnflags
Definition ammo.qh:15
float time
float nextthink
#define use
int state
const int START_ENABLED
Definition defs.qh:6
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
float floor(float f)
float max(float f,...)
void multivibrator_send(entity this)
void multivibrator_reset(entity this)
void multivibrator_toggle(entity this, entity actor, entity trigger)
void multivibrator_send_think(entity this)
float phase
Definition platforms.qh:10
#define NULL
Definition post.qh:14
#define setthink(e, f)
float respawntime
Definition items.qh:31
#define spawnfunc(id)
Definition spawnfunc.qh:96
string targetname
Definition triggers.qh:56