3 #include "../common/triggers/subs.qh"
4 #include "../common/monsters/all.qh"
5 #include "../common/notifications/all.qh"
6 #include "../common/util.qh"
7 #include "../lib/warpzone/util_server.qh"
11 - add an unlock sound (here to trigger_keylock and to func_door)
12 - display available keys on the HUD
14 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
15 - should keys have a trigger?
18 bool item_keys_usekey(entity l, entity p)
20 float valid = l.itemkeys & p.itemkeys;
23 // other has none of the needed keys
25 } else if (l.itemkeys == valid) {
26 // ALL needed keys were given
30 // only some of the needed keys were given
36 string item_keys_keylist(float keylist) {
42 if ((keylist & (keylist-1)) == 0)
43 return strcat("the ", item_keys_names[lowestbit(keylist)]);
48 int l = lowestbit(keylist);
50 n = strcat(n, ", the ", item_keys_names[base + l]);
52 n = strcat("the ", item_keys_names[base + l]);
54 keylist = bitshift(keylist, -(l + 1));
63 ================================
65 ================================
73 if (!IS_PLAYER(other))
76 // player already picked up this key
77 if (other.itemkeys & self.itemkeys)
80 other.itemkeys |= self.itemkeys;
81 play2(other, self.noise);
83 centerprint(other, self.message);
85 string oldmsg = self.message;
89 self.message = oldmsg;
93 * Spawn a key with given model, key code and color.
97 precache_model(self.model);
99 if (self.spawnflags & 1) // FLOATING
103 self.movetype = MOVETYPE_NONE;
105 self.movetype = MOVETYPE_TOSS;
107 precache_sound(self.noise);
109 self.mdl = self.model;
110 self.effects = EF_LOWPRECISION;
111 _setmodel(self, self.model);
112 //setsize(self, '-16 -16 -24', '16 16 32');
113 setorigin(self, self.origin + '0 0 32');
114 setsize(self, '-16 -16 -56', '16 16 0');
115 self.modelflags |= MF_ROTATE;
116 self.solid = SOLID_TRIGGER;
120 // first nudge it off the floor a little bit to avoid math errors
121 setorigin(self, self.origin + '0 0 1');
122 // note droptofloor returns false if stuck/or would fall too far
126 self.touch = item_key_touch;
130 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
132 The itemkeys should contain one of the following key IDs:
140 ... - last key is 1<<23
141 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
142 -----------KEYS------------
143 colormod: color of the key (default: '.9 .9 .9').
145 message: message to print when player picks up this key.
146 model: custom key model to use.
147 netname: the display name of the key.
148 noise: custom sound to play when player picks up the key.
149 -------- SPAWNFLAGS --------
150 FLOATING: the item will float in air, instead of aligning to the floor by falling
151 ---------NOTES----------
152 This is the only correct way to put keys on the map!
154 itemkeys MUST always have exactly one bit set.
161 // reject this entity if more than one key was set!
162 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
163 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
168 // find default netname and colormod
169 switch(self.itemkeys) {
171 _netname = "GOLD key";
172 _colormod = '1 .9 0';
176 _netname = "SILVER key";
177 _colormod = '.9 .9 .9';
181 _netname = "BRONZE key";
182 _colormod = '.6 .25 0';
186 _netname = "RED keycard";
187 _colormod = '.9 0 0';
191 _netname = "BLUE keycard";
192 _colormod = '0 0 .9';
196 _netname = "GREEN keycard";
197 _colormod = '0 .9 0';
201 _netname = "FLUFFY PINK keycard";
204 if (self.netname == "") {
205 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
213 // find default model
214 string _model = string_null;
215 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
216 _model = "models/keys/key.md3";
217 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
218 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
219 } else if (self.model == "") {
220 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
225 // set defailt netname
226 if (self.netname == "")
227 self.netname = _netname;
229 // set default colormod
231 self.colormod = _colormod;
234 if (self.model == "")
237 // set default pickup message
238 if (self.message == "")
239 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
241 if (self.noise == "")
242 self.noise = strzone(SND(ITEMPICKUP));
244 // save the name for later
245 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
247 // put the key on the map
251 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
253 -----------KEYS------------
254 colormod: color of the key (default: '.9 .9 .9').
255 message: message to print when player picks up this key.
256 model: custom model to use.
257 noise: custom sound to play when player picks up the key.
258 -------- SPAWNFLAGS --------
259 FLOATING: the item will float in air, instead of aligning to the floor by falling
260 ---------NOTES----------
261 Don't use this entity on new maps! Use item_key instead.
265 this.classname = "item_key";
266 this.itemkeys = ITEM_KEY_BIT(1);
267 spawnfunc_item_key(this);
270 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
272 -----------KEYS------------
273 colormod: color of the key (default: '1 .9 0').
274 message: message to print when player picks up this key.
275 model: custom model to use.
276 noise: custom sound to play when player picks up the key.
277 -------- SPAWNFLAGS --------
278 FLOATING: the item will float in air, instead of aligning to the floor by falling
279 ---------NOTES----------
280 Don't use this entity on new maps! Use item_key instead.
284 this.classname = "item_key";
285 this.itemkeys = ITEM_KEY_BIT(0);
286 spawnfunc_item_key(this);