2 REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", _("Electro"));
6 .float electro_secondarytime;
8 void W_Electro_Reload()
10 W_Reload(ammo_cells, min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo), autocvar_g_balance_electro_reload_ammo, autocvar_g_balance_electro_reload_time, "weapons/reload.wav");
13 void W_Plasma_Explode_Combo (void);
15 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
18 e = WarpZone_FindRadius(org, rad, TRUE);
21 if (e.classname == "plasma")
23 // change owner to whoever caused the combo explosion
25 e.takedamage = DAMAGE_NO;
26 e.classname = "plasma_chain";
27 e.think = W_Plasma_Explode_Combo;
28 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
34 void W_Plasma_Explode (void)
36 if(other.takedamage == DAMAGE_AIM)
37 if(other.classname == "player")
38 if(IsDifferentTeam(self.owner, other))
39 if(other.deadflag == DEAD_NO)
41 AnnounceTo(self.owner, "electrobitch");
43 self.event_damage = SUB_Null;
44 self.takedamage = DAMAGE_NO;
45 if (self.movetype == MOVETYPE_BOUNCE)
47 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);
51 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
52 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);
58 void W_Plasma_Explode_Combo (void)
60 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
62 self.event_damage = SUB_Null;
63 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
67 void W_Plasma_Touch (void)
69 //self.velocity = self.velocity * 0.1;
72 if (other.takedamage == DAMAGE_AIM) {
75 //UpdateCSQCProjectile(self);
76 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
77 self.projectiledeathtype |= HITTYPE_BOUNCE;
81 void W_Plasma_TouchExplode (void)
87 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
91 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
92 self.health = self.health - damage;
95 self.takedamage = DAMAGE_NO;
96 self.nextthink = time;
97 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
99 // change owner to whoever caused the combo explosion
100 self.owner = inflictor.owner;
101 self.classname = "plasma_chain";
102 self.think = W_Plasma_Explode_Combo;
103 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
104 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
108 self.use = W_Plasma_Explode;
109 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
114 void W_Electro_Attack()
118 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
119 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
121 if(autocvar_g_balance_electro_reload_ammo)
123 self.clip_load -= autocvar_g_balance_electro_primary_ammo;
124 self.weapon_load[WEP_ELECTRO] = self.clip_load;
127 self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
130 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
132 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
135 proj.classname = "plasma_prim";
137 proj.bot_dodge = TRUE;
138 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
139 proj.use = W_Plasma_Explode;
140 proj.think = adaptor_think2use_hittype_splash;
141 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
142 PROJECTILE_MAKETRIGGER(proj);
143 proj.projectiledeathtype = WEP_ELECTRO;
144 setorigin(proj, w_shotorg);
146 proj.movetype = MOVETYPE_FLY;
147 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
148 proj.angles = vectoangles(proj.velocity);
149 proj.touch = W_Plasma_TouchExplode;
150 setsize(proj, '0 0 -3', '0 0 -3');
151 proj.flags = FL_PROJECTILE;
153 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
156 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
158 other = proj; MUTATOR_CALLHOOK(EditProjectile);
161 void W_Electro_Attack2()
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_secondary_ammo;
171 self.weapon_load[WEP_ELECTRO] = self.clip_load;
174 self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
177 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
179 w_shotdir = v_forward; // no TrueAim for grenades please
181 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
184 proj.classname = "plasma";
186 proj.use = W_Plasma_Explode;
187 proj.think = adaptor_think2use_hittype_splash;
188 proj.bot_dodge = TRUE;
189 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
190 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
191 PROJECTILE_MAKETRIGGER(proj);
192 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
193 setorigin(proj, w_shotorg);
195 //proj.glow_size = 50;
196 //proj.glow_color = 45;
197 proj.movetype = MOVETYPE_BOUNCE;
198 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
199 proj.touch = W_Plasma_Touch;
200 setsize(proj, '0 0 -4', '0 0 -4');
201 proj.takedamage = DAMAGE_YES;
202 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
203 proj.health = autocvar_g_balance_electro_secondary_health;
204 proj.event_damage = W_Plasma_Damage;
205 proj.flags = FL_PROJECTILE;
207 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
208 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
213 copyentity(proj, p2);
214 setmodel(p2, "models/ebomb.mdl");
215 setsize(p2, proj.mins, proj.maxs);
218 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
220 other = proj; MUTATOR_CALLHOOK(EditProjectile);
223 .vector hook_start, hook_end;
224 float lgbeam_send(entity to, float sf)
226 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
228 if(sound_allowed(MSG_BROADCAST, self.owner))
230 WriteByte(MSG_ENTITY, sf);
233 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
234 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
238 WriteCoord(MSG_ENTITY, self.hook_start_x);
239 WriteCoord(MSG_ENTITY, self.hook_start_y);
240 WriteCoord(MSG_ENTITY, self.hook_start_z);
244 WriteCoord(MSG_ENTITY, self.hook_end_x);
245 WriteCoord(MSG_ENTITY, self.hook_end_y);
246 WriteCoord(MSG_ENTITY, self.hook_end_z);
252 float lgbeam_checkammo()
254 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
256 else if(autocvar_g_balance_electro_reload_ammo)
257 return self.owner.clip_load > 0;
259 return self.owner.ammo_cells > 0;
265 owner_player = self.owner;
267 owner_player.prevlgfire = time;
268 if (self != owner_player.lgbeam)
274 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
276 if(self == owner_player.lgbeam)
277 owner_player.lgbeam = world;
282 self.nextthink = time;
284 makevectors(owner_player.v_angle);
289 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
290 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
292 if(autocvar_g_balance_electro_primary_ammo)
294 if(autocvar_g_balance_electro_reload_ammo)
296 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
297 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
298 owner_player.weapon_load[WEP_ELECTRO] = owner_player.clip_load;
302 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
303 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
308 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
309 WarpZone_traceline_antilag(owner_player, w_shotorg, w_shotend, MOVE_NORMAL, owner_player, ANTILAG_LATENCY(owner_player));
315 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
317 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));
319 if(accuracy_isgooddamage(owner_player, trace_ent))
320 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
321 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
323 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
326 if(w_shotorg != self.hook_start)
329 self.hook_start = w_shotorg;
331 if(w_shotend != self.hook_end)
334 self.hook_end = w_shotend;
338 // experimental lightning gun
339 void W_Electro_Attack3 (void)
341 // only play fire sound if 0.5 sec has passed since player let go the fire button
342 if(time - self.prevlgfire > 0.5)
343 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
345 entity beam, oldself;
347 self.lgbeam = beam = spawn();
348 beam.classname = "lgbeam";
349 beam.solid = SOLID_NOT;
350 beam.think = lgbeam_think;
352 beam.movetype = MOVETYPE_NONE;
353 beam.shot_spread = 0;
354 beam.bot_dodge = TRUE;
355 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
356 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
366 weapon_action(WEP_ELECTRO, WR_PRECACHE);
367 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
368 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
369 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
370 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
373 void spawnfunc_weapon_electro (void)
375 weapon_defaultspawnfunc(WEP_ELECTRO);
378 void w_electro_checkattack()
380 if(self.electro_count > 1)
381 if(self.BUTTON_ATCK2)
382 if(weapon_prepareattack(1, -1))
385 self.electro_count -= 1;
386 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
393 .float bot_secondary_electromooth;
394 .float BUTTON_ATCK_prev;
395 float w_electro(float req)
400 self.BUTTON_ATCK=FALSE;
401 self.BUTTON_ATCK2=FALSE;
402 if(vlen(self.origin-self.enemy.origin) > 1000)
403 self.bot_secondary_electromooth = 0;
404 if(self.bot_secondary_electromooth == 0)
408 if(autocvar_g_balance_electro_primary_speed)
409 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
411 shoot = bot_aim(1000000, 0, 0.001, FALSE);
415 self.BUTTON_ATCK = TRUE;
416 if(random() < 0.01) self.bot_secondary_electromooth = 1;
421 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
423 self.BUTTON_ATCK2 = TRUE;
424 if(random() < 0.03) self.bot_secondary_electromooth = 0;
428 else if (req == WR_THINK)
430 if(autocvar_g_balance_electro_reload_ammo) // forced reload
432 if(autocvar_g_balance_electro_lightning)
434 if(self.clip_load > 0)
437 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
439 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
448 if (self.BUTTON_ATCK)
450 if(autocvar_g_balance_electro_lightning)
451 if(self.BUTTON_ATCK_prev)
453 // prolong the animtime while the gun is being fired
454 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
455 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
457 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
459 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
461 if(autocvar_g_balance_electro_lightning)
463 if ((!self.lgbeam) || wasfreed(self.lgbeam))
467 if(!self.BUTTON_ATCK_prev)
469 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
470 self.BUTTON_ATCK_prev = 1;
476 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
480 if(autocvar_g_balance_electro_lightning)
482 if (self.BUTTON_ATCK_prev != 0)
484 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
485 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
487 self.BUTTON_ATCK_prev = 0;
490 if (self.BUTTON_ATCK2)
492 if (time >= self.electro_secondarytime)
493 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
496 self.electro_count = autocvar_g_balance_electro_secondary_count;
497 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
498 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
503 else if (req == WR_PRECACHE)
505 precache_model ("models/weapons/g_electro.md3");
506 precache_model ("models/weapons/v_electro.md3");
507 precache_model ("models/weapons/h_electro.iqm");
508 precache_sound ("weapons/electro_bounce.wav");
509 precache_sound ("weapons/electro_fire.wav");
510 precache_sound ("weapons/electro_fire2.wav");
511 precache_sound ("weapons/electro_impact.wav");
512 precache_sound ("weapons/electro_impact_combo.wav");
513 precache_sound ("weapons/reload.wav");
514 if(autocvar_g_balance_electro_lightning)
516 precache_sound ("weapons/lgbeam_fire.wav");
519 else if (req == WR_SETUP)
521 weapon_setup(WEP_ELECTRO);
523 else if (req == WR_CHECKAMMO1)
525 if(autocvar_g_balance_electro_lightning)
527 if(!autocvar_g_balance_electro_primary_ammo)
530 ammo_amount = self.ammo_cells > 0;
531 ammo_amount += self.weapon_load[WEP_ELECTRO] > 0;
535 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
536 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_primary_ammo;
540 else if (req == WR_CHECKAMMO2)
542 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
543 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_secondary_ammo;
546 else if (req == WR_RESETPLAYER)
548 self.electro_secondarytime = time;
550 else if (req == WR_RELOAD)
558 float w_electro(float req)
560 if(req == WR_IMPACTEFFECT)
563 org2 = w_org + w_backoff * 6;
564 if(w_deathtype & HITTYPE_SECONDARY)
566 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
568 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
572 if(w_deathtype & HITTYPE_BOUNCE)
574 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
575 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
577 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
581 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
583 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
587 else if(req == WR_PRECACHE)
589 precache_sound("weapons/electro_impact.wav");
590 precache_sound("weapons/electro_impact_combo.wav");
592 else if (req == WR_SUICIDEMESSAGE)
594 if(w_deathtype & HITTYPE_SECONDARY)
595 w_deathtypestring = _("%s could not remember where they put plasma");
597 w_deathtypestring = _("%s played with plasma");
599 else if (req == WR_KILLMESSAGE)
601 if(w_deathtype & HITTYPE_SECONDARY)
603 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
604 w_deathtypestring = _("%s just noticed %s's blue ball");
605 else // unchecked: BOUNCE
606 w_deathtypestring = _("%s got in touch with %s's blue ball");
610 if(w_deathtype & HITTYPE_BOUNCE) // combo
611 w_deathtypestring = _("%s felt the electrifying air of %s's combo");
612 else if(w_deathtype & HITTYPE_SPLASH)
613 w_deathtypestring = _("%s got too close to %s's blue beam");
615 w_deathtypestring = _("%s was blasted by %s's blue beam");