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 // switch between weapons
26 void(float imp) W_SwitchWeapon
28 weapon_hasammo = TRUE;
29 if (!client_hasweapon(self, imp, TRUE))
32 sprint(self, "You don't have any ammo for that weapon\n");
34 sprint(self, "You don't own that weapon\n");
37 self.switchweapon = imp;
43 local float weaponwant;
45 weaponwant = self.switchweapon + 1;
46 if (weaponwant < WEP_FIRST)
47 weaponwant = WEP_LAST;
48 if (weaponwant > WEP_LAST)
49 weaponwant = WEP_FIRST;
50 weapon_hasammo = TRUE;
51 while(!client_hasweapon(self, weaponwant, TRUE))
53 weaponwant = weaponwant + 1;
54 if (weaponwant < WEP_FIRST)
55 weaponwant = WEP_LAST;
56 if (weaponwant > WEP_LAST)
57 weaponwant = WEP_FIRST;
59 self.switchweapon = weaponwant;
63 void() W_PreviousWeapon =
65 local float weaponwant;
67 weaponwant = self.switchweapon - 1;
68 if (weaponwant < WEP_FIRST)
69 weaponwant = WEP_LAST;
70 if (weaponwant > WEP_LAST)
71 weaponwant = WEP_FIRST;
72 weapon_hasammo = TRUE;
73 while(!client_hasweapon(self, weaponwant, TRUE))
75 weaponwant = weaponwant - 1;
76 if (weaponwant < WEP_FIRST)
77 weaponwant = WEP_LAST;
78 if (weaponwant > WEP_LAST)
79 weaponwant = WEP_FIRST;
81 self.switchweapon = weaponwant;
84 // Bringed back weapon frame
85 void() W_WeaponFrame =
87 if (!self.weaponentity || self.health <= 0)
88 return; // Dead player can't use weapons and injure impulse commands
90 if (cvar("g_antilag"))
92 // if aiming at a player and the original trace won't hit that player
93 // anymore, try aiming at the player's new position
94 if (self.cursor_trace_ent)
96 if (self.cursor_trace_ent.takedamage)
98 traceline(self.origin + self.view_ofs, self.cursor_trace_endpos, FALSE, self);
99 if (trace_ent != self.cursor_trace_ent)
101 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);
102 if (trace_ent == self.cursor_trace_ent)
103 self.cursor_trace_endpos = trace_endpos;
107 self.v_angle = vectoangles(self.cursor_trace_endpos - (self.origin + self.view_ofs));
108 self.v_angle_x = 0 - self.v_angle_x;
111 makevectors(self.v_angle);
114 if (self.weapon != self.switchweapon)
116 if (self.weaponentity.state == WS_CLEAR)
118 self.weaponentity.state = WS_RAISE;
119 weapon_action(self.switchweapon, WR_SETUP);
120 // VorteX: add player model weapon select frame here
121 // setcustomframe(PlayerWeaponRaise);
122 weapon_action(self.weapon, WR_UPDATECOUNTS);
123 weapon_action(self.weapon, WR_RAISE);
125 else if (self.weaponentity.state == WS_READY)
127 sound (self, CHAN_WEAPON, "weapons/weapon_switch.wav", 1, ATTN_NORM);
128 self.weaponentity.state = WS_DROP;
129 // VorteX: add player model weapon deselect frame here
130 // setcustomframe(PlayerWeaponDrop);
131 weapon_action(self.weapon, WR_DROP);
136 weapon_action(self.weapon, WR_FIRE1);
138 weapon_action(self.weapon, WR_FIRE2);
141 if (time >= self.weapon_nextthink)
142 if (self.weapon_nextthink > 0)
145 // weapon bobbing and script actions
146 local float bobintensity, q1pitching, framespeed, diff;
147 local vector vel, realorg, layer1, boblayer;
149 bobintensity = cvar("g_viewweapon_bobintensity"); // weapon bob intensity
150 q1pitching = fabs(cvar("g_viewweapon_q1pitching")); // q1 style of "bob" when looking up and down
152 realorg = self.weaponentity.origin + self.weaponentity.view_ofs;
153 realorg = realorg - self.weaponentity.finaldest; // finaldest is last bob position
155 // VorteX: actually this is needed for weapon screen offset
158 self.weaponentity.view_ofs_x = q1pitching*bound(-5.5, self.v_angle_x/45, 5.5);
159 self.weaponentity.view_ofs_z = q1pitching*bound(-1.5, self.v_angle_x/60, 1.5);
162 // weapon origin interpolation, layer 1
163 if (realorg != self.weaponentity.pos1)
165 framespeed = frametime*self.weaponentity.lip*10; // lip is speed of origin changing (of layer1)
166 diff = vlen(realorg - self.weaponentity.pos1);
167 // VorteX: add speed modifier (haste)?
168 layer1 = frametime*10*self.weaponentity.lip*normalize(self.weaponentity.pos1 - realorg);
169 if (diff <= vlen(layer1))
170 layer1 = normalize(self.weaponentity.pos1 - realorg)*diff;
173 // weapon bobbing (q3-style)
174 if (self.flags & FL_ONGROUND && self.waterlevel < 2)
176 // VorteX: only xy velocity matters
177 vel_x = self.velocity_x;
178 vel_y = self.velocity_y;
179 framespeed = vlen(vel);
181 diff = bobintensity*framespeed/300;
182 self.weaponentity.destvec_y = self.weaponentity.destvec_y + frametime*10;
183 boblayer_y = diff*cos(self.weaponentity.destvec_y + 90);
185 diff = bobintensity*framespeed/540;
186 self.weaponentity.destvec_z = self.weaponentity.destvec_z + frametime*20;
187 boblayer_z = diff*cos(self.weaponentity.destvec_z);
188 self.weaponentity.finaldest = boblayer;
190 else if (self.waterlevel > 0)
191 {// swim, all velocity matters
193 framespeed = vlen(self.velocity);
194 diff = bobintensity*framespeed/100;
195 self.weaponentity.destvec_x = self.weaponentity.destvec_x + frametime*6;
196 boblayer_x = diff*cos(self.weaponentity.destvec_x);
197 self.weaponentity.finaldest = boblayer;
200 self.weaponentity.finaldest = '0 0 0';
201 self.weaponentity.origin = realorg + boblayer + layer1 - self.weaponentity.view_ofs;