2 REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", _("Electro"));
6 .float electro_secondarytime;
10 void W_Electro_SetAmmoCounter()
12 // set clip_load to the weapon we have switched to, if the gun uses reloading
13 if(!autocvar_g_balance_electro_reload_ammo)
14 self.clip_load = 0; // also keeps crosshair ammo from displaying
17 self.clip_load = self.electro_load;
18 self.clip_size = autocvar_g_balance_electro_reload_ammo; // for the crosshair ammo display
22 void W_Electro_ReloadedAndReady()
26 // now do the ammo transfer
27 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
28 while(self.clip_load < autocvar_g_balance_electro_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
33 self.electro_load = self.clip_load;
35 t = ATTACK_FINISHED(self) - autocvar_g_balance_electro_reload_time - 1;
36 ATTACK_FINISHED(self) = t;
40 void W_Electro_Reload()
42 // return if reloading is disabled for this weapon
43 if(!autocvar_g_balance_electro_reload_ammo)
46 if(!W_ReloadCheck(self.ammo_cells))
51 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
53 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_electro_reload_time + 1;
54 ATTACK_FINISHED(self) = t;
56 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_electro_reload_time, W_Electro_ReloadedAndReady);
58 self.old_clip_load = self.clip_load;
62 void W_Plasma_Explode_Combo (void);
64 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
67 e = WarpZone_FindRadius(org, rad, TRUE);
70 if (e.classname == "plasma")
72 // change owner to whoever caused the combo explosion
74 e.takedamage = DAMAGE_NO;
75 e.classname = "plasma_chain";
76 e.think = W_Plasma_Explode_Combo;
77 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
83 void W_Plasma_Explode (void)
85 if(other.takedamage == DAMAGE_AIM)
86 if(other.classname == "player")
87 if(IsDifferentTeam(self.owner, other))
88 if(other.deadflag == DEAD_NO)
90 AnnounceTo(self.owner, "electrobitch");
92 self.event_damage = SUB_Null;
93 self.takedamage = DAMAGE_NO;
94 if (self.movetype == MOVETYPE_BOUNCE)
96 RadiusDamage (self, self.owner, autocvar_g_balance_electro_secondary_damage, autocvar_g_balance_electro_secondary_edgedamage, autocvar_g_balance_electro_secondary_radius, world, autocvar_g_balance_electro_secondary_force, self.projectiledeathtype, other);
100 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
101 RadiusDamage (self, self.owner, autocvar_g_balance_electro_primary_damage, autocvar_g_balance_electro_primary_edgedamage, autocvar_g_balance_electro_primary_radius, world, autocvar_g_balance_electro_primary_force, self.projectiledeathtype, other);
107 void W_Plasma_Explode_Combo (void)
109 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
111 self.event_damage = SUB_Null;
112 RadiusDamage (self, self.owner, autocvar_g_balance_electro_combo_damage, autocvar_g_balance_electro_combo_edgedamage, autocvar_g_balance_electro_combo_radius, world, autocvar_g_balance_electro_combo_force, WEP_ELECTRO | HITTYPE_BOUNCE, world); // use THIS type for a combo because primary can't bounce
116 void W_Plasma_Touch (void)
118 //self.velocity = self.velocity * 0.1;
121 if (other.takedamage == DAMAGE_AIM) {
124 //UpdateCSQCProjectile(self);
125 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
126 self.projectiledeathtype |= HITTYPE_BOUNCE;
130 void W_Plasma_TouchExplode (void)
136 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
140 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
141 self.health = self.health - damage;
142 if (self.health <= 0)
144 self.takedamage = DAMAGE_NO;
145 self.nextthink = time;
146 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
148 // change owner to whoever caused the combo explosion
149 self.owner = inflictor.owner;
150 self.classname = "plasma_chain";
151 self.think = W_Plasma_Explode_Combo;
152 self.nextthink = time + min(autocvar_g_balance_electro_combo_radius, vlen(self.origin - inflictor.origin)) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
153 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
157 self.use = W_Plasma_Explode;
158 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
163 void W_Electro_Attack()
167 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
168 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
170 if(autocvar_g_balance_electro_reload_ammo)
172 self.clip_load -= autocvar_g_balance_electro_primary_ammo;
173 self.electro_load = self.clip_load;
176 self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
179 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
181 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
184 proj.classname = "plasma_prim";
186 proj.bot_dodge = TRUE;
187 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
188 proj.use = W_Plasma_Explode;
189 proj.think = adaptor_think2use_hittype_splash;
190 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
191 PROJECTILE_MAKETRIGGER(proj);
192 proj.projectiledeathtype = WEP_ELECTRO;
193 setorigin(proj, w_shotorg);
195 proj.movetype = MOVETYPE_FLY;
196 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
197 proj.angles = vectoangles(proj.velocity);
198 proj.touch = W_Plasma_TouchExplode;
199 setsize(proj, '0 0 -3', '0 0 -3');
200 proj.flags = FL_PROJECTILE;
202 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
205 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
207 other = proj; MUTATOR_CALLHOOK(EditProjectile);
210 void W_Electro_Attack2()
214 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
215 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
217 if(autocvar_g_balance_electro_reload_ammo)
219 self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
220 self.electro_load = self.clip_load;
223 self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
226 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
228 w_shotdir = v_forward; // no TrueAim for grenades please
230 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
233 proj.classname = "plasma";
235 proj.use = W_Plasma_Explode;
236 proj.think = adaptor_think2use_hittype_splash;
237 proj.bot_dodge = TRUE;
238 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
239 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
240 PROJECTILE_MAKETRIGGER(proj);
241 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
242 setorigin(proj, w_shotorg);
244 //proj.glow_size = 50;
245 //proj.glow_color = 45;
246 proj.movetype = MOVETYPE_BOUNCE;
247 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
248 proj.touch = W_Plasma_Touch;
249 setsize(proj, '0 0 -4', '0 0 -4');
250 proj.takedamage = DAMAGE_YES;
251 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
252 proj.health = autocvar_g_balance_electro_secondary_health;
253 proj.event_damage = W_Plasma_Damage;
254 proj.flags = FL_PROJECTILE;
256 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
257 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
262 copyentity(proj, p2);
263 setmodel(p2, "models/ebomb.mdl");
264 setsize(p2, proj.mins, proj.maxs);
267 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
269 other = proj; MUTATOR_CALLHOOK(EditProjectile);
272 .vector hook_start, hook_end;
273 float lgbeam_send(entity to, float sf)
275 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
277 if(sound_allowed(MSG_BROADCAST, self.owner))
279 WriteByte(MSG_ENTITY, sf);
282 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
283 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
287 WriteCoord(MSG_ENTITY, self.hook_start_x);
288 WriteCoord(MSG_ENTITY, self.hook_start_y);
289 WriteCoord(MSG_ENTITY, self.hook_start_z);
293 WriteCoord(MSG_ENTITY, self.hook_end_x);
294 WriteCoord(MSG_ENTITY, self.hook_end_y);
295 WriteCoord(MSG_ENTITY, self.hook_end_z);
301 float lgbeam_checkammo()
303 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
305 else if(autocvar_g_balance_electro_reload_ammo)
306 return self.owner.clip_load > 0;
308 return self.owner.ammo_cells > 0;
313 self.owner.prevlgfire = time;
314 if (self != self.owner.lgbeam)
320 if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
322 if(self == self.owner.lgbeam)
323 self.owner.lgbeam = world;
328 self.nextthink = time;
330 makevectors(self.owner.v_angle);
334 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
335 if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
337 if(autocvar_g_balance_electro_primary_ammo)
339 if(autocvar_g_balance_electro_reload_ammo)
341 dt = min(dt, self.owner.clip_load / autocvar_g_balance_electro_primary_ammo);
342 self.owner.clip_load = max(0, self.owner.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
343 self.owner.electro_load = self.owner.clip_load;
347 dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_electro_primary_ammo);
348 self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
353 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
354 WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
360 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
362 f = ExponentialFalloff(autocvar_g_balance_electro_primary_falloff_mindist, autocvar_g_balance_electro_primary_falloff_maxdist, autocvar_g_balance_electro_primary_falloff_halflifedist, vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
364 if(accuracy_isgooddamage(self.owner, trace_ent))
365 accuracy_add(self.owner, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
366 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
368 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, self.owner);
371 if(w_shotorg != self.hook_start)
374 self.hook_start = w_shotorg;
376 if(w_shotend != self.hook_end)
379 self.hook_end = w_shotend;
383 // experimental lightning gun
384 void W_Electro_Attack3 (void)
386 // only play fire sound if 0.5 sec has passed since player let go the fire button
387 if(time - self.prevlgfire > 0.5)
388 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
390 entity beam, oldself;
392 self.lgbeam = beam = spawn();
393 beam.classname = "lgbeam";
394 beam.solid = SOLID_NOT;
395 beam.think = lgbeam_think;
397 beam.movetype = MOVETYPE_NONE;
398 beam.shot_spread = 0;
399 beam.bot_dodge = TRUE;
400 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
401 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
411 weapon_action(WEP_ELECTRO, WR_PRECACHE);
412 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
413 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
414 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
415 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
418 void spawnfunc_weapon_electro (void)
420 weapon_defaultspawnfunc(WEP_ELECTRO);
423 void w_electro_checkattack()
425 if(self.electro_count > 1)
426 if(self.BUTTON_ATCK2)
427 if(weapon_prepareattack(1, -1))
430 self.electro_count -= 1;
431 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
438 .float bot_secondary_electromooth;
439 .float BUTTON_ATCK_prev;
440 float w_electro(float req)
444 self.BUTTON_ATCK=FALSE;
445 self.BUTTON_ATCK2=FALSE;
446 if(vlen(self.origin-self.enemy.origin) > 1000)
447 self.bot_secondary_electromooth = 0;
448 if(self.bot_secondary_electromooth == 0)
452 if(autocvar_g_balance_electro_primary_speed)
453 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
455 shoot = bot_aim(1000000, 0, 0.001, FALSE);
459 self.BUTTON_ATCK = TRUE;
460 if(random() < 0.01) self.bot_secondary_electromooth = 1;
465 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
467 self.BUTTON_ATCK2 = TRUE;
468 if(random() < 0.03) self.bot_secondary_electromooth = 0;
472 else if (req == WR_THINK)
474 if(autocvar_g_balance_electro_reload_ammo && self.clip_load < min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)) // forced reload
476 else if (self.BUTTON_ATCK)
478 if(autocvar_g_balance_electro_lightning)
479 if(self.BUTTON_ATCK_prev)
481 // prolong the animtime while the gun is being fired
482 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
483 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
485 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
487 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
489 if(autocvar_g_balance_electro_lightning)
491 if ((!self.lgbeam) || wasfreed(self.lgbeam))
495 if(!self.BUTTON_ATCK_prev)
497 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
498 self.BUTTON_ATCK_prev = 1;
504 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
508 if(autocvar_g_balance_electro_lightning)
510 if (self.BUTTON_ATCK_prev != 0)
512 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
513 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
515 self.BUTTON_ATCK_prev = 0;
518 if (self.BUTTON_ATCK2)
520 if (time >= self.electro_secondarytime)
521 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
524 self.electro_count = autocvar_g_balance_electro_secondary_count;
525 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
526 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
533 if(self.switchweapon == self.weapon)
535 if(self.weaponentity.state == WS_READY)
537 self.wish_reload = 0;
543 else if (req == WR_PRECACHE)
545 precache_model ("models/weapons/g_electro.md3");
546 precache_model ("models/weapons/v_electro.md3");
547 precache_model ("models/weapons/h_electro.iqm");
548 precache_sound ("weapons/electro_bounce.wav");
549 precache_sound ("weapons/electro_fire.wav");
550 precache_sound ("weapons/electro_fire2.wav");
551 precache_sound ("weapons/electro_impact.wav");
552 precache_sound ("weapons/electro_impact_combo.wav");
553 if(autocvar_g_balance_electro_lightning)
555 precache_sound ("weapons/lgbeam_fire.wav");
558 else if (req == WR_SETUP)
560 weapon_setup(WEP_ELECTRO);
561 W_Electro_SetAmmoCounter();
563 else if (req == WR_CHECKAMMO1)
565 if(autocvar_g_balance_electro_reload_ammo)
567 if(autocvar_g_balance_electro_lightning)
568 return !autocvar_g_balance_electro_primary_ammo || (self.electro_load > 0);
570 return self.electro_load >= autocvar_g_balance_electro_primary_ammo;
574 if(autocvar_g_balance_electro_lightning)
575 return !autocvar_g_balance_electro_primary_ammo || (self.ammo_cells > 0);
577 return self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
580 else if (req == WR_CHECKAMMO2)
582 if(autocvar_g_balance_electro_reload_ammo)
583 return self.electro_load >= autocvar_g_balance_electro_secondary_ammo;
585 return self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
587 else if (req == WR_RESETPLAYER)
589 self.electro_secondarytime = time;
591 else if (req == WR_RELOAD)
599 float w_electro(float req)
601 if(req == WR_IMPACTEFFECT)
604 org2 = w_org + w_backoff * 6;
605 if(w_deathtype & HITTYPE_SECONDARY)
607 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
609 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
613 if(w_deathtype & HITTYPE_BOUNCE)
615 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
616 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
618 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
622 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
624 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
628 else if(req == WR_PRECACHE)
630 precache_sound("weapons/electro_impact.wav");
631 precache_sound("weapons/electro_impact_combo.wav");
633 else if (req == WR_SUICIDEMESSAGE)
635 if(w_deathtype & HITTYPE_SECONDARY)
636 w_deathtypestring = "%s could not remember where they put plasma";
638 w_deathtypestring = "%s played with plasma";
640 else if (req == WR_KILLMESSAGE)
642 if(w_deathtype & HITTYPE_SECONDARY)
644 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
645 w_deathtypestring = "%s just noticed %s's blue ball";
646 else // unchecked: BOUNCE
647 w_deathtypestring = "%s got in touch with %s's blue ball";
651 if(w_deathtype & HITTYPE_BOUNCE) // combo
652 w_deathtypestring = "%s felt the electrifying air of %s's combo";
653 else if(w_deathtype & HITTYPE_SPLASH)
654 w_deathtypestring = "%s got too close to %s's blue beam";
656 w_deathtypestring = "%s was blasted by %s's blue beam";