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)
130 if (self.flags & FL_FLY)
131 // owner is currently being teleported, so don't apply EF_NODRAW otherwise the viewmodel would "blink"
132 self.effects = self.owner.effects - (self.owner.effects & EF_NODRAW);
134 self.effects = self.owner.effects;
136 self.alpha = self.owner.alpha;
138 // create or update the lasertarget entity
142 void() CL_ExteriorWeaponentity_Think =
144 self.nextthink = time;
145 if(self.owner.deadflag != DEAD_NO)
150 if (self.owner.exteriorweaponentity != self)
155 if (self.cnt != self.owner.weaponentity.modelindex || self.dmg != self.owner.modelindex || self.deadflag != self.owner.deadflag)
157 self.cnt = self.owner.weaponentity.modelindex;
158 self.dmg = self.owner.modelindex;
159 self.deadflag = self.owner.deadflag;
160 if (self.owner.deadflag) return;
161 else if (self.owner.weapon == WEP_LASER) setmodel(self, "models/weapons/v_laser.md3");
162 else if (self.owner.weapon == WEP_SHOTGUN) setmodel(self, "models/weapons/v_shotgun.md3");
163 else if (self.owner.weapon == WEP_UZI) setmodel(self, "models/weapons/v_uzi.md3");
164 else if (self.owner.weapon == WEP_GRENADE_LAUNCHER) setmodel(self, "models/weapons/v_gl.md3");
165 else if (self.owner.weapon == WEP_ELECTRO) setmodel(self, "models/weapons/v_electro.md3");
166 else if (self.owner.weapon == WEP_CRYLINK) setmodel(self, "models/weapons/v_crylink.md3");
167 else if (self.owner.weapon == WEP_NEX) setmodel(self, "models/weapons/v_nex.md3");
168 else if (self.owner.weapon == WEP_HAGAR) setmodel(self, "models/weapons/v_hagar.md3");
169 else if (self.owner.weapon == WEP_ROCKET_LAUNCHER) setmodel(self, "models/weapons/v_rl.md3");
170 setattachment(self, self.owner, "bip01 r hand");
171 // if that didn't find a tag, hide the exterior weapon model
175 self.effects = self.owner.weaponentity.effects;
178 // spawning weaponentity for client
179 void() CL_SpawnWeaponentity =
181 if (self.weaponentity)
186 self.weaponentity = spawn();
187 self.weaponentity.solid = SOLID_NOT;
188 self.weaponentity.owner = self;
189 self.weaponentity.weaponentity = self.weaponentity;
190 setmodel(self.weaponentity, "");
191 self.weaponentity.origin = '0 0 0';
192 self.weaponentity.angles = '0 0 0';
193 self.weaponentity.viewmodelforclient = self;
194 self.weaponentity.flags = 0;
195 self.weaponentity.think = CL_Weaponentity_Think;
196 self.weaponentity.nextthink = time;
198 self.exteriorweaponentity = spawn();
199 self.exteriorweaponentity.solid = SOLID_NOT;
200 self.exteriorweaponentity.exteriorweaponentity = self.exteriorweaponentity;
201 self.exteriorweaponentity.owner = self;
202 self.exteriorweaponentity.origin = '0 0 0';
203 self.exteriorweaponentity.angles = '0 0 0';
204 self.exteriorweaponentity.think = CL_ExteriorWeaponentity_Think;
205 self.exteriorweaponentity.nextthink = time;
208 // convertion from index (= impulse) to flag in .items
209 float(float index) weapon_translateindextoflag =
211 if (index == WEP_LASER)
213 else if (index == WEP_SHOTGUN)
215 else if (index == WEP_UZI)
217 else if (index == WEP_GRENADE_LAUNCHER)
218 return IT_GRENADE_LAUNCHER;
219 else if (index == WEP_ELECTRO)
221 else if (index == WEP_CRYLINK)
223 else if (index == WEP_NEX)
225 else if (index == WEP_HAGAR)
227 else if (index == WEP_ROCKET_LAUNCHER)
228 return IT_ROCKET_LAUNCHER;
229 else if (index == WEP_LASER)
235 float(entity cl, float wpn, float andammo) client_hasweapon =
237 local float itemcode;
238 local entity oldself;
240 weapon_hasammo = TRUE;
241 if (wpn < WEP_FIRST || wpn > WEP_LAST)
243 itemcode = weapon_translateindextoflag(wpn);
244 if (cl.items & itemcode)
250 weapon_action(wpn, WR_CHECKAMMO);
264 weapon_action(self.weapon, WR_CLEAR);
265 if (self.weapon != -1)
267 if (self.weaponentity)
269 self.weaponentity.state = WS_CLEAR;
270 setmodel(self.weaponentity, "");
271 self.weaponentity.effects = 0;
277 self.weaponentity.state = WS_READY;
278 weapon_action(self.weapon, WR_IDLE);
281 // FIXME: add qw-style client-custom weaponrating (cl_weaponrating)?
282 float(entity e) w_getbestweapon
283 {// add new weapons here
284 if (client_hasweapon(e, WEP_ROCKET_LAUNCHER, TRUE))
285 return WEP_ROCKET_LAUNCHER;
286 else if (client_hasweapon(e, WEP_NEX, TRUE))
288 else if (client_hasweapon(e, WEP_HAGAR, TRUE))
290 else if (client_hasweapon(e, WEP_GRENADE_LAUNCHER, TRUE))
291 return WEP_GRENADE_LAUNCHER;
292 else if (client_hasweapon(e, WEP_ELECTRO, TRUE))
294 else if (client_hasweapon(e, WEP_CRYLINK, TRUE))
296 else if (client_hasweapon(e, WEP_UZI, TRUE))
298 else if (client_hasweapon(e, WEP_SHOTGUN, TRUE))
300 else if (client_hasweapon(e, WEP_LASER, FALSE))
306 // Setup weapon for client (after this raise frame will be launched)
307 void(float windex, string wmodel, float hudammo) weapon_setup =
309 local string weaponmdl;
311 self.items = self.items - (self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS));
312 self.items = self.items | hudammo;
314 self.weapon = windex;
318 weaponmdl = strzone(strcat("models/weapons/", wmodel));
319 setmodel(self.weaponentity, weaponmdl);
321 // VorteX: update visible weapon
322 // CL_ViswepUpdate();
325 // perform weapon to attack (weaponstate and attack_finished check is here)
326 void(float() checkfunc1, float() checkfunc2, void() firefunc, float atktime) weapon_prepareattack =
332 self.switchweapon = w_getbestweapon(self);
333 if (self.switchweapon != self.weapon)
334 self.cnt = self.weapon;
338 // Don't do shot if previos attack not finished
339 if (time < self.attack_finished)
341 // Can't do shot if changing weapon
342 if (self.weaponentity.state != WS_READY)
345 self.attack_finished = time + atktime;
349 // perform weapon attack
350 void(float() checkfunc1, float() checkfunc2, void() firefunc) weapon_doattack
356 self.switchweapon = w_getbestweapon(self);
357 if (self.switchweapon != self.weapon)
358 self.cnt = self.weapon;
362 self.weaponentity.state = WS_INUSE;
364 if (cvar("g_norecoil"))
365 self.punchangle = '0 0 0';
366 weapon_action(self.weapon, WR_UPDATECOUNTS); // update ammo now
369 void(float fr, float t, void() func) weapon_thinkf =
373 if (self.weaponentity != world)
374 self.weaponentity.frame = fr;
377 if(cvar("g_runematch"))
379 if(self.runes & RUNE_SPEED)
381 if(self.runes & CURSE_SLOW)
382 t = t * cvar("g_balance_rune_speed_combo_atkrate");
384 t = t * cvar("g_balance_rune_speed_atkrate");
386 else if(self.runes & CURSE_SLOW)
388 t = t * cvar("g_balance_curse_slow_atkrate");
392 // VorteX: haste can be added here
393 self.weapon_nextthink = time + t;
394 self.weapon_think = func;
397 void(float spd, vector org) weapon_boblayer1 =
399 // VorteX: haste can be added here
400 self.weaponentity.pos1 =org;
401 self.weaponentity.lip = spd;