]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/trigger/counter.qc
Merge branch 'master' into terencehill/scoreboard_stuff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / trigger / counter.qc
1 #include "counter.qh"
2 #ifdef SVQC
3 void counter_reset(entity this);
4
5 void counter_use(entity this, entity actor, entity trigger)
6 {
7         this.count -= 1;
8         if (this.count < 0)
9                 return;
10
11         bool doactivate = (this.spawnflags & COUNTER_FIRE_AT_COUNT);
12
13         if (this.count == 0)
14         {
15                 if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
16                         Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COMPLETED);
17
18                 doactivate = true;
19
20                 if(this.respawntime)
21                 {
22                         setthink(this, counter_reset);
23                         this.nextthink = time + this.respawntime;
24                 }
25         }
26         else
27         {
28                 if(IS_PLAYER(actor) && !(this.spawnflags & SPAWNFLAG_NOMESSAGE))
29                 {
30                         if(this.count >= 4)
31                                 Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER);
32                         else
33                                 Send_Notification(NOTIF_ONE, actor, MSG_CENTER, CENTER_SEQUENCE_COUNTER_FEWMORE, this.count);
34                 }
35         }
36
37         if(doactivate)
38                 SUB_UseTargets(this, actor, trigger);
39 }
40
41 void counter_reset(entity this)
42 {
43         setthink(this, func_null);
44         this.nextthink = 0;
45         this.count = this.cnt;
46 }
47
48 /*QUAKED spawnfunc_trigger_counter (.5 .5 .5) ? nomessage COUNTER_FIRE_AT_COUNT
49 Acts as an intermediary for an action that takes multiple inputs.
50
51 If nomessage is not set, it will print "1 more.. " etc when triggered and "sequence complete" when finished.
52 If COUNTER_FIRE_AT_COUNT is set, it will also fire all of its targets at countdown, making it behave like trigger_mulitple with limited shots
53
54 If respawntime is set, it will re-enable itself after the time once the sequence has been completed
55
56 After the counter has been triggered "count" times (default 2), it will fire all of its targets.
57 */
58 spawnfunc(trigger_counter)
59 {
60         if (!this.count)
61                 this.count = 2;
62         this.cnt = this.count;
63
64         this.use = counter_use;
65         this.reset = counter_reset;
66 }
67 #endif