4 bool item_keys_usekey(entity l, entity p)
6 int valid = (l.itemkeys & p.itemkeys); // TODO: itemkeys isn't networked or anything!
7 l.itemkeys &= ~valid; // only some of the needed keys were given
15 - add an unlock sound (here to trigger_keylock and to func_door)
16 - display available keys on the HUD
18 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
19 - should keys have a trigger?
22 bool item_keys_usekey(entity l, entity p)
24 int valid = l.itemkeys & p.itemkeys;
27 // player has none of the needed keys
29 } else if (l.itemkeys == valid) {
30 // ALL needed keys were given
34 // only some of the needed keys were given
40 string item_keys_keylist(float keylist) {
46 if ((keylist & (keylist-1)) == 0)
47 return strcat("the ", item_keys_names[lowestbit(keylist)]);
52 int l = lowestbit(keylist);
54 n = strcat(n, ", the ", item_keys_names[base + l]);
56 n = strcat("the ", item_keys_names[base + l]);
58 keylist = bitshift(keylist, -(l + 1));
67 ================================
69 ================================
75 void item_key_touch(entity this, entity toucher)
77 if (!IS_PLAYER(toucher))
80 // player already picked up this key
81 if (PS(toucher).itemkeys & this.itemkeys)
84 PS(toucher).itemkeys |= this.itemkeys;
85 play2(toucher, this.noise);
87 centerprint(toucher, this.message);
89 string oldmsg = this.message;
91 SUB_UseTargets(this, toucher, toucher); // TODO: should we be using toucher for the trigger here?
92 this.message = oldmsg;
96 * Spawn a key with given model, key code and color.
98 void spawn_item_key(entity this)
100 precache_model(this.model);
102 if (this.spawnflags & 1) // FLOATING
106 set_movetype(this, MOVETYPE_NONE);
108 set_movetype(this, MOVETYPE_TOSS);
110 precache_sound(this.noise);
112 this.mdl = this.model;
113 this.effects = EF_LOWPRECISION;
114 _setmodel(this, this.model);
115 //setsize(this, '-16 -16 -24', '16 16 32');
116 setorigin(this, this.origin + '0 0 32');
117 setsize(this, '-16 -16 -56', '16 16 0');
118 this.modelflags |= MF_ROTATE;
119 this.solid = SOLID_TRIGGER;
123 // first nudge it off the floor a little bit to avoid math errors
124 setorigin(this, this.origin + '0 0 1');
125 // note droptofloor returns false if stuck/or would fall too far
129 settouch(this, item_key_touch);
133 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
135 The itemkeys should contain one of the following key IDs:
143 ... - last key is 1<<23
144 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
145 -----------KEYS------------
146 colormod: color of the key (default: '.9 .9 .9').
148 message: message to print when player picks up this key.
149 model: custom key model to use.
150 netname: the display name of the key.
151 noise: custom sound to play when player picks up the key.
152 -------- SPAWNFLAGS --------
153 FLOATING: the item will float in air, instead of aligning to the floor by falling
154 ---------NOTES----------
155 This is the only correct way to put keys on the map!
157 itemkeys MUST always have exactly one bit set.
164 // reject this entity if more than one key was set!
165 if (this.itemkeys>0 && (this.itemkeys & (this.itemkeys-1)) != 0) {
166 objerror(this, "item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
171 // find default netname and colormod
172 switch(this.itemkeys) {
174 _netname = "GOLD key";
175 _colormod = '1 .9 0';
179 _netname = "SILVER key";
180 _colormod = '.9 .9 .9';
184 _netname = "BRONZE key";
185 _colormod = '.6 .25 0';
189 _netname = "RED keycard";
190 _colormod = '.9 0 0';
194 _netname = "BLUE keycard";
195 _colormod = '0 0 .9';
199 _netname = "GREEN keycard";
200 _colormod = '0 .9 0';
204 _netname = "FLUFFY PINK keycard";
207 if (this.netname == "") {
208 objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!");
216 // find default model
217 string _model = string_null;
218 if (this.itemkeys <= ITEM_KEY_BIT(2)) {
219 _model = "models/keys/key.md3";
220 } else if (this.itemkeys >= ITEM_KEY_BIT(3) && this.itemkeys <= ITEM_KEY_BIT(5)) {
221 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
222 } else if (this.model == "") {
223 objerror(this, "item_key doesn't have a default model for this key and a custom one was not specified!");
228 // set defailt netname
229 if (this.netname == "")
230 this.netname = _netname;
232 // set default colormod
234 this.colormod = _colormod;
237 if (this.model == "")
240 // set default pickup message
241 if (this.message == "")
242 this.message = strzone(strcat("You've picked up the ", this.netname, "!"));
244 if (this.noise == "")
245 this.noise = strzone(SND(ITEMPICKUP));
247 // save the name for later
248 item_keys_names[lowestbit(this.itemkeys)] = this.netname;
250 // put the key on the map
251 spawn_item_key(this);
254 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
256 -----------KEYS------------
257 colormod: color of the key (default: '.9 .9 .9').
258 message: message to print when player picks up this key.
259 model: custom model to use.
260 noise: custom sound to play when player picks up the key.
261 -------- SPAWNFLAGS --------
262 FLOATING: the item will float in air, instead of aligning to the floor by falling
263 ---------NOTES----------
264 Don't use this entity on new maps! Use item_key instead.
268 this.classname = "item_key";
269 this.itemkeys = ITEM_KEY_BIT(1);
270 spawnfunc_item_key(this);
273 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
275 -----------KEYS------------
276 colormod: color of the key (default: '1 .9 0').
277 message: message to print when player picks up this key.
278 model: custom model to use.
279 noise: custom sound to play when player picks up the key.
280 -------- SPAWNFLAGS --------
281 FLOATING: the item will float in air, instead of aligning to the floor by falling
282 ---------NOTES----------
283 Don't use this entity on new maps! Use item_key instead.
287 this.classname = "item_key";
288 this.itemkeys = ITEM_KEY_BIT(0);
289 spawnfunc_item_key(this);