2 * trigger given targets
4 void trigger_keylock_trigger(string s)
6 for(entity t = world; (t = find(t, targetname, s)); )
12 * kill killtarget of trigger keylock.
14 void trigger_keylock_kill(string s)
17 for(t = world; (t = find(t, targetname, s)); )
21 void trigger_keylock_touch()
23 bool key_used = false;
24 bool started_delay = false;
26 // only player may trigger the lock
32 key_used = item_keys_usekey(self, other);
39 // at least one of the keys is missing
42 // one or more keys were given, but others are still missing!
43 play2(other, self.noise1);
44 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
45 other.key_door_messagetime = time + 2;
47 else if(other.key_door_messagetime <= time)
50 play2(other, self.noise2);
51 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
52 other.key_door_messagetime = time + 2;
57 if(self.delay <= time || started_delay == true)
60 trigger_keylock_trigger(self.target2);
62 self.delay = time + self.wait;
68 // all keys were given!
69 play2(other, self.noise);
70 centerprint(other, self.message);
74 trigger_keylock_trigger(self.target);
77 trigger_keylock_kill(self.killtarget);
84 REGISTER_NET_LINKED(ENT_CLIENT_KEYLOCK)
87 bool trigger_keylock_send(entity to, int sf)
89 WriteHeader(MSG_ENTITY, ENT_CLIENT_KEYLOCK);
91 WriteInt24_t(MSG_ENTITY, self.itemkeys);
92 WriteByte(MSG_ENTITY, self.height);
94 trigger_common_write(self, true);
99 void trigger_keylock_link()
101 // uncomment to network keylocks
102 //Net_LinkEntity(self, false, 0, trigger_keylock_send);
105 /*QUAKED trigger_keylock (.0 .5 .8) ?
106 Keylock trigger. Must target other entities.
107 This trigger will trigger target entities when all required keys are provided.
108 -------- KEYS --------
109 itemkeys: A bit field with key IDs that are needed to open this lock.
110 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default)
111 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
112 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
113 killtarget: remove all entities with this targetname when triggered with all the needed keys.
114 message: print this message to the player who activated the trigger when all needed keys have been given.
115 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
116 noise: sound to play when lock gets unlocked (default: see sounds)
117 noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav)
118 noise2: sound to play when a key is missing (default: misc/talk.wav)
119 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
120 ---------NOTES----------
121 If spawned without any key specified in itemkeys, this trigger will display an error and remove itself.
122 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
124 spawnfunc(trigger_keylock)
126 if(!self.itemkeys) { remove(self); return; }
128 // set unlocked message
129 if(self.message == "")
130 self.message = "Unlocked!";
132 // set default unlock noise
136 self.noise = "misc/secret.wav";
137 else if(self.sounds == 2)
138 self.noise = strzone(SND(TALK));
139 else //if (self.sounds == 3) {
140 self.noise = "misc/trigger1.wav";
143 // set default use key sound
144 if(self.noise1 == "")
145 self.noise1 = "misc/decreasevalue.wav";
148 if(self.noise2 == "")
149 self.noise2 = SND(TALK);
151 // delay between triggering message2 and trigger2
152 if(!self.wait) { self.wait = 5; }
155 precache_sound(self.noise);
156 precache_sound(self.noise1);
157 precache_sound(self.noise2);
161 self.touch = trigger_keylock_touch;
163 trigger_keylock_link();
166 void keylock_remove(entity this)
168 if(this.target) { strunzone(this.target); }
169 this.target = string_null;
171 if(this.target2) { strunzone(this.target2); }
172 this.target2 = string_null;
174 if(this.target3) { strunzone(this.target3); }
175 this.target3 = string_null;
177 if(this.target4) { strunzone(this.target4); }
178 this.target4 = string_null;
180 if(this.killtarget) { strunzone(this.killtarget); }
181 this.killtarget = string_null;
183 if(this.targetname) { strunzone(this.targetname); }
184 this.targetname = string_null;
187 NET_HANDLE(ENT_CLIENT_KEYLOCK, bool isnew)
189 self.itemkeys = ReadInt24_t();
190 self.height = ReadByte();
192 trigger_common_read(true);
196 self.classname = "trigger_keylock";
197 self.drawmask = MASK_NORMAL;
198 self.draw = trigger_draw_generic;
199 self.trigger_touch = trigger_keylock_touch;
200 self.entremove = keylock_remove;