1 // generic weapons table
2 // add new weapons here
3 void(float wpn, float wrequest) weapon_action =
5 if (cvar("g_minstagib"))
14 else if (wpn == WEP_SHOTGUN)
16 else if (wpn == WEP_UZI)
18 else if (wpn == WEP_GRENADE_LAUNCHER)
19 w_glauncher(wrequest);
20 else if (wpn == WEP_ELECTRO)
22 else if (wpn == WEP_CRYLINK)
24 else if (wpn == WEP_NEX)
26 else if (wpn == WEP_HAGAR)
28 else if (wpn == WEP_ROCKET_LAUNCHER)
29 w_rlauncher(wrequest);
32 // think function for tossed weapons
33 void() thrown_wep_think =
35 self.solid = SOLID_TRIGGER;
36 SUB_SetFade(self, time + 20, 1);
37 setorigin(self, self.origin);
40 // toss current weapon
50 setorigin(wep, e.origin);
51 makevectors(e.angles);
52 wep.classname = "droppedweapon";
53 wep.velocity = e.velocity * 0.5 + v_forward * 750;
54 SUB_SetFade(wep, time + 20, 1);
80 else if(w == WEP_GRENADE_LAUNCHER)
82 w = IT_GRENADE_LAUNCHER;
88 weapon_grenadelauncher();
92 else if(w == WEP_ELECTRO)
104 else if(w == WEP_CRYLINK)
116 else if(w == WEP_NEX)
128 else if(w == WEP_HAGAR)
137 wep.ammo_rockets = 1;
140 else if(w == WEP_ROCKET_LAUNCHER)
142 w = IT_ROCKET_LAUNCHER;
148 weapon_rocketlauncher();
149 wep.ammo_rockets = 1;
154 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
155 wep.solid = SOLID_NOT;
156 setorigin(wep, wep.origin);
157 wep.nextthink = time + 0.25;
158 wep.think = thrown_wep_think;
159 wep.classname = "droppedweapon";
160 e.items = e.items - (e.items & w);
161 e.switchweapon = w_getbestweapon(e);
165 // switch between weapons
166 void(float imp) W_SwitchWeapon
168 weapon_hasammo = TRUE;
169 if (!client_hasweapon(self, imp, TRUE))
172 sprint(self, "You don't have any ammo for that weapon\n");
174 sprint(self, "You don't own that weapon\n");
177 self.switchweapon = imp;
181 void() W_NextWeapon =
183 local float weaponwant, maxtries;
187 weaponwant = self.switchweapon + 1;
188 if (weaponwant < WEP_FIRST)
189 weaponwant = WEP_LAST;
190 if (weaponwant > WEP_LAST)
191 weaponwant = WEP_FIRST;
192 weapon_hasammo = TRUE;
193 while(!client_hasweapon(self, weaponwant, TRUE))
199 weaponwant = weaponwant + 1;
200 if (weaponwant < WEP_FIRST)
201 weaponwant = WEP_LAST;
202 if (weaponwant > WEP_LAST)
203 weaponwant = WEP_FIRST;
205 self.switchweapon = weaponwant;
209 void() W_PreviousWeapon =
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 weapon_hasammo = TRUE;
221 while(!client_hasweapon(self, weaponwant, TRUE))
227 weaponwant = weaponwant - 1;
228 if (weaponwant < WEP_FIRST)
229 weaponwant = WEP_LAST;
230 if (weaponwant > WEP_LAST)
231 weaponwant = WEP_FIRST;
233 self.switchweapon = weaponwant;
236 // Bringed back weapon frame
237 void() W_WeaponFrame =
239 if (!self.weaponentity || self.health <= 0)
240 return; // Dead player can't use weapons and injure impulse commands
242 makevectors(self.v_angle);
245 if (self.weapon != self.switchweapon)
247 if (self.weaponentity.state == WS_CLEAR)
249 self.weaponentity.state = WS_RAISE;
250 weapon_action(self.switchweapon, WR_SETUP);
251 // VorteX: add player model weapon select frame here
252 // setcustomframe(PlayerWeaponRaise);
253 weapon_action(self.weapon, WR_UPDATECOUNTS);
254 weapon_action(self.weapon, WR_RAISE);
256 else if (self.weaponentity.state == WS_READY)
258 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
259 self.weaponentity.state = WS_DROP;
260 // VorteX: add player model weapon deselect frame here
261 // setcustomframe(PlayerWeaponDrop);
262 weapon_action(self.weapon, WR_DROP);
267 weapon_action(self.weapon, WR_FIRE1);
269 weapon_action(self.weapon, WR_FIRE2);
272 if (time >= self.weapon_nextthink)
273 if (self.weapon_nextthink > 0)
276 // weapon bobbing and script actions
277 local float bobintensity, q1pitching, framespeed, diff;
278 local vector vel, realorg, layer1, boblayer;
280 bobintensity = cvar("g_viewweapon_bobintensity"); // weapon bob intensity
281 q1pitching = fabs(cvar("g_viewweapon_q1pitching")); // q1 style of "bob" when looking up and down
283 realorg = self.weaponentity.origin + self.weaponentity.view_ofs;
284 realorg = realorg - self.weaponentity.finaldest; // finaldest is last bob position
286 // VorteX: actually this is needed for weapon screen offset
289 self.weaponentity.view_ofs_x = q1pitching*bound(-5.5, self.v_angle_x/45, 5.5);
290 self.weaponentity.view_ofs_z = q1pitching*bound(-1.5, self.v_angle_x/60, 1.5);
293 // weapon origin interpolation, layer 1
294 if (realorg != self.weaponentity.pos1)
296 framespeed = frametime*self.weaponentity.lip*10; // lip is speed of origin changing (of layer1)
297 diff = vlen(realorg - self.weaponentity.pos1);
298 // VorteX: add speed modifier (haste)?
299 layer1 = frametime*10*self.weaponentity.lip*normalize(self.weaponentity.pos1 - realorg);
300 if (diff <= vlen(layer1))
301 layer1 = normalize(self.weaponentity.pos1 - realorg)*diff;
304 // weapon bobbing (q3-style)
305 if (self.flags & FL_ONGROUND && self.waterlevel < 2)
307 // VorteX: only xy velocity matters
308 vel_x = self.velocity_x;
309 vel_y = self.velocity_y;
310 framespeed = vlen(vel);
312 diff = bobintensity*framespeed/300;
313 self.weaponentity.destvec_y = self.weaponentity.destvec_y + frametime*10;
314 boblayer_y = diff*cos(self.weaponentity.destvec_y + 90);
316 diff = bobintensity*framespeed/540;
317 self.weaponentity.destvec_z = self.weaponentity.destvec_z + frametime*20;
318 boblayer_z = diff*cos(self.weaponentity.destvec_z);
319 self.weaponentity.finaldest = boblayer;
321 else if (self.waterlevel > 0)
322 {// swim, all velocity matters
324 framespeed = vlen(self.velocity);
325 diff = bobintensity*framespeed/100;
326 self.weaponentity.destvec_x = self.weaponentity.destvec_x + frametime*6;
327 boblayer_x = diff*cos(self.weaponentity.destvec_x);
328 self.weaponentity.finaldest = boblayer;
331 self.weaponentity.finaldest = '0 0 0';
332 self.weaponentity.origin = realorg + boblayer + layer1 - self.weaponentity.view_ofs;