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 self.reload_ammo_player = ammo_cells;
11 self.reload_ammo_min = min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo);
12 self.reload_ammo_amount = autocvar_g_balance_electro_reload_ammo;
13 self.reload_time = autocvar_g_balance_electro_reload_time;
14 self.reload_sound = "weapons/reload.wav";
19 void W_Plasma_Explode_Combo (void);
21 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
24 e = WarpZone_FindRadius(org, rad, TRUE);
27 if (e.classname == "plasma")
29 // change owner to whoever caused the combo explosion
31 e.takedamage = DAMAGE_NO;
32 e.classname = "plasma_chain";
33 e.think = W_Plasma_Explode_Combo;
34 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
40 void W_Plasma_Explode (void)
42 if(other.takedamage == DAMAGE_AIM)
43 if(other.classname == "player")
44 if(IsDifferentTeam(self.owner, other))
45 if(other.deadflag == DEAD_NO)
47 AnnounceTo(self.owner, "electrobitch");
49 self.event_damage = SUB_Null;
50 self.takedamage = DAMAGE_NO;
51 if (self.movetype == MOVETYPE_BOUNCE)
53 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);
57 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
58 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);
64 void W_Plasma_Explode_Combo (void)
66 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
68 self.event_damage = SUB_Null;
69 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
73 void W_Plasma_Touch (void)
75 //self.velocity = self.velocity * 0.1;
78 if (other.takedamage == DAMAGE_AIM) {
81 //UpdateCSQCProjectile(self);
82 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
83 self.projectiledeathtype |= HITTYPE_BOUNCE;
87 void W_Plasma_TouchExplode (void)
93 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
97 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
98 self.health = self.health - damage;
101 self.takedamage = DAMAGE_NO;
102 self.nextthink = time;
103 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
105 // change owner to whoever caused the combo explosion
106 self.owner = inflictor.owner;
107 self.classname = "plasma_chain";
108 self.think = W_Plasma_Explode_Combo;
109 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
110 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
114 self.use = W_Plasma_Explode;
115 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
120 void W_Electro_Attack()
124 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
125 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
127 if(autocvar_g_balance_electro_reload_ammo)
129 self.clip_load -= autocvar_g_balance_electro_primary_ammo;
130 self.weapon_load[WEP_ELECTRO] = self.clip_load;
133 self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
136 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
138 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
141 proj.classname = "plasma_prim";
143 proj.bot_dodge = TRUE;
144 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
145 proj.use = W_Plasma_Explode;
146 proj.think = adaptor_think2use_hittype_splash;
147 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
148 PROJECTILE_MAKETRIGGER(proj);
149 proj.projectiledeathtype = WEP_ELECTRO;
150 setorigin(proj, w_shotorg);
152 proj.movetype = MOVETYPE_FLY;
153 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
154 proj.angles = vectoangles(proj.velocity);
155 proj.touch = W_Plasma_TouchExplode;
156 setsize(proj, '0 0 -3', '0 0 -3');
157 proj.flags = FL_PROJECTILE;
159 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
162 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
164 other = proj; MUTATOR_CALLHOOK(EditProjectile);
167 void W_Electro_Attack2()
171 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
172 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
174 if(autocvar_g_balance_electro_reload_ammo)
176 self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
177 self.weapon_load[WEP_ELECTRO] = self.clip_load;
180 self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
183 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
185 w_shotdir = v_forward; // no TrueAim for grenades please
187 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
190 proj.classname = "plasma";
192 proj.use = W_Plasma_Explode;
193 proj.think = adaptor_think2use_hittype_splash;
194 proj.bot_dodge = TRUE;
195 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
196 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
197 PROJECTILE_MAKETRIGGER(proj);
198 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
199 setorigin(proj, w_shotorg);
201 //proj.glow_size = 50;
202 //proj.glow_color = 45;
203 proj.movetype = MOVETYPE_BOUNCE;
204 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
205 proj.touch = W_Plasma_Touch;
206 setsize(proj, '0 0 -4', '0 0 -4');
207 proj.takedamage = DAMAGE_YES;
208 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
209 proj.health = autocvar_g_balance_electro_secondary_health;
210 proj.event_damage = W_Plasma_Damage;
211 proj.flags = FL_PROJECTILE;
213 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
214 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
219 copyentity(proj, p2);
220 setmodel(p2, "models/ebomb.mdl");
221 setsize(p2, proj.mins, proj.maxs);
224 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
226 other = proj; MUTATOR_CALLHOOK(EditProjectile);
229 .vector hook_start, hook_end;
230 float lgbeam_send(entity to, float sf)
232 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
234 if(sound_allowed(MSG_BROADCAST, self.owner))
236 WriteByte(MSG_ENTITY, sf);
239 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
240 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
244 WriteCoord(MSG_ENTITY, self.hook_start_x);
245 WriteCoord(MSG_ENTITY, self.hook_start_y);
246 WriteCoord(MSG_ENTITY, self.hook_start_z);
250 WriteCoord(MSG_ENTITY, self.hook_end_x);
251 WriteCoord(MSG_ENTITY, self.hook_end_y);
252 WriteCoord(MSG_ENTITY, self.hook_end_z);
258 float lgbeam_checkammo()
260 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
262 else if(autocvar_g_balance_electro_reload_ammo)
263 return self.owner.clip_load > 0;
265 return self.owner.ammo_cells > 0;
271 owner_player = self.owner;
273 owner_player.prevlgfire = time;
274 if (self != owner_player.lgbeam)
280 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
282 if(self == owner_player.lgbeam)
283 owner_player.lgbeam = world;
288 self.nextthink = time;
290 makevectors(owner_player.v_angle);
295 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
296 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
298 if(autocvar_g_balance_electro_primary_ammo)
300 if(autocvar_g_balance_electro_reload_ammo)
302 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
303 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
304 owner_player.weapon_load[WEP_ELECTRO] = owner_player.clip_load;
308 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
309 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
314 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
315 WarpZone_traceline_antilag(owner_player, w_shotorg, w_shotend, MOVE_NORMAL, owner_player, ANTILAG_LATENCY(owner_player));
321 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
323 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));
325 if(accuracy_isgooddamage(owner_player, trace_ent))
326 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
327 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
329 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
332 if(w_shotorg != self.hook_start)
335 self.hook_start = w_shotorg;
337 if(w_shotend != self.hook_end)
340 self.hook_end = w_shotend;
344 // experimental lightning gun
345 void W_Electro_Attack3 (void)
347 // only play fire sound if 0.5 sec has passed since player let go the fire button
348 if(time - self.prevlgfire > 0.5)
349 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
351 entity beam, oldself;
353 self.lgbeam = beam = spawn();
354 beam.classname = "lgbeam";
355 beam.solid = SOLID_NOT;
356 beam.think = lgbeam_think;
358 beam.movetype = MOVETYPE_NONE;
359 beam.shot_spread = 0;
360 beam.bot_dodge = TRUE;
361 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
362 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
372 weapon_action(WEP_ELECTRO, WR_PRECACHE);
373 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
374 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
375 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
376 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
379 void spawnfunc_weapon_electro (void)
381 weapon_defaultspawnfunc(WEP_ELECTRO);
384 void w_electro_checkattack()
386 if(self.electro_count > 1)
387 if(self.BUTTON_ATCK2)
388 if(weapon_prepareattack(1, -1))
391 self.electro_count -= 1;
392 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
399 .float bot_secondary_electromooth;
400 .float BUTTON_ATCK_prev;
401 float w_electro(float req)
406 self.BUTTON_ATCK=FALSE;
407 self.BUTTON_ATCK2=FALSE;
408 if(vlen(self.origin-self.enemy.origin) > 1000)
409 self.bot_secondary_electromooth = 0;
410 if(self.bot_secondary_electromooth == 0)
414 if(autocvar_g_balance_electro_primary_speed)
415 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
417 shoot = bot_aim(1000000, 0, 0.001, FALSE);
421 self.BUTTON_ATCK = TRUE;
422 if(random() < 0.01) self.bot_secondary_electromooth = 1;
427 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
429 self.BUTTON_ATCK2 = TRUE;
430 if(random() < 0.03) self.bot_secondary_electromooth = 0;
434 else if (req == WR_THINK)
436 if(autocvar_g_balance_electro_reload_ammo) // forced reload
438 if(autocvar_g_balance_electro_lightning)
440 if(self.clip_load > 0)
443 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
445 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
454 if (self.BUTTON_ATCK)
456 if(autocvar_g_balance_electro_lightning)
457 if(self.BUTTON_ATCK_prev)
459 // prolong the animtime while the gun is being fired
460 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
461 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
463 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
465 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
467 if(autocvar_g_balance_electro_lightning)
469 if ((!self.lgbeam) || wasfreed(self.lgbeam))
473 if(!self.BUTTON_ATCK_prev)
475 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
476 self.BUTTON_ATCK_prev = 1;
482 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
486 if(autocvar_g_balance_electro_lightning)
488 if (self.BUTTON_ATCK_prev != 0)
490 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
491 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
493 self.BUTTON_ATCK_prev = 0;
496 if (self.BUTTON_ATCK2)
498 if (time >= self.electro_secondarytime)
499 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
502 self.electro_count = autocvar_g_balance_electro_secondary_count;
503 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
504 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
509 else if (req == WR_PRECACHE)
511 precache_model ("models/weapons/g_electro.md3");
512 precache_model ("models/weapons/v_electro.md3");
513 precache_model ("models/weapons/h_electro.iqm");
514 precache_sound ("weapons/electro_bounce.wav");
515 precache_sound ("weapons/electro_fire.wav");
516 precache_sound ("weapons/electro_fire2.wav");
517 precache_sound ("weapons/electro_impact.wav");
518 precache_sound ("weapons/electro_impact_combo.wav");
519 precache_sound ("weapons/reload.wav");
520 if(autocvar_g_balance_electro_lightning)
522 precache_sound ("weapons/lgbeam_fire.wav");
525 else if (req == WR_SETUP)
527 weapon_setup(WEP_ELECTRO);
529 else if (req == WR_CHECKAMMO1)
531 if(autocvar_g_balance_electro_lightning)
533 if(!autocvar_g_balance_electro_primary_ammo)
536 ammo_amount = self.ammo_cells > 0;
537 ammo_amount += self.weapon_load[WEP_ELECTRO] > 0;
541 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
542 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_primary_ammo;
546 else if (req == WR_CHECKAMMO2)
548 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
549 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_secondary_ammo;
552 else if (req == WR_RESETPLAYER)
554 self.electro_secondarytime = time;
556 else if (req == WR_RELOAD)
564 float w_electro(float req)
566 if(req == WR_IMPACTEFFECT)
569 org2 = w_org + w_backoff * 6;
570 if(w_deathtype & HITTYPE_SECONDARY)
572 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
574 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
578 if(w_deathtype & HITTYPE_BOUNCE)
580 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
581 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
583 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
587 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
589 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
593 else if(req == WR_PRECACHE)
595 precache_sound("weapons/electro_impact.wav");
596 precache_sound("weapons/electro_impact_combo.wav");
598 else if (req == WR_SUICIDEMESSAGE)
600 if(w_deathtype & HITTYPE_SECONDARY)
601 w_deathtypestring = _("%s could not remember where they put plasma");
603 w_deathtypestring = _("%s played with plasma");
605 else if (req == WR_KILLMESSAGE)
607 if(w_deathtype & HITTYPE_SECONDARY)
609 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
610 w_deathtypestring = _("%s just noticed %s's blue ball");
611 else // unchecked: BOUNCE
612 w_deathtypestring = _("%s got in touch with %s's blue ball");
616 if(w_deathtype & HITTYPE_BOUNCE) // combo
617 w_deathtypestring = _("%s felt the electrifying air of %s's combo");
618 else if(w_deathtype & HITTYPE_SPLASH)
619 w_deathtypestring = _("%s got too close to %s's blue beam");
621 w_deathtypestring = _("%s was blasted by %s's blue beam");