]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
trigger_secret entity
authorPrzemysław Grzywacz <nexather@gmail.com>
Sun, 16 Oct 2011 21:23:11 +0000 (23:23 +0200)
committerPrzemysław Grzywacz <nexather@gmail.com>
Sun, 16 Oct 2011 21:23:11 +0000 (23:23 +0200)
qcsrc/server/progs.src
qcsrc/server/secret.qc [new file with mode: 0644]

index c78b9f2fa5908c650ba76fd71cb0298146764599..12a73217170f1bcdf38aa66096cf60775e76195c 100644 (file)
@@ -100,6 +100,7 @@ t_teleporters.qc
 sv_main.qc
 
 g_triggers.qc
+secret.qc
 g_models.qc
 
 cl_weaponsystem.qc
diff --git a/qcsrc/server/secret.qc b/qcsrc/server/secret.qc
new file mode 100644 (file)
index 0000000..07957e5
--- /dev/null
@@ -0,0 +1,84 @@
+entity secret_counter;
+
+/*
+.count - total number of secrets to find
+.cnt - number of secrets found
+*/
+void secret_counter_create() {
+       print("^1secret_counter_create()\n");
+       secret_counter = spawn();
+       secret_counter.classname = "secret_counter";
+       secret_counter.count = 0;
+       secret_counter.cnt = 0;
+}
+
+/*
+A secret has been found!
+*/
+void trigger_secret_touch() {
+       // only a player can trigger this
+       if (other.classname != "player")
+               return;
+       
+       // update secrets found counter
+       secret_counter.cnt += 1;
+       print("Secret found: ", ftos(secret_counter.cnt), "/");
+       print(ftos(secret_counter.count), " - ");
+       print("self=", self.classname, ", other=", other.classname, "\n");
+       
+       // handle normal trigger features
+       multi_touch();
+       remove(self);
+}
+
+/*QUAKED trigger_secret (.5 .5 .5) ?
+Variable sized secret trigger. Can be targeted at one or more entities.
+Basically, it's a trigger_once (with restrictions, see notes) that additionally updates the number of secrets found.
+-------- KEYS --------
+sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (default: 1)
+noise: path to sound file, if you want to play something else
+target: trigger all entities with this targetname when triggered
+message: print this message to the player who activated the trigger instead of the standard 'You found a secret!'
+killtarget: remove all entities with this targetname when triggered
+-------- NOTES --------
+You should create a common/trigger textured brush covering the entrance to a secret room/area.
+Trigger secret can only be trigger by a player's touch and can not be a target itself.
+*/
+void spawnfunc_trigger_secret() {
+       // FIXME: should it be disabled in most modes?
+       
+       // create secret counter
+       if not(secret_counter)
+               secret_counter_create();
+       
+       // update secrets count
+       secret_counter.count += 1;
+       
+       // add default message
+       if (self.message == "")
+               self.message = "You found a secret!";
+       
+       // set default sound
+       if (self.noise == "")
+       if not(self.sounds)
+               self.sounds = 1; // misc/secret.wav
+       
+       // this entity can't be a target itself!!!!
+       self.targetname = "";
+       
+       // you can't just shoot a room to find it, can you?
+       self.health = 0;
+       
+       // a secret can not be delayed
+       self.delay = 0;
+       
+       // convert this trigger to trigger_once
+       self.classname = "trigger_once";
+       spawnfunc_trigger_once();
+       
+       // take over the touch() function, so we can mark secret as found
+       self.touch = trigger_secret_touch;
+       // ignore triggering;
+       self.use = SUB_Null;
+}
+