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_Plasma_Explode_Combo (void);
10 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
13 e = WarpZone_FindRadius(org, rad, TRUE);
16 if (e.classname == "plasma")
18 // change owner to whoever caused the combo explosion
20 e.takedamage = DAMAGE_NO;
21 e.classname = "plasma_chain";
22 e.think = W_Plasma_Explode_Combo;
23 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
29 void W_Plasma_Explode (void)
31 if(other.takedamage == DAMAGE_AIM)
32 if(other.classname == "player")
33 if(IsDifferentTeam(self.realowner, other))
34 if(other.deadflag == DEAD_NO)
36 AnnounceTo(self.realowner, "electrobitch");
38 self.event_damage = SUB_Null;
39 self.takedamage = DAMAGE_NO;
40 if (self.movetype == MOVETYPE_BOUNCE)
42 RadiusDamage (self, self.realowner, 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);
46 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.realowner);
47 RadiusDamage (self, self.realowner, 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);
53 void W_Plasma_Explode_Combo (void)
55 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.realowner);
57 self.event_damage = SUB_Null;
58 RadiusDamage (self, self.realowner, 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
62 void W_Plasma_Touch (void)
64 //self.velocity = self.velocity * 0.1;
67 if (other.takedamage == DAMAGE_AIM) {
70 //UpdateCSQCProjectile(self);
71 spamsound (self, CH_SHOTS, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
72 self.projectiledeathtype |= HITTYPE_BOUNCE;
76 void W_Plasma_TouchExplode (void)
82 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
87 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
88 float is_combo = (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim");
90 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, (is_combo ? 1 : -1)))
91 return; // g_projectiles_damage says to halt
93 self.health = self.health - damage;
96 self.takedamage = DAMAGE_NO;
97 self.nextthink = time;
100 // change owner to whoever caused the combo explosion
101 self.realowner = inflictor.realowner;
102 self.classname = "plasma_chain";
103 self.think = W_Plasma_Explode_Combo;
104 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
105 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
109 self.use = W_Plasma_Explode;
110 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
115 void W_Electro_Attack()
119 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_reload_ammo);
121 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CH_WEAPON_A, autocvar_g_balance_electro_primary_damage);
123 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
126 proj.classname = "plasma_prim";
127 proj.owner = proj.realowner = self;
128 proj.bot_dodge = TRUE;
129 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
130 proj.use = W_Plasma_Explode;
131 proj.think = adaptor_think2use_hittype_splash;
132 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
133 PROJECTILE_MAKETRIGGER(proj);
134 proj.projectiledeathtype = WEP_ELECTRO;
135 setorigin(proj, w_shotorg);
137 proj.movetype = MOVETYPE_FLY;
138 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
139 proj.angles = vectoangles(proj.velocity);
140 proj.touch = W_Plasma_TouchExplode;
141 setsize(proj, '0 0 -3', '0 0 -3');
142 proj.flags = FL_PROJECTILE;
144 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
146 other = proj; MUTATOR_CALLHOOK(EditProjectile);
149 void W_Electro_Attack2()
153 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
155 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CH_WEAPON_A, autocvar_g_balance_electro_secondary_damage);
157 w_shotdir = v_forward; // no TrueAim for grenades please
159 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
162 proj.classname = "plasma";
163 proj.owner = proj.realowner = self;
164 proj.use = W_Plasma_Explode;
165 proj.think = adaptor_think2use_hittype_splash;
166 proj.bot_dodge = TRUE;
167 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
168 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
169 PROJECTILE_MAKETRIGGER(proj);
170 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
171 setorigin(proj, w_shotorg);
173 //proj.glow_size = 50;
174 //proj.glow_color = 45;
175 proj.movetype = MOVETYPE_BOUNCE;
176 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
177 proj.touch = W_Plasma_Touch;
178 setsize(proj, '0 0 -4', '0 0 -4');
179 proj.takedamage = DAMAGE_YES;
180 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
181 proj.health = autocvar_g_balance_electro_secondary_health;
182 proj.event_damage = W_Plasma_Damage;
183 proj.flags = FL_PROJECTILE;
184 proj.damagedbycontents = (autocvar_g_balance_electro_secondary_damagedbycontents);
186 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
187 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
192 copyentity(proj, p2);
193 setmodel(p2, "models/ebomb.mdl");
194 setsize(p2, proj.mins, proj.maxs);
197 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
199 other = proj; MUTATOR_CALLHOOK(EditProjectile);
202 .vector hook_start, hook_end;
203 float lgbeam_send(entity to, float sf)
205 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
207 if(sound_allowed(MSG_BROADCAST, self.realowner))
209 WriteByte(MSG_ENTITY, sf);
212 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
213 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
217 WriteCoord(MSG_ENTITY, self.hook_start_x);
218 WriteCoord(MSG_ENTITY, self.hook_start_y);
219 WriteCoord(MSG_ENTITY, self.hook_start_z);
223 WriteCoord(MSG_ENTITY, self.hook_end_x);
224 WriteCoord(MSG_ENTITY, self.hook_end_y);
225 WriteCoord(MSG_ENTITY, self.hook_end_z);
231 float lgbeam_checkammo()
233 if(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO)
235 else if(autocvar_g_balance_electro_reload_ammo)
236 return self.realowner.clip_load > 0;
238 return self.realowner.ammo_cells > 0;
241 entity lgbeam_owner_ent;
245 owner_player = self.realowner;
247 owner_player.prevlgfire = time;
248 if (self != owner_player.lgbeam)
254 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
256 if(self == owner_player.lgbeam)
257 owner_player.lgbeam = world;
262 self.nextthink = time;
264 makevectors(owner_player.v_angle);
269 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
270 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
272 if(autocvar_g_balance_electro_primary_ammo)
274 if(autocvar_g_balance_electro_reload_ammo)
276 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
277 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
278 owner_player.(weapon_load[WEP_ELECTRO]) = owner_player.clip_load;
282 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
283 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
288 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
289 if(!lgbeam_owner_ent)
291 lgbeam_owner_ent = spawn();
292 lgbeam_owner_ent.classname = "lgbeam_owner_ent";
294 WarpZone_traceline_antilag(lgbeam_owner_ent, w_shotorg, w_shotend, MOVE_NORMAL, lgbeam_owner_ent, ANTILAG_LATENCY(owner_player));
300 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
302 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));
304 if(accuracy_isgooddamage(owner_player, trace_ent))
305 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
306 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
308 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
311 if(w_shotorg != self.hook_start)
314 self.hook_start = w_shotorg;
316 if(w_shotend != self.hook_end)
319 self.hook_end = w_shotend;
323 // experimental lightning gun
324 void W_Electro_Attack3 (void)
326 // only play fire sound if 0.5 sec has passed since player let go the fire button
327 if(time - self.prevlgfire > 0.5)
328 sound (self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
330 entity beam, oldself;
332 self.lgbeam = beam = spawn();
333 beam.classname = "lgbeam";
334 beam.solid = SOLID_NOT;
335 beam.think = lgbeam_think;
336 beam.owner = beam.realowner = self;
337 beam.movetype = MOVETYPE_NONE;
338 beam.shot_spread = 0;
339 beam.bot_dodge = TRUE;
340 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
341 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
351 weapon_action(WEP_ELECTRO, WR_PRECACHE);
352 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
353 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
354 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
355 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
358 void spawnfunc_weapon_electro (void)
360 weapon_defaultspawnfunc(WEP_ELECTRO);
363 void w_electro_checkattack()
365 if(self.electro_count > 1)
366 if(self.BUTTON_ATCK2)
367 if(weapon_prepareattack(1, -1))
370 self.electro_count -= 1;
371 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
378 .float bot_secondary_electromooth;
379 .float BUTTON_ATCK_prev;
380 float w_electro(float req)
385 self.BUTTON_ATCK=FALSE;
386 self.BUTTON_ATCK2=FALSE;
387 if(vlen(self.origin-self.enemy.origin) > 1000)
388 self.bot_secondary_electromooth = 0;
389 if(self.bot_secondary_electromooth == 0)
393 if(autocvar_g_balance_electro_primary_speed)
394 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
396 shoot = bot_aim(1000000, 0, 0.001, FALSE);
400 self.BUTTON_ATCK = TRUE;
401 if(random() < 0.01) self.bot_secondary_electromooth = 1;
406 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
408 self.BUTTON_ATCK2 = TRUE;
409 if(random() < 0.03) self.bot_secondary_electromooth = 0;
413 else if (req == WR_THINK)
415 if(autocvar_g_balance_electro_reload_ammo) // forced reload
417 if(autocvar_g_balance_electro_lightning)
419 if(self.clip_load > 0)
422 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
424 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
429 weapon_action(self.weapon, WR_RELOAD);
433 if (self.BUTTON_ATCK)
435 if(autocvar_g_balance_electro_lightning)
436 if(self.BUTTON_ATCK_prev)
438 // prolong the animtime while the gun is being fired
439 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
440 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
442 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
444 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
446 if(autocvar_g_balance_electro_lightning)
448 if ((!self.lgbeam) || wasfreed(self.lgbeam))
452 if(!self.BUTTON_ATCK_prev)
454 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
455 self.BUTTON_ATCK_prev = 1;
461 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
465 if(autocvar_g_balance_electro_lightning)
467 if (self.BUTTON_ATCK_prev != 0)
469 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
470 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
472 self.BUTTON_ATCK_prev = 0;
475 if (self.BUTTON_ATCK2)
477 if (time >= self.electro_secondarytime)
478 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
481 self.electro_count = autocvar_g_balance_electro_secondary_count;
482 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
483 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
488 else if (req == WR_PRECACHE)
490 precache_model ("models/weapons/g_electro.md3");
491 precache_model ("models/weapons/v_electro.md3");
492 precache_model ("models/weapons/h_electro.iqm");
493 precache_sound ("weapons/electro_bounce.wav");
494 precache_sound ("weapons/electro_fire.wav");
495 precache_sound ("weapons/electro_fire2.wav");
496 precache_sound ("weapons/electro_impact.wav");
497 precache_sound ("weapons/electro_impact_combo.wav");
498 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
499 if(autocvar_g_balance_electro_lightning)
501 precache_sound ("weapons/lgbeam_fire.wav");
504 else if (req == WR_SETUP)
506 weapon_setup(WEP_ELECTRO);
507 self.current_ammo = ammo_cells;
509 else if (req == WR_CHECKAMMO1)
511 if(autocvar_g_balance_electro_lightning)
513 if(!autocvar_g_balance_electro_primary_ammo)
516 ammo_amount = self.ammo_cells > 0;
517 ammo_amount += self.(weapon_load[WEP_ELECTRO]) > 0;
521 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
522 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_primary_ammo;
526 else if (req == WR_CHECKAMMO2)
528 if(autocvar_g_balance_electro_combo_safeammocheck) // true if you can fire at least one secondary blob AND one primary shot after it, otherwise false.
530 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
531 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
535 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
536 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo;
540 else if (req == WR_RESETPLAYER)
542 self.electro_secondarytime = time;
544 else if (req == WR_RELOAD)
546 W_Reload(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");
552 float w_electro(float req)
554 if(req == WR_IMPACTEFFECT)
557 org2 = w_org + w_backoff * 6;
558 if(w_deathtype & HITTYPE_SECONDARY)
560 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
562 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
566 if(w_deathtype & HITTYPE_BOUNCE)
568 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
569 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
571 sound(self, CH_SHOTS, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
575 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
577 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
581 else if(req == WR_PRECACHE)
583 precache_sound("weapons/electro_impact.wav");
584 precache_sound("weapons/electro_impact_combo.wav");
586 else if (req == WR_SUICIDEMESSAGE)
588 if(w_deathtype & HITTYPE_SECONDARY)
589 w_deathtypestring = _("%s could not remember where they put their electro plasma");
591 w_deathtypestring = _("%s played with electro plasma");
593 else if (req == WR_KILLMESSAGE)
595 if(w_deathtype & HITTYPE_SECONDARY)
597 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
598 w_deathtypestring = _("%s just noticed %s's electro plasma");
599 else // unchecked: BOUNCE
600 w_deathtypestring = _("%s got in touch with %s's electro plasma");
604 if(w_deathtype & HITTYPE_BOUNCE) // combo
605 w_deathtypestring = _("%s felt the electrifying air of %s's electro combo");
606 else if(w_deathtype & HITTYPE_SPLASH)
607 w_deathtypestring = _("%s got too close to %s's blue electro bolt");
609 w_deathtypestring = _("%s was blasted by %s's blue electro bolt");