2 * trigger given targets
4 void trigger_keylock_trigger(string s)
7 entity atemp = activator;
10 for(t = world; (t = find(t, targetname, s)); )
25 * kill killtarget of trigger keylock.
27 void trigger_keylock_kill(string s)
30 for(t = world; (t = find(t, targetname, s)); )
34 void trigger_keylock_touch()
36 bool key_used = false;
37 bool started_delay = false;
39 // only player may trigger the lock
45 key_used = item_keys_usekey(self, other);
52 // at least one of the keys is missing
55 // one or more keys were given, but others are still missing!
56 play2(other, self.noise1);
57 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
58 other.key_door_messagetime = time + 2;
60 else if(other.key_door_messagetime <= time)
63 play2(other, self.noise2);
64 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
65 other.key_door_messagetime = time + 2;
70 if(self.delay <= time || started_delay == true)
73 trigger_keylock_trigger(self.target2);
75 self.delay = time + self.wait;
81 // all keys were given!
82 play2(other, self.noise);
83 centerprint(other, self.message);
87 trigger_keylock_trigger(self.target);
90 trigger_keylock_kill(self.killtarget);
97 REGISTER_NET_LINKED(ENT_CLIENT_KEYLOCK)
100 bool trigger_keylock_send(entity to, int sf)
102 WriteHeader(MSG_ENTITY, ENT_CLIENT_KEYLOCK);
104 WriteInt24_t(MSG_ENTITY, self.itemkeys);
105 WriteByte(MSG_ENTITY, self.height);
107 trigger_common_write(self, true);
112 void trigger_keylock_link()
114 // uncomment to network keylocks
115 //Net_LinkEntity(self, false, 0, trigger_keylock_send);
118 /*QUAKED trigger_keylock (.0 .5 .8) ?
119 Keylock trigger. Must target other entities.
120 This trigger will trigger target entities when all required keys are provided.
121 -------- KEYS --------
122 itemkeys: A bit field with key IDs that are needed to open this lock.
123 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default)
124 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
125 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
126 killtarget: remove all entities with this targetname when triggered with all the needed keys.
127 message: print this message to the player who activated the trigger when all needed keys have been given.
128 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
129 noise: sound to play when lock gets unlocked (default: see sounds)
130 noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav)
131 noise2: sound to play when a key is missing (default: misc/talk.wav)
132 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
133 ---------NOTES----------
134 If spawned without any key specified in itemkeys, this trigger will display an error and remove itself.
135 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
137 spawnfunc(trigger_keylock)
139 if(!self.itemkeys) { remove(self); return; }
141 // set unlocked message
142 if(self.message == "")
143 self.message = "Unlocked!";
145 // set default unlock noise
149 self.noise = "misc/secret.wav";
150 else if(self.sounds == 2)
151 self.noise = strzone(SND(TALK));
152 else //if (self.sounds == 3) {
153 self.noise = "misc/trigger1.wav";
156 // set default use key sound
157 if(self.noise1 == "")
158 self.noise1 = "misc/decreasevalue.wav";
161 if(self.noise2 == "")
162 self.noise2 = SND(TALK);
164 // delay between triggering message2 and trigger2
165 if(!self.wait) { self.wait = 5; }
168 precache_sound(self.noise);
169 precache_sound(self.noise1);
170 precache_sound(self.noise2);
174 self.touch = trigger_keylock_touch;
176 trigger_keylock_link();
179 void keylock_remove(entity this)
181 if(this.target) { strunzone(this.target); }
182 this.target = string_null;
184 if(this.target2) { strunzone(this.target2); }
185 this.target2 = string_null;
187 if(this.target3) { strunzone(this.target3); }
188 this.target3 = string_null;
190 if(this.target4) { strunzone(this.target4); }
191 this.target4 = string_null;
193 if(this.killtarget) { strunzone(this.killtarget); }
194 this.killtarget = string_null;
196 if(this.targetname) { strunzone(this.targetname); }
197 this.targetname = string_null;
200 NET_HANDLE(ENT_CLIENT_KEYLOCK, bool isnew)
202 self.itemkeys = ReadInt24_t();
203 self.height = ReadByte();
205 trigger_common_read(true);
209 self.classname = "trigger_keylock";
210 self.drawmask = MASK_NORMAL;
211 self.draw = trigger_draw_generic;
212 self.trigger_touch = trigger_keylock_touch;
213 self.entremove = keylock_remove;