2 ===========================================================================
4 CLIENT WEAPONSYSTEM CODE
5 Bring back W_Weaponframe
7 ===========================================================================
10 vector() W_TrueAim = {
12 traceline_hitcorpse(self,self.origin + self.view_ofs,self.origin + self.view_ofs + v_forward * 4096,FALSE,self);
14 if ((self.weapon == WEP_NEX || self.weapon == WEP_SHOTGUN || self.weapon == WEP_UZI) && cvar("g_antilag"))
16 // if aiming at a player and the original trace won't hit that player
17 // anymore, try aiming at the player's new position
19 if(self.cursor_trace_ent)
20 if(self.cursor_trace_ent.takedamage)
21 if(trace_ent != self.cursor_trace_ent) {
22 return self.cursor_trace_ent.origin;
30 // this function allows you to spawn projectiles ahead of the player so they appear to come out of
31 // the muzzle properly, but won't put shots inside walls if you're too close.
32 // make sure you call makevectors first (FIXME?)
33 vector W_MuzzleOrigin (entity ent, vector vecs)
38 startorg = ent.origin + ent.view_ofs - '0 0 8';
39 idealorg = ent.origin + ent.view_ofs + v_forward * vecs_x + v_right * vecs_y + v_up * vecs_z;
41 traceline_hitcorpse (ent, startorg, idealorg, MOVE_NORMAL, ent);
43 // if obstructed, back off a bit so the shot will definitely hit it
44 if (trace_fraction < 1.0)
46 // FIXME! this whole thing messes up W_TrueAim... if you're up against a wall, the trueaim and the muzzle
47 // origin will be about the same distance from the player, causing the bullets to fly out at a near 90
49 // trace_endpos = trace_endpos - normalize (idealorg - startorg);
52 // nasty placeholder (well I admit you don't really notice it all... especially since the
53 // weapon model sinking into the wall provides such a nice distraction)
54 trace_endpos = startorg;
60 void LaserTarget_Think()
67 // list of weapons that will use the laser, and the options that enable it
68 if(self.owner.laser_on && self.owner.weapon == WEP_ROCKET_LAUNCHER && cvar("g_laserguided_missile"))
71 //if(self.owner.weapon == WEP_ELECTRO && cvar("g_laserguided_electro"))
76 // if a laser-enabled weapon isn't selected, delete any existing laser and quit
79 // rocket launcher isn't selected, so no laser target.
80 if(self.lasertarget != world)
82 remove(self.lasertarget);
83 self.lasertarget = world;
90 // we don't have a lasertarget entity, so spawn one
91 //bprint("create laser target\n");
92 e = self.lasertarget = spawn();
93 e.owner = self.owner; // Its owner is my owner
94 e.classname = "laser_target";
95 e.movetype = MOVETYPE_NOCLIP; // don't touch things
96 setmodel(e, "models/laser_dot.mdl"); // what it looks like
97 e.scale = 1.25; // make it larger
98 e.alpha = 0.25; // transparency
99 e.colormod = '255 0 0' * (1/255) * 8; // change colors
100 e.effects = EF_FULLBRIGHT;
101 // make it dynamically glow
102 // you should avoid over-using this, as it can slow down the player's computer.
103 e.glow_color = 251; // red color
107 e = self.lasertarget;
109 // move the laser dot to where the player is looking
111 makevectors(self.owner.v_angle); // set v_forward etc to the direction the player is looking
112 offset = '0 0 26' + v_right*3;
113 traceline(self.owner.origin + offset, self.owner.origin + offset + v_forward * 2048, FALSE, self); // trace forward until you hit something, like a player or wall
114 setorigin(e, trace_endpos + v_forward*8); // move me to where the traceline ended
115 if(trace_plane_normal != '0 0 0')
116 e.angles = vectoangles(trace_plane_normal);
118 e.angles = vectoangles(v_forward);
121 void() CL_Weaponentity_Think =
123 self.nextthink = time;
124 if (self.owner.weaponentity != self)
129 self.effects = self.owner.effects;
130 self.alpha = self.owner.alpha;
132 // create or update the lasertarget entity
136 void() CL_ExteriorWeaponentity_Think =
138 self.nextthink = time;
139 if(self.owner.deadflag != DEAD_NO)
144 if (self.owner.exteriorweaponentity != self)
149 if (self.cnt != self.owner.weaponentity.modelindex || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
151 self.cnt = self.owner.weaponentity.modelindex;
152 self.dmg = self.owner.modelindex;
153 self.deadflag = self.owner.deadflag;
154 if (self.owner.deadflag) return;
155 else if (self.owner.weapon == WEP_LASER) setmodel(self, "models/weapons/v_laser.md3");
156 else if (self.owner.weapon == WEP_SHOTGUN) setmodel(self, "models/weapons/v_shotgun.md3");
157 else if (self.owner.weapon == WEP_UZI) setmodel(self, "models/weapons/v_uzi.md3");
158 else if (self.owner.weapon == WEP_GRENADE_LAUNCHER) setmodel(self, "models/weapons/v_gl.md3");
159 else if (self.owner.weapon == WEP_ELECTRO) setmodel(self, "models/weapons/v_electro.md3");
160 else if (self.owner.weapon == WEP_CRYLINK) setmodel(self, "models/weapons/v_crylink.md3");
161 else if (self.owner.weapon == WEP_NEX) setmodel(self, "models/weapons/v_nex.md3");
162 else if (self.owner.weapon == WEP_HAGAR) setmodel(self, "models/weapons/v_hagar.md3");
163 else if (self.owner.weapon == WEP_ROCKET_LAUNCHER) setmodel(self, "models/weapons/v_rl.md3");
164 setattachment(self, self.owner, "bip01 r hand");
165 // if that didn't find a tag, hide the exterior weapon model
169 self.effects = self.owner.weaponentity.effects;
172 // spawning weaponentity for client
173 void() CL_SpawnWeaponentity =
175 if (self.weaponentity)
180 self.weaponentity = spawn();
181 self.weaponentity.solid = SOLID_NOT;
182 self.weaponentity.owner = self;
183 self.weaponentity.weaponentity = self.weaponentity;
184 setmodel(self.weaponentity, "");
185 self.weaponentity.origin = '0 0 0';
186 self.weaponentity.angles = '0 0 0';
187 self.weaponentity.viewmodelforclient = self;
188 self.weaponentity.flags = 0;
189 self.weaponentity.think = CL_Weaponentity_Think;
190 self.weaponentity.nextthink = time;
192 self.exteriorweaponentity = spawn();
193 self.exteriorweaponentity.solid = SOLID_NOT;
194 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
195 self.exteriorweaponentity.owner = self;
196 self.exteriorweaponentity.origin = '0 0 0';
197 self.exteriorweaponentity.angles = '0 0 0';
198 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
199 self.exteriorweaponentity.nextthink = time;
202 // convertion from index (= impulse) to flag in .items
203 float(float index) weapon_translateindextoflag =
205 if (index == WEP_LASER)
207 else if (index == WEP_SHOTGUN)
209 else if (index == WEP_UZI)
211 else if (index == WEP_GRENADE_LAUNCHER)
212 return IT_GRENADE_LAUNCHER;
213 else if (index == WEP_ELECTRO)
215 else if (index == WEP_CRYLINK)
217 else if (index == WEP_NEX)
219 else if (index == WEP_HAGAR)
221 else if (index == WEP_ROCKET_LAUNCHER)
222 return IT_ROCKET_LAUNCHER;
223 else if (index == WEP_LASER)
229 float(entity cl, float wpn, float andammo) client_hasweapon =
231 local float itemcode;
232 local entity oldself;
234 weapon_hasammo = TRUE;
235 if (wpn < WEP_FIRST || wpn > WEP_LAST)
237 itemcode = weapon_translateindextoflag(wpn);
238 if (cl.items & itemcode)
244 weapon_action(wpn, WR_CHECKAMMO);
258 weapon_action(self.weapon, WR_CLEAR);
259 if (self.weapon != -1)
261 if (self.weaponentity)
263 self.weaponentity.state = WS_CLEAR;
264 setmodel(self.weaponentity, "");
265 self.weaponentity.effects = 0;
271 self.weaponentity.state = WS_READY;
272 weapon_action(self.weapon, WR_IDLE);
275 // FIXME: add qw-style client-custom weaponrating (cl_weaponrating)?
276 float(entity e) w_getbestweapon
277 {// add new weapons here
278 if (client_hasweapon(e, WEP_ROCKET_LAUNCHER, TRUE))
279 return WEP_ROCKET_LAUNCHER;
280 else if (client_hasweapon(e, WEP_NEX, TRUE))
282 else if (client_hasweapon(e, WEP_HAGAR, TRUE))
284 else if (client_hasweapon(e, WEP_GRENADE_LAUNCHER, TRUE))
285 return WEP_GRENADE_LAUNCHER;
286 else if (client_hasweapon(e, WEP_ELECTRO, TRUE))
288 else if (client_hasweapon(e, WEP_CRYLINK, TRUE))
290 else if (client_hasweapon(e, WEP_UZI, TRUE))
292 else if (client_hasweapon(e, WEP_SHOTGUN, TRUE))
294 else if (client_hasweapon(e, WEP_LASER, FALSE))
300 // Setup weapon for client (after this raise frame will be launched)
301 void(float windex, string wmodel, float hudammo) weapon_setup =
303 local string weaponmdl;
305 self.items = self.items - (self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS));
306 self.items = self.items | hudammo;
308 self.weapon = windex;
312 weaponmdl = strzone(strcat("models/weapons/", wmodel));
313 setmodel(self.weaponentity, weaponmdl);
315 // VorteX: update visible weapon
316 // CL_ViswepUpdate();
319 // perform weapon to attack (weaponstate and attack_finished check is here)
320 void(float() checkfunc1, float() checkfunc2, void() firefunc, float atktime) weapon_prepareattack =
326 self.switchweapon = w_getbestweapon(self);
327 if (self.switchweapon != self.weapon)
328 self.cnt = self.weapon;
332 // Don't do shot if previos attack not finished
333 if (time < self.attack_finished)
335 // Can't do shot if changing weapon
336 if (self.weaponentity.state != WS_READY)
339 self.attack_finished = time + atktime;
343 // perform weapon attack
344 void(float() checkfunc1, float() checkfunc2, void() firefunc) weapon_doattack
350 self.switchweapon = w_getbestweapon(self);
351 if (self.switchweapon != self.weapon)
352 self.cnt = self.weapon;
356 self.weaponentity.state = WS_INUSE;
358 if (cvar("g_norecoil"))
359 self.punchangle = '0 0 0';
360 weapon_action(self.weapon, WR_UPDATECOUNTS); // update ammo now
363 void(float fr, float t, void() func) weapon_thinkf =
367 if (self.weaponentity != world)
368 self.weaponentity.frame = fr;
371 if(cvar("g_runematch"))
373 if(self.runes & RUNE_SPEED)
375 if(self.runes & CURSE_SLOW)
376 t = t * cvar("g_balance_rune_speed_combo_atkrate");
378 t = t * cvar("g_balance_rune_speed_atkrate");
380 else if(self.runes & CURSE_SLOW)
382 t = t * cvar("g_balance_curse_slow_atkrate");
386 // VorteX: haste can be added here
387 self.weapon_nextthink = time + t;
388 self.weapon_think = func;
391 void(float spd, vector org) weapon_boblayer1 =
393 // VorteX: haste can be added here
394 self.weaponentity.pos1 =org;
395 self.weaponentity.lip = spd;