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);
71 ammo = min(e.ammo_shells, wep.ammo_shells);
72 wep.ammo_shells = ammo;
73 e.ammo_shells -= ammo;
89 ammo = min(e.ammo_nails, wep.ammo_nails);
90 wep.ammo_nails = ammo;
94 else if(w == WEP_GRENADE_LAUNCHER)
96 w = IT_GRENADE_LAUNCHER;
102 weapon_grenadelauncher();
107 ammo = min(e.ammo_rockets, wep.ammo_rockets);
108 wep.ammo_rockets = ammo;
109 e.ammo_rockets -= ammo;
112 else if(w == WEP_ELECTRO)
125 ammo = min(e.ammo_cells, wep.ammo_cells);
126 wep.ammo_cells = ammo;
127 e.ammo_cells -= ammo;
130 else if(w == WEP_CRYLINK)
143 ammo = min(e.ammo_cells, wep.ammo_cells);
144 wep.ammo_cells = ammo;
145 e.ammo_cells -= ammo;
148 else if(w == WEP_NEX)
161 ammo = min(e.ammo_cells, wep.ammo_cells);
162 wep.ammo_cells = ammo;
163 e.ammo_cells -= ammo;
166 else if(w == WEP_HAGAR)
179 ammo = min(e.ammo_rockets, wep.ammo_rockets);
180 wep.ammo_rockets = ammo;
181 e.ammo_rockets -= ammo;
184 else if(w == WEP_ROCKET_LAUNCHER)
186 w = IT_ROCKET_LAUNCHER;
192 weapon_rocketlauncher();
197 ammo = min(e.ammo_rockets, wep.ammo_rockets);
198 wep.ammo_rockets = ammo;
199 e.ammo_rockets -= ammo;
205 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
207 setorigin(wep, wep.origin);
208 wep.nextthink = time + 0.5;
209 wep.think = thrown_wep_think;
210 wep.classname = "droppedweapon";
211 wep.flags = wep.flags | FL_TOSSED;
212 e.items = e.items - (e.items & w);
213 e.switchweapon = w_getbestweapon(e);
214 wep.colormap = e.colormap;
215 if (e.switchweapon != e.weapon)
220 // switch between weapons
221 void(float imp) W_SwitchWeapon
223 if (self.weapon != imp)
224 if (client_hasweapon(self, imp, TRUE, TRUE))
226 self.cnt = self.weapon;
227 self.switchweapon = imp;
232 void() W_NextWeapon =
234 local float weaponwant, maxtries;
238 weaponwant = self.switchweapon + 1;
239 if (weaponwant < WEP_FIRST)
240 weaponwant = WEP_LAST;
241 if (weaponwant > WEP_LAST)
242 weaponwant = WEP_FIRST;
243 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
249 weaponwant = weaponwant + 1;
250 if (weaponwant < WEP_FIRST)
251 weaponwant = WEP_LAST;
252 if (weaponwant > WEP_LAST)
253 weaponwant = WEP_FIRST;
255 self.cnt = self.weapon;
256 self.switchweapon = weaponwant;
260 void() W_PreviousWeapon =
262 local float weaponwant, maxtries;
266 weaponwant = self.switchweapon - 1;
267 if (weaponwant < WEP_FIRST)
268 weaponwant = WEP_LAST;
269 if (weaponwant > WEP_LAST)
270 weaponwant = WEP_FIRST;
271 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
277 weaponwant = weaponwant - 1;
278 if (weaponwant < WEP_FIRST)
279 weaponwant = WEP_LAST;
280 if (weaponwant > WEP_LAST)
281 weaponwant = WEP_FIRST;
283 self.cnt = self.weapon;
284 self.switchweapon = weaponwant;
287 // Bringed back weapon frame
288 void() W_WeaponFrame =
294 if (!self.weaponentity || self.health < 1)
295 return; // Dead player can't use weapons and injure impulse commands
297 if(!self.switchweapon)
300 self.weaponentity.state = WS_CLEAR;
304 makevectors(self.v_angle);
307 if (self.weapon != self.switchweapon)
309 if (self.weaponentity.state == WS_CLEAR)
311 self.weaponentity.state = WS_RAISE;
312 weapon_action(self.switchweapon, WR_SETUP);
313 // VorteX: add player model weapon select frame here
314 // setcustomframe(PlayerWeaponRaise);
315 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
316 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
318 else if (self.weaponentity.state == WS_READY)
320 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
321 self.weaponentity.state = WS_DROP;
322 // set up weapon switch think in the future, and start drop anim
323 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
324 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
328 // call the think code which may fire the weapon
329 // and do so multiple times to resolve framerate dependency issues if the
330 // server framerate is very low and the weapon fire rate very high
336 weapon_action(self.weapon, WR_THINK);
337 if (self.weapon_nextthink > 0 && time >= self.weapon_nextthink)
339 self.weapon_nextthink_lastframe = self.weapon_nextthink;
344 // don't let attack_finished fall behind when not firing
345 if (self.attack_finished < time)
346 self.attack_finished = time;
348 // update currentammo incase it has changed
349 if (self.items & IT_CELLS)
350 self.currentammo = self.ammo_cells;
351 else if (self.items & IT_ROCKETS)
352 self.currentammo = self.ammo_rockets;
353 else if (self.items & IT_NAILS)
354 self.currentammo = self.ammo_nails;
355 else if (self.items & IT_SHELLS)
356 self.currentammo = self.ammo_shells;
358 self.currentammo = 1;
363 float nixnex_nextchange;
364 float nixnex_nextweapon;
365 .float nixnex_lastchange_id;
366 .float nixnex_lastinfotime;
367 .float nixnex_nextincr;
369 void Nixnex_ChooseNextWeapon()
372 numberof = WEP_LAST - WEP_FIRST; // all but the current one
373 if(cvar("g_nixnex_with_laser"))
374 numberof = numberof - 1;
375 id = WEP_FIRST + ceil(random() * numberof) - 1;
377 if(cvar("g_nixnex_with_laser")) // skip the laser if needed
380 if(id >= nixnex_weapon) // skip the current weapon
383 if(id < WEP_FIRST) // can't happen, but to be sure...
385 dprint("Won't happen (id < WEP_FIRST)\n");
388 if(id > WEP_LAST) // either
390 dprint("Won't happen (id > WEP_LAST)\n");
394 nixnex_nextweapon = id;
397 string W_Name(float weaponid)
399 if(weaponid == WEP_LASER) return "Laser";
400 if(weaponid == WEP_UZI) return "Machine Gun";
401 if(weaponid == WEP_SHOTGUN) return "Shotgun";
402 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
403 if(weaponid == WEP_ELECTRO) return "Electro";
404 if(weaponid == WEP_NEX) return "Nex";
405 if(weaponid == WEP_HAGAR) return "Hagar";
406 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
407 if(weaponid == WEP_CRYLINK) return "Crylink";
408 return "@!#%'n Tuba";
411 void Nixnex_GiveCurrentWeapon()
416 if(!nixnex_nextweapon)
417 Nixnex_ChooseNextWeapon();
419 dt = ceil(nixnex_nextchange - time);
423 nixnex_weapon = nixnex_nextweapon;
424 nixnex_nextweapon = 0;
425 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
428 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
430 self.nixnex_lastchange_id = nixnex_nextchange;
431 if (cvar("g_use_ammunition"))
433 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
434 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
435 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
436 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
440 self.ammo_shells = 999;
441 self.ammo_nails = 999;
442 self.ammo_rockets = 999;
443 self.ammo_cells = 999;
445 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
446 if(dt >= 1 && dt <= 5)
447 self.nixnex_lastinfotime = -42;
450 centermsg_free(CENTERMSG_NIXNEXCOUNT);
451 centermsg_set(CENTERMSG_NIXNEX, strcat("^2Active weapon: ^3", W_Name(nixnex_weapon)));
454 if(self.nixnex_lastinfotime != dt)
456 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
457 if(dt >= 1 && dt <= 5)
459 centermsg_set(CENTERMSG_NIXNEXCOUNT, strcat("^3", ftos(dt), "^2 seconds until weapon change..."));
460 centermsg_set(CENTERMSG_NIXNEX, strcat("Next weapon: ^3", W_Name(nixnex_nextweapon)));
464 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
466 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
467 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
468 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
469 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
470 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
473 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));
474 if(cvar("g_nixnex_with_laser"))
475 self.items = self.items + IT_LASER;
476 self.items = self.items - (self.items & weapon_translateindextoflag(nixnex_weapon)) + weapon_translateindextoflag(nixnex_weapon);
478 if(self.switchweapon != nixnex_weapon)
479 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
480 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
481 W_SwitchWeapon(nixnex_weapon);