3 - add an unlock sound (here to trigger_keylock and to func_door)
4 - display available keys on the HUD
6 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
7 - should keys have a trigger?
11 ================================
13 ================================
19 void item_key_touch(void) {
27 if (p.classname != "player")
30 // player already picked up this key
31 if (p.itemkeys & self.itemkeys)
34 p.itemkeys |= self.itemkeys;
35 play2(other, self.noise);
38 centerprint(p, self.message);
43 Spawn a key with given model, key code and color.
45 void spawn_item_key(float key_code) {
46 self.itemkeys = key_code;
47 precache_model(self.model);
49 if (self.spawnflags & 1)
53 self.movetype = MOVETYPE_NONE;
55 self.movetype = MOVETYPE_TOSS;
58 self.noise = "misc/itempickup.wav";
60 precache_sound(self.noise);
62 self.mdl = self.model;
63 self.effects = EF_LOWPRECISION;
64 setmodel(self, self.model);
65 //setsize(self, '-16 -16 -24', '16 16 32');
66 setorigin(self, self.origin + '0 0 32');
67 setsize(self, '-16 -16 -56', '16 16 0');
68 self.modelflags |= MF_ROTATE;
69 self.solid = SOLID_TRIGGER;
73 // first nudge it off the floor a little bit to avoid math errors
74 setorigin(self, self.origin + '0 0 1');
75 // note droptofloor returns FALSE if stuck/or would fall too far
79 self.touch = item_key_touch;
83 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
85 -----------KEYS------------
86 colormod: color of the key (default: '.9 .9 .9').
87 message: message to print when player picks up this key.
88 model: custom model to use.
89 noise: custom sound to play when player picks up the key.
90 -------- SPAWNFLAGS --------
91 FLOATING: the item will float in air, instead of aligning to the floor by falling
92 ---------NOTES----------
94 void spawnfunc_item_key1(void) {
96 self.model = "models/keys/key.md3";
99 self.colormod = '.9 .9 .9';
102 self.message = "You've picked up the silver key!";
104 spawn_item_key(KEYS_SILVER_KEY);
107 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
109 -----------KEYS------------
110 colormod: color of the key (default: '1 .9 0').
111 message: message to print when player picks up this key.
112 model: custom model to use.
113 noise: custom sound to play when player picks up the key.
114 -------- SPAWNFLAGS --------
115 FLOATING: the item will float in air, instead of aligning to the floor by falling
116 ---------NOTES----------
118 void spawnfunc_item_key2(void) {
120 self.model = "models/keys/key.md3";
123 self.colormod = '1 .9 0';
126 self.message = "You've picked up the gold key!";
128 spawn_item_key(KEYS_GOLD_KEY);
133 ================================
135 ================================
139 trigger givent targets
141 void trigger_keylock_trigger(string s) {
142 local entity t, stemp, otemp, atemp;
149 for(t = world; (t = find(t, targetname, s)); )
163 kill killtarget of trigger keylock.
165 void trigger_keylock_kill(string s) {
166 local entity t, stemp, otemp, atemp;
172 for(t = world; (t = find(t, targetname, s)); )
182 void trigger_keylock_touch(void) {
183 local float key_used, silver_key_missing, gold_key_missing, started_delay;
187 silver_key_missing = FALSE;
188 gold_key_missing = FALSE;
189 started_delay = FALSE;
196 // only player may trigger the lock
197 if (p.classname != "player")
202 if (self.itemkeys & KEYS_SILVER_KEY) {
203 // lock still requires the SILVER key
204 if (p.itemkeys & KEYS_SILVER_KEY) {
205 self.itemkeys &~= KEYS_SILVER_KEY;
208 silver_key_missing = TRUE;
213 if (self.itemkeys & KEYS_GOLD_KEY) {
214 // lock still requires the GOLD key
215 if (p.itemkeys & KEYS_GOLD_KEY) {
216 self.itemkeys &~= KEYS_GOLD_KEY;
219 gold_key_missing = TRUE;
226 if (silver_key_missing) {
227 // silver key is missing
228 if (self.delay <= time) {
230 trigger_keylock_trigger(self.target4);
231 started_delay = TRUE;
232 self.delay = time + self.wait;
237 if (gold_key_missing) {
238 // gold key is missing
239 if (self.delay <= time || started_delay) {
241 trigger_keylock_trigger(self.target3);
242 started_delay = TRUE;
243 self.delay = time + self.wait;
249 if (silver_key_missing || gold_key_missing) {
250 // at least one of the keys is missing
253 // one key was given, but an other one is missing!
254 play2(other, self.noise1);
255 if (silver_key_missing)
256 centerprint(other, "You also need the silver key!");
257 else if (gold_key_missing)
258 centerprint(other, "You also need the gold key!");
259 p.key_door_messagetime = time + 2;
261 if (p.key_door_messagetime <= time) {
262 play2(other, self.noise2);
263 centerprint(other, self.message2);
264 p.key_door_messagetime = time + 2;
268 if (self.delay <= time || started_delay == TRUE) {
270 trigger_keylock_trigger(self.target2);
271 started_delay = TRUE;
272 self.delay = time + self.wait;
277 // all keys were given!
278 play2(other, self.noise);
279 centerprint(other, self.message);
282 trigger_keylock_trigger(self.target);
285 trigger_keylock_kill(self.killtarget);
292 /*QUAKED trigger_keylock (.0 .5 .8) ? - - - GOLD_KEY SILVER_KEY
293 Keylock trigger. Must target other entities.
294 This trigger will trigger target entities when all required keys are provided.
295 -------- KEYS --------
296 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
297 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav
298 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
299 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
300 target3: trigger all entities with this targetname when triggered with GOLD_KEY missing (requires GOLD_KEY spawnflag)
301 target4: trigger all entities with this targetname when triggered with SILVER_KEY missing (requires SILVER_KEY spawnflag)
302 message: print this message to the player who activated the trigger when all needed keys have been given.
303 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
304 noise: sound to play when lock gets unlocked (default: see sounds)
305 noise1: sound to play when only one of the needed key was used (default: misc/decreasevalue.wav)
306 noise2: sound to play when a key is missing (default: misc/talk.wav)
307 killtarget: remove all entities with this targetname when triggered with all the needed keys.
308 -------- SPAWNFLAGS --------
309 GOLD_KEY: causes the door to open only if the activator holds a gold key.
310 SILVER_KEY: causes the door to open only if the activator holds a silver key.
311 ---------NOTES----------
312 If spawned without any key specified, this trigger will remove itself.
313 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
315 void spawnfunc_trigger_keylock(void) {
316 if (!(self.spawnflags & (SPAWNFLAGS_SILVER_KEY | SPAWNFLAGS_GOLD_KEY))) {
321 // give the trigger the silver key
322 if (self.spawnflags & SPAWNFLAGS_SILVER_KEY)
323 self.itemkeys |= KEYS_SILVER_KEY;
325 // give the trigger the gold key
326 if (self.spawnflags & SPAWNFLAGS_GOLD_KEY)
327 self.itemkeys |= KEYS_GOLD_KEY;
329 if (!self.message2) {
330 // generate default missing key message
331 if (self.itemkeys & (KEYS_GOLD_KEY | KEYS_SILVER_KEY) == KEYS_GOLD_KEY | KEYS_SILVER_KEY) {
332 self.message2 = "Silver key and gold key required!";
333 } else if (self.itemkeys & KEYS_GOLD_KEY) {
334 self.message2 = "Gold key required!";
335 } else if (self.itemkeys & KEYS_SILVER_KEY) {
336 self.message2 = "Silver key required!";
341 self.message = "Unlocked!";
345 if (self.sounds == 1) {
346 self.noise = "misc/secret.wav";
347 } else if (self.sounds == 2) {
348 self.noise = "misc/talk.wav";
349 } else { //if (self.sounds == 3) {
350 self.noise = "misc/trigger1.wav";
355 self.noise1 = "misc/decreasevalue.wav";
358 self.noise2 = "misc/talk.wav";
363 precache_sound(self.noise);
364 precache_sound(self.noise1);
365 precache_sound(self.noise2);
369 self.touch = trigger_keylock_touch;