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.velocity = e.velocity * 0.5 + v_forward * 750;
53 SUB_SetFade(wep, time + 20, 1);
79 else if(w == WEP_GRENADE_LAUNCHER)
81 w = IT_GRENADE_LAUNCHER;
87 weapon_grenadelauncher();
91 else if(w == WEP_ELECTRO)
103 else if(w == WEP_CRYLINK)
115 else if(w == WEP_NEX)
127 else if(w == WEP_HAGAR)
136 wep.ammo_rockets = 1;
139 else if(w == WEP_ROCKET_LAUNCHER)
141 w = IT_ROCKET_LAUNCHER;
147 weapon_rocketlauncher();
148 wep.ammo_rockets = 1;
153 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
154 wep.solid = SOLID_NOT;
155 setorigin(wep, wep.origin);
156 wep.nextthink = time + 0.25;
157 wep.think = thrown_wep_think;
158 wep.classname = "droppedweapon";
159 e.items = e.items - (e.items & w);
160 e.switchweapon = w_getbestweapon(e);
164 // switch between weapons
165 void(float imp) W_SwitchWeapon
167 weapon_hasammo = TRUE;
168 if (!client_hasweapon(self, imp, TRUE))
171 sprint(self, "You don't have any ammo for that weapon\n");
173 sprint(self, "You don't own that weapon\n");
176 self.switchweapon = imp;
180 void() W_NextWeapon =
182 local float weaponwant;
184 weaponwant = self.switchweapon + 1;
185 if (weaponwant < WEP_FIRST)
186 weaponwant = WEP_LAST;
187 if (weaponwant > WEP_LAST)
188 weaponwant = WEP_FIRST;
189 weapon_hasammo = TRUE;
190 while(!client_hasweapon(self, weaponwant, TRUE))
192 weaponwant = weaponwant + 1;
193 if (weaponwant < WEP_FIRST)
194 weaponwant = WEP_LAST;
195 if (weaponwant > WEP_LAST)
196 weaponwant = WEP_FIRST;
198 self.switchweapon = weaponwant;
202 void() W_PreviousWeapon =
204 local float weaponwant;
206 weaponwant = self.switchweapon - 1;
207 if (weaponwant < WEP_FIRST)
208 weaponwant = WEP_LAST;
209 if (weaponwant > WEP_LAST)
210 weaponwant = WEP_FIRST;
211 weapon_hasammo = TRUE;
212 while(!client_hasweapon(self, weaponwant, TRUE))
214 weaponwant = weaponwant - 1;
215 if (weaponwant < WEP_FIRST)
216 weaponwant = WEP_LAST;
217 if (weaponwant > WEP_LAST)
218 weaponwant = WEP_FIRST;
220 self.switchweapon = weaponwant;
223 // Bringed back weapon frame
224 void() W_WeaponFrame =
226 if (!self.weaponentity || self.health <= 0)
227 return; // Dead player can't use weapons and injure impulse commands
229 if (cvar("g_antilag"))
231 // if aiming at a player and the original trace won't hit that player
232 // anymore, try aiming at the player's new position
233 if (self.cursor_trace_ent)
235 if (self.cursor_trace_ent.takedamage)
237 traceline(self.origin + self.view_ofs, self.cursor_trace_endpos, FALSE, self);
238 if (trace_ent != self.cursor_trace_ent)
240 traceline(self.origin + self.view_ofs, self.cursor_trace_ent.origin + (self.cursor_trace_ent.mins + self.cursor_trace_ent.maxs) * 0.5, FALSE, self);
241 if (trace_ent == self.cursor_trace_ent)
242 self.cursor_trace_endpos = trace_endpos;
246 self.v_angle = vectoangles(self.cursor_trace_endpos - (self.origin + self.view_ofs));
247 self.v_angle_x = 0 - self.v_angle_x;
250 makevectors(self.v_angle);
253 if (self.weapon != self.switchweapon)
255 if (self.weaponentity.state == WS_CLEAR)
257 self.weaponentity.state = WS_RAISE;
258 weapon_action(self.switchweapon, WR_SETUP);
259 // VorteX: add player model weapon select frame here
260 // setcustomframe(PlayerWeaponRaise);
261 weapon_action(self.weapon, WR_UPDATECOUNTS);
262 weapon_action(self.weapon, WR_RAISE);
264 else if (self.weaponentity.state == WS_READY)
266 sound (self, CHAN_WEAPON, "weapons/weapon_switch.ogg", 1, ATTN_NORM);
267 self.weaponentity.state = WS_DROP;
268 // VorteX: add player model weapon deselect frame here
269 // setcustomframe(PlayerWeaponDrop);
270 weapon_action(self.weapon, WR_DROP);
275 weapon_action(self.weapon, WR_FIRE1);
277 weapon_action(self.weapon, WR_FIRE2);
280 if (time >= self.weapon_nextthink)
281 if (self.weapon_nextthink > 0)
284 // weapon bobbing and script actions
285 local float bobintensity, q1pitching, framespeed, diff;
286 local vector vel, realorg, layer1, boblayer;
288 bobintensity = cvar("g_viewweapon_bobintensity"); // weapon bob intensity
289 q1pitching = fabs(cvar("g_viewweapon_q1pitching")); // q1 style of "bob" when looking up and down
291 realorg = self.weaponentity.origin + self.weaponentity.view_ofs;
292 realorg = realorg - self.weaponentity.finaldest; // finaldest is last bob position
294 // VorteX: actually this is needed for weapon screen offset
297 self.weaponentity.view_ofs_x = q1pitching*bound(-5.5, self.v_angle_x/45, 5.5);
298 self.weaponentity.view_ofs_z = q1pitching*bound(-1.5, self.v_angle_x/60, 1.5);
301 // weapon origin interpolation, layer 1
302 if (realorg != self.weaponentity.pos1)
304 framespeed = frametime*self.weaponentity.lip*10; // lip is speed of origin changing (of layer1)
305 diff = vlen(realorg - self.weaponentity.pos1);
306 // VorteX: add speed modifier (haste)?
307 layer1 = frametime*10*self.weaponentity.lip*normalize(self.weaponentity.pos1 - realorg);
308 if (diff <= vlen(layer1))
309 layer1 = normalize(self.weaponentity.pos1 - realorg)*diff;
312 // weapon bobbing (q3-style)
313 if (self.flags & FL_ONGROUND && self.waterlevel < 2)
315 // VorteX: only xy velocity matters
316 vel_x = self.velocity_x;
317 vel_y = self.velocity_y;
318 framespeed = vlen(vel);
320 diff = bobintensity*framespeed/300;
321 self.weaponentity.destvec_y = self.weaponentity.destvec_y + frametime*10;
322 boblayer_y = diff*cos(self.weaponentity.destvec_y + 90);
324 diff = bobintensity*framespeed/540;
325 self.weaponentity.destvec_z = self.weaponentity.destvec_z + frametime*20;
326 boblayer_z = diff*cos(self.weaponentity.destvec_z);
327 self.weaponentity.finaldest = boblayer;
329 else if (self.waterlevel > 0)
330 {// swim, all velocity matters
332 framespeed = vlen(self.velocity);
333 diff = bobintensity*framespeed/100;
334 self.weaponentity.destvec_x = self.weaponentity.destvec_x + frametime*6;
335 boblayer_x = diff*cos(self.weaponentity.destvec_x);
336 self.weaponentity.finaldest = boblayer;
339 self.weaponentity.finaldest = '0 0 0';
340 self.weaponentity.origin = realorg + boblayer + layer1 - self.weaponentity.view_ofs;