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;
8 void W_Electro_SetAmmoCounter()
10 // set clip_load to the weapon we have switched to, if the gun uses reloading
11 if(!autocvar_g_balance_electro_reload_ammo)
12 self.clip_load = 0; // also keeps crosshair ammo from displaying
15 self.clip_load = self.electro_load;
16 self.clip_size = autocvar_g_balance_electro_reload_ammo; // for the crosshair ammo display
20 void W_Electro_ReloadedAndReady()
24 // now do the ammo transfer
25 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
26 while(self.clip_load < autocvar_g_balance_electro_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
31 self.electro_load = self.clip_load;
33 t = ATTACK_FINISHED(self) - autocvar_g_balance_electro_reload_time - 1;
34 ATTACK_FINISHED(self) = t;
38 void W_Electro_Reload()
40 // return if reloading is disabled for this weapon
41 if(!autocvar_g_balance_electro_reload_ammo)
44 if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)))
49 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
51 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_electro_reload_time + 1;
52 ATTACK_FINISHED(self) = t;
54 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_electro_reload_time, W_Electro_ReloadedAndReady);
56 self.old_clip_load = self.clip_load;
60 void W_Plasma_Explode_Combo (void);
62 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
65 e = WarpZone_FindRadius(org, rad, TRUE);
68 if (e.classname == "plasma")
70 // change owner to whoever caused the combo explosion
72 e.takedamage = DAMAGE_NO;
73 e.classname = "plasma_chain";
74 e.think = W_Plasma_Explode_Combo;
75 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
81 void W_Plasma_Explode (void)
83 if(other.takedamage == DAMAGE_AIM)
84 if(other.classname == "player")
85 if(IsDifferentTeam(self.owner, other))
86 if(other.deadflag == DEAD_NO)
88 AnnounceTo(self.owner, "electrobitch");
90 self.event_damage = SUB_Null;
91 self.takedamage = DAMAGE_NO;
92 if (self.movetype == MOVETYPE_BOUNCE)
94 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);
98 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
99 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);
105 void W_Plasma_Explode_Combo (void)
107 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
109 self.event_damage = SUB_Null;
110 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
114 void W_Plasma_Touch (void)
116 //self.velocity = self.velocity * 0.1;
119 if (other.takedamage == DAMAGE_AIM) {
122 //UpdateCSQCProjectile(self);
123 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
124 self.projectiledeathtype |= HITTYPE_BOUNCE;
128 void W_Plasma_TouchExplode (void)
134 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
138 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
139 self.health = self.health - damage;
140 if (self.health <= 0)
142 self.takedamage = DAMAGE_NO;
143 self.nextthink = time;
144 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
146 // change owner to whoever caused the combo explosion
147 self.owner = inflictor.owner;
148 self.classname = "plasma_chain";
149 self.think = W_Plasma_Explode_Combo;
150 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
151 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
155 self.use = W_Plasma_Explode;
156 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
161 void W_Electro_Attack()
165 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
166 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
168 if(autocvar_g_balance_electro_reload_ammo)
170 self.clip_load -= autocvar_g_balance_electro_primary_ammo;
171 self.electro_load = self.clip_load;
174 self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
177 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
179 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
182 proj.classname = "plasma_prim";
184 proj.bot_dodge = TRUE;
185 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
186 proj.use = W_Plasma_Explode;
187 proj.think = adaptor_think2use_hittype_splash;
188 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
189 PROJECTILE_MAKETRIGGER(proj);
190 proj.projectiledeathtype = WEP_ELECTRO;
191 setorigin(proj, w_shotorg);
193 proj.movetype = MOVETYPE_FLY;
194 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
195 proj.angles = vectoangles(proj.velocity);
196 proj.touch = W_Plasma_TouchExplode;
197 setsize(proj, '0 0 -3', '0 0 -3');
198 proj.flags = FL_PROJECTILE;
200 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
203 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
205 other = proj; MUTATOR_CALLHOOK(EditProjectile);
208 void W_Electro_Attack2()
212 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
213 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
215 if(autocvar_g_balance_electro_reload_ammo)
217 self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
218 self.electro_load = self.clip_load;
221 self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
224 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
226 w_shotdir = v_forward; // no TrueAim for grenades please
228 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
231 proj.classname = "plasma";
233 proj.use = W_Plasma_Explode;
234 proj.think = adaptor_think2use_hittype_splash;
235 proj.bot_dodge = TRUE;
236 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
237 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
238 PROJECTILE_MAKETRIGGER(proj);
239 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
240 setorigin(proj, w_shotorg);
242 //proj.glow_size = 50;
243 //proj.glow_color = 45;
244 proj.movetype = MOVETYPE_BOUNCE;
245 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
246 proj.touch = W_Plasma_Touch;
247 setsize(proj, '0 0 -4', '0 0 -4');
248 proj.takedamage = DAMAGE_YES;
249 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
250 proj.health = autocvar_g_balance_electro_secondary_health;
251 proj.event_damage = W_Plasma_Damage;
252 proj.flags = FL_PROJECTILE;
254 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
255 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
260 copyentity(proj, p2);
261 setmodel(p2, "models/ebomb.mdl");
262 setsize(p2, proj.mins, proj.maxs);
265 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
267 other = proj; MUTATOR_CALLHOOK(EditProjectile);
270 .vector hook_start, hook_end;
271 float lgbeam_send(entity to, float sf)
273 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
275 if(sound_allowed(MSG_BROADCAST, self.owner))
277 WriteByte(MSG_ENTITY, sf);
280 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
281 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
285 WriteCoord(MSG_ENTITY, self.hook_start_x);
286 WriteCoord(MSG_ENTITY, self.hook_start_y);
287 WriteCoord(MSG_ENTITY, self.hook_start_z);
291 WriteCoord(MSG_ENTITY, self.hook_end_x);
292 WriteCoord(MSG_ENTITY, self.hook_end_y);
293 WriteCoord(MSG_ENTITY, self.hook_end_z);
299 float lgbeam_checkammo()
301 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
303 else if(autocvar_g_balance_electro_reload_ammo)
304 return self.owner.clip_load > 0;
306 return self.owner.ammo_cells > 0;
311 self.owner.prevlgfire = time;
312 if (self != self.owner.lgbeam)
318 if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
320 if(self == self.owner.lgbeam)
321 self.owner.lgbeam = world;
326 self.nextthink = time;
328 makevectors(self.owner.v_angle);
332 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
333 if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
335 if(autocvar_g_balance_electro_primary_ammo)
337 if(autocvar_g_balance_electro_reload_ammo)
339 dt = min(dt, self.owner.clip_load / autocvar_g_balance_electro_primary_ammo);
340 self.owner.clip_load = max(0, self.owner.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
341 self.owner.electro_load = self.owner.clip_load;
345 dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_electro_primary_ammo);
346 self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
351 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
352 WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
358 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
360 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));
362 if(accuracy_isgooddamage(self.owner, trace_ent))
363 accuracy_add(self.owner, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
364 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
366 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, self.owner);
369 if(w_shotorg != self.hook_start)
372 self.hook_start = w_shotorg;
374 if(w_shotend != self.hook_end)
377 self.hook_end = w_shotend;
381 // experimental lightning gun
382 void W_Electro_Attack3 (void)
384 // only play fire sound if 0.5 sec has passed since player let go the fire button
385 if(time - self.prevlgfire > 0.5)
386 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
388 entity beam, oldself;
390 self.lgbeam = beam = spawn();
391 beam.classname = "lgbeam";
392 beam.solid = SOLID_NOT;
393 beam.think = lgbeam_think;
395 beam.movetype = MOVETYPE_NONE;
396 beam.shot_spread = 0;
397 beam.bot_dodge = TRUE;
398 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
399 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
409 weapon_action(WEP_ELECTRO, WR_PRECACHE);
410 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
411 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
412 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
413 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
416 void spawnfunc_weapon_electro (void)
418 weapon_defaultspawnfunc(WEP_ELECTRO);
421 void w_electro_checkattack()
423 if(self.electro_count > 1)
424 if(self.BUTTON_ATCK2)
425 if(weapon_prepareattack(1, -1))
428 self.electro_count -= 1;
429 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
436 .float bot_secondary_electromooth;
437 .float BUTTON_ATCK_prev;
438 float w_electro(float req)
442 self.BUTTON_ATCK=FALSE;
443 self.BUTTON_ATCK2=FALSE;
444 if(vlen(self.origin-self.enemy.origin) > 1000)
445 self.bot_secondary_electromooth = 0;
446 if(self.bot_secondary_electromooth == 0)
450 if(autocvar_g_balance_electro_primary_speed)
451 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
453 shoot = bot_aim(1000000, 0, 0.001, FALSE);
457 self.BUTTON_ATCK = TRUE;
458 if(random() < 0.01) self.bot_secondary_electromooth = 1;
463 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
465 self.BUTTON_ATCK2 = TRUE;
466 if(random() < 0.03) self.bot_secondary_electromooth = 0;
470 else if (req == WR_THINK)
472 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
474 else if (self.BUTTON_ATCK)
476 if(autocvar_g_balance_electro_lightning)
477 if(self.BUTTON_ATCK_prev)
479 // prolong the animtime while the gun is being fired
480 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
481 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
483 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
485 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
487 if(autocvar_g_balance_electro_lightning)
489 if ((!self.lgbeam) || wasfreed(self.lgbeam))
493 if(!self.BUTTON_ATCK_prev)
495 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
496 self.BUTTON_ATCK_prev = 1;
502 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
506 if(autocvar_g_balance_electro_lightning)
508 if (self.BUTTON_ATCK_prev != 0)
510 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
511 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
513 self.BUTTON_ATCK_prev = 0;
516 if (self.BUTTON_ATCK2)
518 if (time >= self.electro_secondarytime)
519 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
522 self.electro_count = autocvar_g_balance_electro_secondary_count;
523 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
524 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
529 else if (req == WR_PRECACHE)
531 precache_model ("models/weapons/g_electro.md3");
532 precache_model ("models/weapons/v_electro.md3");
533 precache_model ("models/weapons/h_electro.iqm");
534 precache_sound ("weapons/electro_bounce.wav");
535 precache_sound ("weapons/electro_fire.wav");
536 precache_sound ("weapons/electro_fire2.wav");
537 precache_sound ("weapons/electro_impact.wav");
538 precache_sound ("weapons/electro_impact_combo.wav");
539 precache_sound ("weapons/reload.wav");
540 if(autocvar_g_balance_electro_lightning)
542 precache_sound ("weapons/lgbeam_fire.wav");
545 else if (req == WR_SETUP)
547 weapon_setup(WEP_ELECTRO);
548 W_Electro_SetAmmoCounter();
550 else if (req == WR_CHECKAMMO1)
552 if(autocvar_g_balance_electro_reload_ammo)
554 if(autocvar_g_balance_electro_lightning)
555 return !autocvar_g_balance_electro_primary_ammo || (self.electro_load > 0);
557 return self.electro_load >= autocvar_g_balance_electro_primary_ammo;
561 if(autocvar_g_balance_electro_lightning)
562 return !autocvar_g_balance_electro_primary_ammo || (self.ammo_cells > 0);
564 return self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
567 else if (req == WR_CHECKAMMO2)
569 if(autocvar_g_balance_electro_reload_ammo)
570 return self.electro_load >= autocvar_g_balance_electro_secondary_ammo;
572 return self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
574 else if (req == WR_RESETPLAYER)
576 self.electro_secondarytime = time;
578 else if (req == WR_RELOAD)
582 else if (req == WR_SWITCHABLE)
584 // checks if this weapon can be switched to, when reloading is enabled
585 // returns true if there's either enough load in the weapon to use it,
586 // or we have enough ammo to reload the weapon to a usable point
588 ammo_amount = min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo);
589 return self.electro_load >= ammo_amount || self.ammo_cells >= ammo_amount;
595 float w_electro(float req)
597 if(req == WR_IMPACTEFFECT)
600 org2 = w_org + w_backoff * 6;
601 if(w_deathtype & HITTYPE_SECONDARY)
603 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
605 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
609 if(w_deathtype & HITTYPE_BOUNCE)
611 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
612 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
614 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
618 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
620 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
624 else if(req == WR_PRECACHE)
626 precache_sound("weapons/electro_impact.wav");
627 precache_sound("weapons/electro_impact_combo.wav");
629 else if (req == WR_SUICIDEMESSAGE)
631 if(w_deathtype & HITTYPE_SECONDARY)
632 w_deathtypestring = "%s could not remember where they put plasma";
634 w_deathtypestring = "%s played with plasma";
636 else if (req == WR_KILLMESSAGE)
638 if(w_deathtype & HITTYPE_SECONDARY)
640 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
641 w_deathtypestring = "%s just noticed %s's blue ball";
642 else // unchecked: BOUNCE
643 w_deathtypestring = "%s got in touch with %s's blue ball";
647 if(w_deathtype & HITTYPE_BOUNCE) // combo
648 w_deathtypestring = "%s felt the electrifying air of %s's combo";
649 else if(w_deathtype & HITTYPE_SPLASH)
650 w_deathtypestring = "%s got too close to %s's blue beam";
652 w_deathtypestring = "%s was blasted by %s's blue beam";