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 setorigin(wep, e.origin + delta);
47 makevectors(e.angles);
48 wep.classname = "droppedweapon";
49 wep.velocity = velo; // e.velocity * 0.5 + v_forward * 750;
50 SUB_SetFade(wep, time + 20, 1);
63 ammo = min(e.ammo_shells, wep.ammo_shells);
64 wep.ammo_shells = ammo;
65 e.ammo_shells -= ammo;
79 ammo = min(e.ammo_nails, wep.ammo_nails);
80 wep.ammo_nails = ammo;
84 else if(w == WEP_GRENADE_LAUNCHER)
86 w = IT_GRENADE_LAUNCHER;
92 weapon_grenadelauncher();
95 ammo = min(e.ammo_rockets, wep.ammo_rockets);
96 wep.ammo_rockets = ammo;
97 e.ammo_rockets -= ammo;
100 else if(w == WEP_ELECTRO)
111 ammo = min(e.ammo_cells, wep.ammo_cells);
112 wep.ammo_cells = ammo;
113 e.ammo_cells -= ammo;
116 else if(w == WEP_CRYLINK)
127 ammo = min(e.ammo_cells, wep.ammo_cells);
128 wep.ammo_cells = ammo;
129 e.ammo_cells -= ammo;
132 else if(w == WEP_NEX)
143 ammo = min(e.ammo_cells, wep.ammo_cells);
144 wep.ammo_cells = ammo;
145 e.ammo_cells -= ammo;
148 else if(w == WEP_HAGAR)
159 ammo = min(e.ammo_rockets, wep.ammo_rockets);
160 wep.ammo_rockets = ammo;
161 e.ammo_rockets -= ammo;
164 else if(w == WEP_ROCKET_LAUNCHER)
166 w = IT_ROCKET_LAUNCHER;
172 weapon_rocketlauncher();
175 ammo = min(e.ammo_rockets, wep.ammo_rockets);
176 wep.ammo_rockets = ammo;
177 e.ammo_rockets -= ammo;
182 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
184 setorigin(wep, wep.origin);
185 wep.nextthink = time + 0.5;
186 wep.think = thrown_wep_think;
187 wep.classname = "droppedweapon";
188 wep.flags = wep.flags | FL_TOSSED;
189 e.items = e.items - (e.items & w);
190 e.switchweapon = w_getbestweapon(e);
191 wep.colormap = e.colormap;
192 if (e.switchweapon != e.weapon)
197 // switch between weapons
198 void(float imp) W_SwitchWeapon
200 if (self.weapon != imp)
201 if (client_hasweapon(self, imp, TRUE, TRUE))
203 self.cnt = self.weapon;
204 self.switchweapon = imp;
209 void() W_NextWeapon =
211 local float weaponwant, maxtries;
215 weaponwant = self.switchweapon + 1;
216 if (weaponwant < WEP_FIRST)
217 weaponwant = WEP_LAST;
218 if (weaponwant > WEP_LAST)
219 weaponwant = WEP_FIRST;
220 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
226 weaponwant = weaponwant + 1;
227 if (weaponwant < WEP_FIRST)
228 weaponwant = WEP_LAST;
229 if (weaponwant > WEP_LAST)
230 weaponwant = WEP_FIRST;
232 self.cnt = self.weapon;
233 self.switchweapon = weaponwant;
237 void() W_PreviousWeapon =
239 local float weaponwant, maxtries;
243 weaponwant = self.switchweapon - 1;
244 if (weaponwant < WEP_FIRST)
245 weaponwant = WEP_LAST;
246 if (weaponwant > WEP_LAST)
247 weaponwant = WEP_FIRST;
248 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
254 weaponwant = weaponwant - 1;
255 if (weaponwant < WEP_FIRST)
256 weaponwant = WEP_LAST;
257 if (weaponwant > WEP_LAST)
258 weaponwant = WEP_FIRST;
260 self.cnt = self.weapon;
261 self.switchweapon = weaponwant;
264 // Bringed back weapon frame
265 void() W_WeaponFrame =
271 if (!self.weaponentity || self.health < 1)
272 return; // Dead player can't use weapons and injure impulse commands
274 if(!self.switchweapon)
277 self.weaponentity.state = WS_CLEAR;
281 makevectors(self.v_angle);
284 if (self.weapon != self.switchweapon)
286 if (self.weaponentity.state == WS_CLEAR)
288 self.weaponentity.state = WS_RAISE;
289 weapon_action(self.switchweapon, WR_SETUP);
290 // VorteX: add player model weapon select frame here
291 // setcustomframe(PlayerWeaponRaise);
292 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
293 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
295 else if (self.weaponentity.state == WS_READY)
297 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
298 self.weaponentity.state = WS_DROP;
299 // set up weapon switch think in the future, and start drop anim
300 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
301 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
305 // call the think code which may fire the weapon
306 // and do so multiple times to resolve framerate dependency issues if the
307 // server framerate is very low and the weapon fire rate very high
313 weapon_action(self.weapon, WR_THINK);
314 if (self.weapon_nextthink > 0 && time >= self.weapon_nextthink)
316 self.weapon_nextthink_lastframe = self.weapon_nextthink;
321 // don't let attack_finished fall behind when not firing
322 if (self.attack_finished < time)
323 self.attack_finished = time;
325 // update currentammo incase it has changed
326 if (self.items & IT_CELLS)
327 self.currentammo = self.ammo_cells;
328 else if (self.items & IT_ROCKETS)
329 self.currentammo = self.ammo_rockets;
330 else if (self.items & IT_NAILS)
331 self.currentammo = self.ammo_nails;
332 else if (self.items & IT_SHELLS)
333 self.currentammo = self.ammo_shells;
335 self.currentammo = 1;
340 float nixnex_nextchange;
341 float nixnex_nextweapon;
342 .float nixnex_lastchange_id;
343 .float nixnex_lastinfotime;
344 .float nixnex_nextincr;
346 void Nixnex_ChooseNextWeapon()
349 numberof = WEP_LAST - WEP_FIRST; // all but the current one
350 if(cvar("g_nixnex_with_laser"))
351 numberof = numberof - 1;
352 id = WEP_FIRST + ceil(random() * numberof) - 1;
354 if(cvar("g_nixnex_with_laser")) // skip the laser if needed
357 if(id >= nixnex_weapon) // skip the current weapon
360 if(id < WEP_FIRST) // can't happen, but to be sure...
362 dprint("Won't happen (id < WEP_FIRST)\n");
365 if(id > WEP_LAST) // either
367 dprint("Won't happen (id > WEP_LAST)\n");
371 nixnex_nextweapon = id;
374 string W_Name(float weaponid)
376 if(weaponid == WEP_LASER) return "Laser";
377 if(weaponid == WEP_UZI) return "Machine Gun";
378 if(weaponid == WEP_SHOTGUN) return "Shotgun";
379 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
380 if(weaponid == WEP_ELECTRO) return "Electro";
381 if(weaponid == WEP_NEX) return "Nex";
382 if(weaponid == WEP_HAGAR) return "Hagar";
383 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
384 if(weaponid == WEP_CRYLINK) return "Crylink";
385 return "@!#%'n Tuba";
388 void Nixnex_GiveCurrentWeapon()
393 if(!nixnex_nextweapon)
394 Nixnex_ChooseNextWeapon();
396 dt = ceil(nixnex_nextchange - time);
400 nixnex_weapon = nixnex_nextweapon;
401 nixnex_nextweapon = 0;
402 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
405 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
407 self.nixnex_lastchange_id = nixnex_nextchange;
408 if (cvar("g_use_ammunition"))
410 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
411 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
412 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
413 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
417 self.ammo_shells = 999;
418 self.ammo_nails = 999;
419 self.ammo_rockets = 999;
420 self.ammo_cells = 999;
422 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
423 if(dt >= 1 && dt <= 5)
424 self.nixnex_lastinfotime = -42;
427 centermsg_free(CENTERMSG_NIXNEXCOUNT);
428 centermsg_set(CENTERMSG_NIXNEX, strcat("^2Active weapon: ^3", W_Name(nixnex_weapon)));
431 if(self.nixnex_lastinfotime != dt)
433 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
434 if(dt >= 1 && dt <= 5)
436 centermsg_set(CENTERMSG_NIXNEXCOUNT, strcat("^3", ftos(dt), "^2 seconds until weapon change..."));
437 centermsg_set(CENTERMSG_NIXNEX, strcat("Next weapon: ^3", W_Name(nixnex_nextweapon)));
441 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
443 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
444 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
445 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
446 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
447 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
450 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));
451 if(cvar("g_nixnex_with_laser"))
452 self.items = self.items + IT_LASER;
453 self.items = self.items - (self.items & weapon_translateindextoflag(nixnex_weapon)) + weapon_translateindextoflag(nixnex_weapon);
455 if(self.switchweapon != nixnex_weapon)
456 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
457 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
458 W_SwitchWeapon(nixnex_weapon);