1 // generic weapons table
2 // add new weapons here
3 void(float wpn, float wrequest) weapon_action =
7 else if (wpn == WEP_SHOTGUN)
9 else if (wpn == WEP_UZI)
11 else if (wpn == WEP_GRENADE_LAUNCHER)
12 w_glauncher(wrequest);
13 else if (wpn == WEP_ELECTRO)
15 else if (wpn == WEP_CRYLINK)
17 else if (wpn == WEP_NEX)
19 else if (wpn == WEP_HAGAR)
21 else if (wpn == WEP_ROCKET_LAUNCHER)
22 w_rlauncher(wrequest);
25 // think function for tossed weapons
26 void() thrown_wep_think =
28 self.solid = SOLID_TRIGGER;
29 SUB_SetFade(self, time + 20, 1);
30 setorigin(self, self.origin);
33 // toss current weapon
43 setorigin(wep, e.origin);
44 makevectors(e.angles);
45 wep.classname = "droppedweapon";
46 wep.velocity = e.velocity * 0.5 + v_forward * 750;
47 SUB_SetFade(wep, time + 20, 1);
73 else if(w == WEP_GRENADE_LAUNCHER)
75 w = IT_GRENADE_LAUNCHER;
81 weapon_grenadelauncher();
85 else if(w == WEP_ELECTRO)
97 else if(w == WEP_CRYLINK)
109 else if(w == WEP_NEX)
121 else if(w == WEP_HAGAR)
130 wep.ammo_rockets = 1;
133 else if(w == WEP_ROCKET_LAUNCHER)
135 w = IT_ROCKET_LAUNCHER;
141 weapon_rocketlauncher();
142 wep.ammo_rockets = 1;
147 sprint(e, strcat("You dropped the ^2", wep.netname, "\n"));
148 wep.solid = SOLID_NOT;
149 setorigin(wep, wep.origin);
150 wep.nextthink = time + 0.25;
151 wep.think = thrown_wep_think;
152 wep.classname = "droppedweapon";
153 e.items = e.items - (e.items & w);
154 e.switchweapon = w_getbestweapon(e);
155 if (e.switchweapon != e.weapon)
160 // switch between weapons
161 void(float imp) W_SwitchWeapon
163 weapon_hasammo = TRUE;
164 if (!client_hasweapon(self, imp, TRUE))
167 sprint(self, "You don't have any ammo for that weapon\n");
169 sprint(self, "You don't own that weapon\n");
173 self.cnt = self.weapon;
174 self.switchweapon = imp;
179 void() W_NextWeapon =
181 local float weaponwant, maxtries;
185 weaponwant = self.switchweapon + 1;
186 if (weaponwant < WEP_FIRST)
187 weaponwant = WEP_LAST;
188 if (weaponwant > WEP_LAST)
189 weaponwant = WEP_FIRST;
190 weapon_hasammo = TRUE;
191 while(!client_hasweapon(self, weaponwant, TRUE))
197 weaponwant = weaponwant + 1;
198 if (weaponwant < WEP_FIRST)
199 weaponwant = WEP_LAST;
200 if (weaponwant > WEP_LAST)
201 weaponwant = WEP_FIRST;
203 self.cnt = self.weapon;
204 self.switchweapon = weaponwant;
208 void() W_PreviousWeapon =
210 local float weaponwant, maxtries;
214 weaponwant = self.switchweapon - 1;
215 if (weaponwant < WEP_FIRST)
216 weaponwant = WEP_LAST;
217 if (weaponwant > WEP_LAST)
218 weaponwant = WEP_FIRST;
219 weapon_hasammo = TRUE;
220 while(!client_hasweapon(self, weaponwant, TRUE))
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;
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;