Post by mik1 on Oct 1, 2012 7:49:42 GMT -5
I started a map that uses the trigger_key to spawn ammo, i was thinking of making some kind of shop system mainly for testing. When i tried it, it activates once and stays that way, because in the main game theres no need for repeating key doors.
I want to know if its possible to modify the key function so instead of removing itself on activation, it would repeat so it can be used again, kinda like what buttons do.
I found a code that should be the trigger_key actions.
I want to know if its possible to modify the key function so instead of removing itself on activation, it would repeat so it can be used again, kinda like what buttons do.
I found a code that should be the trigger_key actions.
/*211 ==============================================================================
212
213 trigger_key
214
215 ==============================================================================
216 */
217
218 /*QUAKED trigger_key (.5 .5 .5) (-8 -8 -8) (8 8 8)
219 A relay trigger that only fires it's targets if player has the proper key.
220 Use "item" to specify the required key, for example "key_data_cd"
221 */
222 void trigger_key_use (edict_t *self, edict_t *other, edict_t *activator)
223 {
224 int index;
225
226 if (!self->item)
227 return;
228 if (!activator->client)
229 return;
230
231 index = ITEM_INDEX(self->item);
232 if (!activator->client->pers.inventory[index])
233 {
234 if (level.time < self->touch_debounce_time)
235 return;
236 self->touch_debounce_time = level.time + 5.0;
237 gi.centerprintf (activator, "You need the %s", self->item->pickup_name);
238 gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keytry.wav"), 1, ATTN_NORM, 0);
239 return;
240 }
241
242 gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keyuse.wav"), 1, ATTN_NORM, 0);
243 if (coop->value)
244 {
245 int player;
246 edict_t *ent;
247
248 if (strcmp(self->item->classname, "key_power_cube") == 0)
249 {
250 int cube;
251
252 for (cube = 0; cube < 8; cube++)
253 if (activator->client->pers.power_cubes & (1 << cube))
254 break;
255 for (player = 1; player <= game.maxclients; player++)
256 {
257 ent = &g_edicts[player];
258 if (!ent->inuse)
259 continue;
260 if (!ent->client)
261 continue;
262 if (ent->client->pers.power_cubes & (1 << cube))
263 {
264 ent->client->pers.inventory[index]--;
265 ent->client->pers.power_cubes &= ~(1 << cube);
266 }
267 }
268 }
269 else
270 {
271 for (player = 1; player <= game.maxclients; player++)
272 {
273 ent = &g_edicts[player];
274 if (!ent->inuse)
275 continue;
276 if (!ent->client)
277 continue;
278 ent->client->pers.inventory[index] = 0;
279 }
280 }
281 }
282 else
283 {
284 activator->client->pers.inventory[index]--;
285 }
286
287 G_UseTargets (self, activator);
288
289 self->use = NULL;
290 }
212
213 trigger_key
214
215 ==============================================================================
216 */
217
218 /*QUAKED trigger_key (.5 .5 .5) (-8 -8 -8) (8 8 8)
219 A relay trigger that only fires it's targets if player has the proper key.
220 Use "item" to specify the required key, for example "key_data_cd"
221 */
222 void trigger_key_use (edict_t *self, edict_t *other, edict_t *activator)
223 {
224 int index;
225
226 if (!self->item)
227 return;
228 if (!activator->client)
229 return;
230
231 index = ITEM_INDEX(self->item);
232 if (!activator->client->pers.inventory[index])
233 {
234 if (level.time < self->touch_debounce_time)
235 return;
236 self->touch_debounce_time = level.time + 5.0;
237 gi.centerprintf (activator, "You need the %s", self->item->pickup_name);
238 gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keytry.wav"), 1, ATTN_NORM, 0);
239 return;
240 }
241
242 gi.sound (activator, CHAN_AUTO, gi.soundindex ("misc/keyuse.wav"), 1, ATTN_NORM, 0);
243 if (coop->value)
244 {
245 int player;
246 edict_t *ent;
247
248 if (strcmp(self->item->classname, "key_power_cube") == 0)
249 {
250 int cube;
251
252 for (cube = 0; cube < 8; cube++)
253 if (activator->client->pers.power_cubes & (1 << cube))
254 break;
255 for (player = 1; player <= game.maxclients; player++)
256 {
257 ent = &g_edicts[player];
258 if (!ent->inuse)
259 continue;
260 if (!ent->client)
261 continue;
262 if (ent->client->pers.power_cubes & (1 << cube))
263 {
264 ent->client->pers.inventory[index]--;
265 ent->client->pers.power_cubes &= ~(1 << cube);
266 }
267 }
268 }
269 else
270 {
271 for (player = 1; player <= game.maxclients; player++)
272 {
273 ent = &g_edicts[player];
274 if (!ent->inuse)
275 continue;
276 if (!ent->client)
277 continue;
278 ent->client->pers.inventory[index] = 0;
279 }
280 }
281 }
282 else
283 {
284 activator->client->pers.inventory[index]--;
285 }
286
287 G_UseTargets (self, activator);
288
289 self->use = NULL;
290 }