]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/secret.qc
trigger_secret entity
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / secret.qc
1 entity secret_counter;
2
3 /*
4 .count - total number of secrets to find
5 .cnt - number of secrets found
6 */
7 void secret_counter_create() {
8         print("^1secret_counter_create()\n");
9         secret_counter = spawn();
10         secret_counter.classname = "secret_counter";
11         secret_counter.count = 0;
12         secret_counter.cnt = 0;
13 }
14
15 /*
16 A secret has been found!
17 */
18 void trigger_secret_touch() {
19         // only a player can trigger this
20         if (other.classname != "player")
21                 return;
22         
23         // update secrets found counter
24         secret_counter.cnt += 1;
25         print("Secret found: ", ftos(secret_counter.cnt), "/");
26         print(ftos(secret_counter.count), " - ");
27         print("self=", self.classname, ", other=", other.classname, "\n");
28         
29         // handle normal trigger features
30         multi_touch();
31         remove(self);
32 }
33
34 /*QUAKED trigger_secret (.5 .5 .5) ?
35 Variable sized secret trigger. Can be targeted at one or more entities.
36 Basically, it's a trigger_once (with restrictions, see notes) that additionally updates the number of secrets found.
37 -------- KEYS --------
38 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (default: 1)
39 noise: path to sound file, if you want to play something else
40 target: trigger all entities with this targetname when triggered
41 message: print this message to the player who activated the trigger instead of the standard 'You found a secret!'
42 killtarget: remove all entities with this targetname when triggered
43 -------- NOTES --------
44 You should create a common/trigger textured brush covering the entrance to a secret room/area.
45 Trigger secret can only be trigger by a player's touch and can not be a target itself.
46 */
47 void spawnfunc_trigger_secret() {
48         // FIXME: should it be disabled in most modes?
49         
50         // create secret counter
51         if not(secret_counter)
52                 secret_counter_create();
53         
54         // update secrets count
55         secret_counter.count += 1;
56         
57         // add default message
58         if (self.message == "")
59                 self.message = "You found a secret!";
60         
61         // set default sound
62         if (self.noise == "")
63         if not(self.sounds)
64                 self.sounds = 1; // misc/secret.wav
65         
66         // this entity can't be a target itself!!!!
67         self.targetname = "";
68         
69         // you can't just shoot a room to find it, can you?
70         self.health = 0;
71         
72         // a secret can not be delayed
73         self.delay = 0;
74         
75         // convert this trigger to trigger_once
76         self.classname = "trigger_once";
77         spawnfunc_trigger_once();
78         
79         // take over the touch() function, so we can mark secret as found
80         self.touch = trigger_secret_touch;
81         // ignore triggering;
82         self.use = SUB_Null;
83 }
84