2 // generic weapons table
3 // add new weapons here
4 float(float wpn, float wrequest) weapon_action =
7 return w_laser(wrequest);
8 else if (wpn == WEP_SHOTGUN)
9 return w_shotgun(wrequest);
10 else if (wpn == WEP_UZI)
11 return w_uzi(wrequest);
12 else if (wpn == WEP_GRENADE_LAUNCHER)
13 return w_glauncher(wrequest);
14 else if (wpn == WEP_ELECTRO)
15 return w_electro(wrequest);
16 else if (wpn == WEP_CRYLINK)
17 return w_crylink(wrequest);
18 else if (wpn == WEP_NEX)
19 return w_nex(wrequest);
20 else if (wpn == WEP_HAGAR)
21 return w_hagar(wrequest);
22 else if (wpn == WEP_ROCKET_LAUNCHER)
23 return w_rlauncher(wrequest);
27 // think function for tossed weapons
28 void() thrown_wep_think
30 self.solid = SOLID_TRIGGER;
32 SUB_SetFade(self, time + 20, 1);
33 setorigin(self, self.origin);
36 // toss current weapon
37 void(vector velo, vector delta, float doreduce) W_ThrowWeapon
46 return; // just in case
52 setorigin(wep, e.origin + delta);
53 makevectors(e.angles);
54 wep.classname = "droppedweapon";
55 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
56 SUB_SetFade(wep, time + 20, 1);
75 ammo = min(e.ammo_shells, wep.ammo_shells);
76 wep.ammo_shells = ammo;
77 e.ammo_shells -= ammo;
97 ammo = min(e.ammo_nails, wep.ammo_nails);
98 wep.ammo_nails = ammo;
102 else if(w == WEP_GRENADE_LAUNCHER)
104 w = IT_GRENADE_LAUNCHER;
111 weapon_grenadelauncher();
119 ammo = min(e.ammo_rockets, wep.ammo_rockets);
120 wep.ammo_rockets = ammo;
121 e.ammo_rockets -= ammo;
124 else if(w == WEP_ELECTRO)
141 ammo = min(e.ammo_cells, wep.ammo_cells);
142 wep.ammo_cells = ammo;
143 e.ammo_cells -= ammo;
146 else if(w == WEP_CRYLINK)
163 ammo = min(e.ammo_cells, wep.ammo_cells);
164 wep.ammo_cells = ammo;
165 e.ammo_cells -= ammo;
168 else if(w == WEP_NEX)
185 ammo = min(e.ammo_cells, wep.ammo_cells);
186 wep.ammo_cells = ammo;
187 e.ammo_cells -= ammo;
190 else if(w == WEP_HAGAR)
207 ammo = min(e.ammo_rockets, wep.ammo_rockets);
208 wep.ammo_rockets = ammo;
209 e.ammo_rockets -= ammo;
212 else if(w == WEP_ROCKET_LAUNCHER)
214 w = IT_ROCKET_LAUNCHER;
221 weapon_rocketlauncher();
229 ammo = min(e.ammo_rockets, wep.ammo_rockets);
230 wep.ammo_rockets = ammo;
231 e.ammo_rockets -= ammo;
237 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
239 setorigin(wep, wep.origin);
240 wep.nextthink = time + 0.5;
241 wep.think = thrown_wep_think;
242 wep.classname = "droppedweapon";
243 wep.flags = wep.flags | FL_TOSSED;
244 e.items = e.items - (e.items & w);
245 e.switchweapon = w_getbestweapon(e);
246 wep.colormap = e.colormap;
247 if (e.switchweapon != e.weapon)
252 // switch between weapons
253 void(float imp) W_SwitchWeapon
255 if (self.weapon != imp)
256 if (client_hasweapon(self, imp, TRUE, TRUE))
258 self.cnt = self.weapon;
259 self.switchweapon = imp;
264 void() W_NextWeapon =
266 local float weaponwant, maxtries;
270 weaponwant = self.switchweapon + 1;
271 if (weaponwant < WEP_FIRST)
272 weaponwant = WEP_LAST;
273 if (weaponwant > WEP_LAST)
274 weaponwant = WEP_FIRST;
275 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
281 weaponwant = weaponwant + 1;
282 if (weaponwant < WEP_FIRST)
283 weaponwant = WEP_LAST;
284 if (weaponwant > WEP_LAST)
285 weaponwant = WEP_FIRST;
287 self.cnt = self.weapon;
288 self.switchweapon = weaponwant;
292 void() W_PreviousWeapon =
294 local float weaponwant, maxtries;
298 weaponwant = self.switchweapon - 1;
299 if (weaponwant < WEP_FIRST)
300 weaponwant = WEP_LAST;
301 if (weaponwant > WEP_LAST)
302 weaponwant = WEP_FIRST;
303 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
309 weaponwant = weaponwant - 1;
310 if (weaponwant < WEP_FIRST)
311 weaponwant = WEP_LAST;
312 if (weaponwant > WEP_LAST)
313 weaponwant = WEP_FIRST;
315 self.cnt = self.weapon;
316 self.switchweapon = weaponwant;
319 // Bringed back weapon frame
320 void() W_WeaponFrame =
326 if (!self.weaponentity || self.health < 1)
327 return; // Dead player can't use weapons and injure impulse commands
329 if(!self.switchweapon)
332 self.weaponentity.state = WS_CLEAR;
336 makevectors(self.v_angle);
339 if (self.weapon != self.switchweapon)
341 if (self.weaponentity.state == WS_CLEAR)
343 self.weaponentity.state = WS_RAISE;
344 weapon_action(self.switchweapon, WR_SETUP);
345 // VorteX: add player model weapon select frame here
346 // setcustomframe(PlayerWeaponRaise);
347 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
348 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
350 else if (self.weaponentity.state == WS_READY)
352 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
353 self.weaponentity.state = WS_DROP;
354 // set up weapon switch think in the future, and start drop anim
355 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
356 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
360 // call the think code which may fire the weapon
361 // and do so multiple times to resolve framerate dependency issues if the
362 // server framerate is very low and the weapon fire rate very high
368 weapon_action(self.weapon, WR_THINK);
369 if (self.weapon_nextthink > 0 && time >= self.weapon_nextthink)
371 self.weapon_nextthink_lastframe = self.weapon_nextthink;
376 // don't let attack_finished fall behind when not firing
377 if (self.attack_finished < time)
378 self.attack_finished = time;
380 // update currentammo incase it has changed
381 if (self.items & IT_CELLS)
382 self.currentammo = self.ammo_cells;
383 else if (self.items & IT_ROCKETS)
384 self.currentammo = self.ammo_rockets;
385 else if (self.items & IT_NAILS)
386 self.currentammo = self.ammo_nails;
387 else if (self.items & IT_SHELLS)
388 self.currentammo = self.ammo_shells;
390 self.currentammo = 1;
395 float nixnex_nextchange;
396 float nixnex_nextweapon;
397 .float nixnex_lastchange_id;
398 .float nixnex_lastinfotime;
399 .float nixnex_nextincr;
401 void Nixnex_ChooseNextWeapon()
404 numberof = WEP_LAST - WEP_FIRST; // all but the current one
405 if(cvar("g_nixnex_with_laser"))
406 numberof = numberof - 1;
407 id = WEP_FIRST + ceil(random() * numberof) - 1;
409 if(cvar("g_nixnex_with_laser")) // skip the laser if needed
412 if(id >= nixnex_weapon) // skip the current weapon
415 if(id < WEP_FIRST) // can't happen, but to be sure...
417 dprint("Won't happen (id < WEP_FIRST)\n");
420 if(id > WEP_LAST) // either
422 dprint("Won't happen (id > WEP_LAST)\n");
426 nixnex_nextweapon = id;
429 string W_Name(float weaponid)
431 if(weaponid == WEP_LASER) return "Laser";
432 if(weaponid == WEP_UZI) return "Machine Gun";
433 if(weaponid == WEP_SHOTGUN) return "Shotgun";
434 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
435 if(weaponid == WEP_ELECTRO) return "Electro";
436 if(weaponid == WEP_NEX) return "Nex";
437 if(weaponid == WEP_HAGAR) return "Hagar";
438 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
439 if(weaponid == WEP_CRYLINK) return "Crylink";
440 return "@!#%'n Tuba";
443 void Nixnex_GiveCurrentWeapon()
448 if(!nixnex_nextweapon)
449 Nixnex_ChooseNextWeapon();
451 dt = ceil(nixnex_nextchange - time);
455 nixnex_weapon = nixnex_nextweapon;
456 nixnex_nextweapon = 0;
457 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
460 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
462 self.nixnex_lastchange_id = nixnex_nextchange;
463 if (cvar("g_use_ammunition"))
465 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
466 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
467 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
468 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
472 self.ammo_shells = 999;
473 self.ammo_nails = 999;
474 self.ammo_rockets = 999;
475 self.ammo_cells = 999;
477 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
478 if(dt >= 1 && dt <= 5)
479 self.nixnex_lastinfotime = -42;
482 centermsg_free(CENTERMSG_NIXNEXCOUNT);
483 centermsg_set(CENTERMSG_NIXNEX, strcat("^2Active weapon: ^3", W_Name(nixnex_weapon)));
486 if(self.nixnex_lastinfotime != dt)
488 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
489 if(dt >= 1 && dt <= 5)
491 centermsg_set(CENTERMSG_NIXNEXCOUNT, strcat("^3", ftos(dt), "^2 seconds until weapon change..."));
492 centermsg_set(CENTERMSG_NIXNEX, strcat("Next weapon: ^3", W_Name(nixnex_nextweapon)));
496 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
498 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
499 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
500 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
501 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
502 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
505 self.items = self.items - (self.items & (IT_LASER | IT_SHOTGUN | IT_UZI | IT_GRENADE_LAUNCHER | IT_ELECTRO | IT_CRYLINK | IT_NEX | IT_HAGAR | IT_ROCKET_LAUNCHER));
506 if(cvar("g_nixnex_with_laser"))
507 self.items = self.items + IT_LASER;
508 self.items = self.items - (self.items & weapon_translateindextoflag(nixnex_weapon)) + weapon_translateindextoflag(nixnex_weapon);
510 if(self.switchweapon != nixnex_weapon)
511 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
512 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
513 W_SwitchWeapon(nixnex_weapon);