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 newstate;
6 float cyclestart;
7
8 cyclestart = floor((time + this.phase) / (this.wait + this.respawntime)) * (this.wait + this.respawntime) - this.phase;
9
10 newstate = (time < cyclestart + this.wait);
11
12 if(this.state != newstate)
13 SUB_UseTargets(this, this, NULL);
14 this.state = newstate;
15
16 if(this.state)
17 this.nextthink = cyclestart + this.wait + 0.01;
18 else
19 this.nextthink = cyclestart + this.wait + this.respawntime + 0.01;
20}
21
26
27void multivibrator_toggle(entity this, entity actor, entity trigger)
28{
29 if(this.nextthink == 0)
30 {
32 }
33 else
34 {
35 if(this.state)
36 {
37 SUB_UseTargets(this, actor, trigger);
38 this.state = 0;
39 }
40 this.nextthink = 0;
41 }
42}
43
45{
46 if(!(this.spawnflags & START_ENABLED))
47 this.nextthink = 0; // wait for a trigger event
48 else
49 this.nextthink = max(1, time);
50}
51
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 --------
55target: trigger all entities with this targetname when it goes off
56targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
57phase: offset of the timing
58wait: "on" cycle time (default: 1)
59respawntime: "off" cycle time (default: same as wait)
60-------- SPAWNFLAGS --------
61START_ENABLED: assume it is already turned on (when targeted)
62*/
63spawnfunc(trigger_multivibrator)
64{
65 if(!this.wait)
66 this.wait = 1;
67 if(!this.respawntime)
68 this.respawntime = this.wait;
69
70 this.state = 0;
73 this.nextthink = max(1, time);
74
75 if(this.targetname && this.targetname != "")
77}
78#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:30
#define spawnfunc(id)
Definition spawnfunc.qh:96
string targetname
Definition triggers.qh:56