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
46 setorigin(wep, e.origin);
47 makevectors(e.angles);
48 wep.classname = "droppedweapon";
49 wep.velocity = e.velocity * 0.5 + v_forward * 750;
50 SUB_SetFade(wep, time + 20, 1);
61 ammo = min(e.ammo_shells, wep.ammo_shells);
62 wep.ammo_shells = ammo;
63 e.ammo_shells -= ammo;
74 ammo = min(e.ammo_nails, wep.ammo_nails);
75 wep.ammo_nails = ammo;
78 else if(w == WEP_GRENADE_LAUNCHER)
80 w = IT_GRENADE_LAUNCHER;
86 weapon_grenadelauncher();
87 ammo = min(e.ammo_rockets, wep.ammo_rockets);
88 wep.ammo_rockets = ammo;
89 e.ammo_rockets -= ammo;
91 else if(w == WEP_ELECTRO)
100 ammo = min(e.ammo_cells, wep.ammo_cells);
101 wep.ammo_cells = ammo;
102 e.ammo_cells -= ammo;
104 else if(w == WEP_CRYLINK)
113 ammo = min(e.ammo_cells, wep.ammo_cells);
114 wep.ammo_cells = ammo;
115 e.ammo_cells -= ammo;
117 else if(w == WEP_NEX)
126 ammo = min(e.ammo_cells, wep.ammo_cells);
127 wep.ammo_cells = ammo;
128 e.ammo_cells -= ammo;
130 else if(w == WEP_HAGAR)
139 ammo = min(e.ammo_rockets, wep.ammo_rockets);
140 wep.ammo_rockets = ammo;
141 e.ammo_rockets -= ammo;
143 else if(w == WEP_ROCKET_LAUNCHER)
145 w = IT_ROCKET_LAUNCHER;
151 weapon_rocketlauncher();
152 ammo = min(e.ammo_rockets, wep.ammo_rockets);
153 wep.ammo_rockets = ammo;
154 e.ammo_rockets -= ammo;
158 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
160 setorigin(wep, wep.origin);
161 wep.nextthink = time + 0.5;
162 wep.think = thrown_wep_think;
163 wep.classname = "droppedweapon";
164 wep.flags = wep.flags | FL_TOSSED;
165 e.items = e.items - (e.items & w);
166 e.switchweapon = w_getbestweapon(e);
167 wep.colormap = e.colormap;
168 if (e.switchweapon != e.weapon)
173 // switch between weapons
174 void(float imp) W_SwitchWeapon
176 if (self.weapon != imp)
177 if (client_hasweapon(self, imp, TRUE, TRUE))
179 self.cnt = self.weapon;
180 self.switchweapon = imp;
185 void() W_NextWeapon =
187 local float weaponwant, maxtries;
191 weaponwant = self.switchweapon + 1;
192 if (weaponwant < WEP_FIRST)
193 weaponwant = WEP_LAST;
194 if (weaponwant > WEP_LAST)
195 weaponwant = WEP_FIRST;
196 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
202 weaponwant = weaponwant + 1;
203 if (weaponwant < WEP_FIRST)
204 weaponwant = WEP_LAST;
205 if (weaponwant > WEP_LAST)
206 weaponwant = WEP_FIRST;
208 self.cnt = self.weapon;
209 self.switchweapon = weaponwant;
213 void() W_PreviousWeapon =
215 local float weaponwant, maxtries;
219 weaponwant = self.switchweapon - 1;
220 if (weaponwant < WEP_FIRST)
221 weaponwant = WEP_LAST;
222 if (weaponwant > WEP_LAST)
223 weaponwant = WEP_FIRST;
224 while(!client_hasweapon(self, weaponwant, TRUE, FALSE))
230 weaponwant = weaponwant - 1;
231 if (weaponwant < WEP_FIRST)
232 weaponwant = WEP_LAST;
233 if (weaponwant > WEP_LAST)
234 weaponwant = WEP_FIRST;
236 self.cnt = self.weapon;
237 self.switchweapon = weaponwant;
240 // Bringed back weapon frame
241 void() W_WeaponFrame =
247 if (!self.weaponentity || self.health < 1)
248 return; // Dead player can't use weapons and injure impulse commands
250 if(!self.switchweapon)
253 self.weaponentity.state = WS_CLEAR;
257 makevectors(self.v_angle);
260 if (self.weapon != self.switchweapon)
262 if (self.weaponentity.state == WS_CLEAR)
264 self.weaponentity.state = WS_RAISE;
265 weapon_action(self.switchweapon, WR_SETUP);
266 // VorteX: add player model weapon select frame here
267 // setcustomframe(PlayerWeaponRaise);
268 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_ready);
269 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
271 else if (self.weaponentity.state == WS_READY)
273 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
274 self.weaponentity.state = WS_DROP;
275 // set up weapon switch think in the future, and start drop anim
276 weapon_thinkf(WFRAME_IDLE, cvar("g_balance_weaponswitchdelay"), w_clear);
277 weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);
281 // call the think code which may fire the weapon
282 // and do so multiple times to resolve framerate dependency issues if the
283 // server framerate is very low and the weapon fire rate very high
289 weapon_action(self.weapon, WR_THINK);
290 if (self.weapon_nextthink > 0 && time >= self.weapon_nextthink)
292 self.weapon_nextthink_lastframe = self.weapon_nextthink;
297 // don't let attack_finished fall behind when not firing
298 if (self.attack_finished < time)
299 self.attack_finished = time;
301 // update currentammo incase it has changed
302 if (self.items & IT_CELLS)
303 self.currentammo = self.ammo_cells;
304 else if (self.items & IT_ROCKETS)
305 self.currentammo = self.ammo_rockets;
306 else if (self.items & IT_NAILS)
307 self.currentammo = self.ammo_nails;
308 else if (self.items & IT_SHELLS)
309 self.currentammo = self.ammo_shells;
311 self.currentammo = 1;
316 float nixnex_nextchange;
317 float nixnex_nextweapon;
318 .float nixnex_lastchange_id;
319 .float nixnex_lastinfotime;
320 .float nixnex_nextincr;
322 void Nixnex_ChooseNextWeapon()
325 numberof = WEP_LAST - WEP_FIRST; // all but the current one
326 if(cvar("g_nixnex_with_laser"))
327 numberof = numberof - 1;
328 id = WEP_FIRST + ceil(random() * numberof) - 1;
330 if(cvar("g_nixnex_with_laser")) // skip the laser if needed
333 if(id >= nixnex_weapon) // skip the current weapon
336 if(id < WEP_FIRST) // can't happen, but to be sure...
338 dprint("Won't happen (id < WEP_FIRST)\n");
341 if(id > WEP_LAST) // either
343 dprint("Won't happen (id > WEP_LAST)\n");
347 nixnex_nextweapon = id;
350 string W_Name(float weaponid)
352 if(weaponid == WEP_LASER) return "Laser";
353 if(weaponid == WEP_UZI) return "Machine Gun";
354 if(weaponid == WEP_SHOTGUN) return "Shotgun";
355 if(weaponid == WEP_GRENADE_LAUNCHER) return "Mortar";
356 if(weaponid == WEP_ELECTRO) return "Electro";
357 if(weaponid == WEP_NEX) return "Nex";
358 if(weaponid == WEP_HAGAR) return "Hagar";
359 if(weaponid == WEP_ROCKET_LAUNCHER) return "Rocket Launcher";
360 if(weaponid == WEP_CRYLINK) return "Crylink";
361 return "@!#%'n Tuba";
364 void Nixnex_GiveCurrentWeapon()
369 if(!nixnex_nextweapon)
370 Nixnex_ChooseNextWeapon();
372 dt = ceil(nixnex_nextchange - time);
376 nixnex_weapon = nixnex_nextweapon;
377 nixnex_nextweapon = 0;
378 nixnex_nextchange = time + cvar("g_balance_nixnex_roundtime");
381 if(nixnex_nextchange != self.nixnex_lastchange_id) // this shall only be called once per round!
383 self.nixnex_lastchange_id = nixnex_nextchange;
384 if (cvar("g_use_ammunition"))
386 self.ammo_shells = cvar("g_balance_nixnex_ammo_shells");
387 self.ammo_nails = cvar("g_balance_nixnex_ammo_nails");
388 self.ammo_rockets = cvar("g_balance_nixnex_ammo_rockets");
389 self.ammo_cells = cvar("g_balance_nixnex_ammo_cells");
393 self.ammo_shells = 999;
394 self.ammo_nails = 999;
395 self.ammo_rockets = 999;
396 self.ammo_cells = 999;
398 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
399 if(dt >= 1 && dt <= 5)
400 self.nixnex_lastinfotime = -42;
403 centermsg_free(CENTERMSG_NIXNEXCOUNT);
404 centermsg_set(CENTERMSG_NIXNEX, strcat("^2Active weapon: ^3", W_Name(nixnex_weapon)));
407 if(self.nixnex_lastinfotime != dt)
409 self.nixnex_lastinfotime = dt; // initial value 0 should count as "not seen"
410 if(dt >= 1 && dt <= 5)
412 centermsg_set(CENTERMSG_NIXNEXCOUNT, strcat("^3", ftos(dt), "^2 seconds until weapon change..."));
413 centermsg_set(CENTERMSG_NIXNEX, strcat("Next weapon: ^3", W_Name(nixnex_nextweapon)));
417 if(cvar("g_use_ammunition") && time > self.nixnex_nextincr)
419 self.ammo_shells = self.ammo_shells + cvar("g_balance_nixnex_ammoincr_shells");
420 self.ammo_nails = self.ammo_nails + cvar("g_balance_nixnex_ammoincr_nails");
421 self.ammo_rockets = self.ammo_rockets + cvar("g_balance_nixnex_ammoincr_rockets");
422 self.ammo_cells = self.ammo_cells + cvar("g_balance_nixnex_ammoincr_cells");
423 self.nixnex_nextincr = time + cvar("g_balance_nixnex_incrtime");
426 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));
427 if(cvar("g_nixnex_with_laser"))
428 self.items = self.items + IT_LASER;
429 self.items = self.items - (self.items & weapon_translateindextoflag(nixnex_weapon)) + weapon_translateindextoflag(nixnex_weapon);
431 if(self.switchweapon != nixnex_weapon)
432 if(!client_hasweapon(self, self.switchweapon, TRUE, FALSE))
433 if(client_hasweapon(self, nixnex_weapon, TRUE, FALSE))
434 W_SwitchWeapon(nixnex_weapon);