]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/trigger/counter.qc
Merge branch 'master' into TimePath/scrollpanel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / 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 & 4);
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
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
53 If respawntime is set, it will re-enable itself after the time once the sequence has been completed
54
55 After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
56 */
57 spawnfunc(trigger_counter)
58 {
59         if (!this.count)
60                 this.count = 2;
61         this.cnt = this.count;
62
63         this.use = counter_use;
64         this.reset = counter_reset;
65 }
66 #endif