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 = func_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 = func_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;
143 proj.missile_flags = MIF_SPLASH;
145 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
147 other = proj; MUTATOR_CALLHOOK(EditProjectile);
150 void W_Electro_Attack2()
154 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
156 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);
158 w_shotdir = v_forward; // no TrueAim for grenades please
160 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
163 proj.classname = "plasma";
164 proj.owner = proj.realowner = self;
165 proj.use = W_Plasma_Explode;
166 proj.think = adaptor_think2use_hittype_splash;
167 proj.bot_dodge = TRUE;
168 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
169 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
170 PROJECTILE_MAKETRIGGER(proj);
171 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
172 setorigin(proj, w_shotorg);
174 //proj.glow_size = 50;
175 //proj.glow_color = 45;
176 proj.movetype = MOVETYPE_BOUNCE;
177 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
178 proj.touch = W_Plasma_Touch;
179 setsize(proj, '0 0 -4', '0 0 -4');
180 proj.takedamage = DAMAGE_YES;
181 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
182 proj.health = autocvar_g_balance_electro_secondary_health;
183 proj.event_damage = W_Plasma_Damage;
184 proj.flags = FL_PROJECTILE;
185 proj.damagedbycontents = (autocvar_g_balance_electro_secondary_damagedbycontents);
187 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
188 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
189 proj.missile_flags = MIF_SPLASH | MIF_ARC;
194 copyentity(proj, p2);
195 setmodel(p2, "models/ebomb.mdl");
196 setsize(p2, proj.mins, proj.maxs);
199 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
201 other = proj; MUTATOR_CALLHOOK(EditProjectile);
204 .vector hook_start, hook_end;
205 float lgbeam_send(entity to, float sf)
207 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
209 if(sound_allowed(MSG_BROADCAST, self.realowner))
211 WriteByte(MSG_ENTITY, sf);
214 WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
215 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
219 WriteCoord(MSG_ENTITY, self.hook_start_x);
220 WriteCoord(MSG_ENTITY, self.hook_start_y);
221 WriteCoord(MSG_ENTITY, self.hook_start_z);
225 WriteCoord(MSG_ENTITY, self.hook_end_x);
226 WriteCoord(MSG_ENTITY, self.hook_end_y);
227 WriteCoord(MSG_ENTITY, self.hook_end_z);
233 float lgbeam_checkammo()
235 if(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO)
237 else if(autocvar_g_balance_electro_reload_ammo)
238 return self.realowner.clip_load > 0;
240 return self.realowner.ammo_cells > 0;
243 entity lgbeam_owner_ent;
247 owner_player = self.realowner;
249 owner_player.prevlgfire = time;
250 if (self != owner_player.lgbeam)
256 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen || owner_player.frozen)
258 if(self == owner_player.lgbeam)
259 owner_player.lgbeam = world;
264 self.nextthink = time;
266 makevectors(owner_player.v_angle);
271 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
272 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
274 if(autocvar_g_balance_electro_primary_ammo)
276 if(autocvar_g_balance_electro_reload_ammo)
278 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
279 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
280 owner_player.(weapon_load[WEP_ELECTRO]) = owner_player.clip_load;
284 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
285 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
290 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
291 if(!lgbeam_owner_ent)
293 lgbeam_owner_ent = spawn();
294 lgbeam_owner_ent.classname = "lgbeam_owner_ent";
296 WarpZone_traceline_antilag(lgbeam_owner_ent, w_shotorg, w_shotend, MOVE_NORMAL, lgbeam_owner_ent, ANTILAG_LATENCY(owner_player));
302 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
304 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));
306 if(accuracy_isgooddamage(owner_player, trace_ent))
307 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
308 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
310 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
313 if(w_shotorg != self.hook_start)
316 self.hook_start = w_shotorg;
318 if(w_shotend != self.hook_end)
321 self.hook_end = w_shotend;
325 // experimental lightning gun
326 void W_Electro_Attack3 (void)
328 // only play fire sound if 0.5 sec has passed since player let go the fire button
329 if(time - self.prevlgfire > 0.5)
330 sound (self, CH_WEAPON_A, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
332 entity beam, oldself;
334 self.lgbeam = beam = spawn();
335 beam.classname = "lgbeam";
336 beam.solid = SOLID_NOT;
337 beam.think = lgbeam_think;
338 beam.owner = beam.realowner = self;
339 beam.movetype = MOVETYPE_NONE;
340 beam.shot_spread = 0;
341 beam.bot_dodge = TRUE;
342 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
343 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
353 weapon_action(WEP_ELECTRO, WR_PRECACHE);
354 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
355 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
356 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
357 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
360 void spawnfunc_weapon_electro (void)
362 weapon_defaultspawnfunc(WEP_ELECTRO);
365 void w_electro_checkattack()
367 if(self.electro_count > 1)
368 if(self.BUTTON_ATCK2)
369 if(weapon_prepareattack(1, -1))
372 self.electro_count -= 1;
373 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
380 .float bot_secondary_electromooth;
381 .float BUTTON_ATCK_prev;
382 float w_electro(float req)
387 self.BUTTON_ATCK=FALSE;
388 self.BUTTON_ATCK2=FALSE;
389 if(vlen(self.origin-self.enemy.origin) > 1000)
390 self.bot_secondary_electromooth = 0;
391 if(self.bot_secondary_electromooth == 0)
395 if(autocvar_g_balance_electro_primary_speed)
396 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
398 shoot = bot_aim(1000000, 0, 0.001, FALSE);
402 self.BUTTON_ATCK = TRUE;
403 if(random() < 0.01) self.bot_secondary_electromooth = 1;
408 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
410 self.BUTTON_ATCK2 = TRUE;
411 if(random() < 0.03) self.bot_secondary_electromooth = 0;
415 else if (req == WR_THINK)
417 if(autocvar_g_balance_electro_reload_ammo) // forced reload
420 if(autocvar_g_balance_electro_lightning)
422 if(self.clip_load > 0)
425 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
427 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
432 weapon_action(self.weapon, WR_RELOAD);
436 if (self.BUTTON_ATCK)
438 if(autocvar_g_balance_electro_lightning)
439 if(self.BUTTON_ATCK_prev)
441 // prolong the animtime while the gun is being fired
442 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
443 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
445 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
447 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
449 if(autocvar_g_balance_electro_lightning)
451 if ((!self.lgbeam) || wasfreed(self.lgbeam))
455 if(!self.BUTTON_ATCK_prev)
457 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
458 self.BUTTON_ATCK_prev = 1;
464 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
468 if(autocvar_g_balance_electro_lightning)
470 if (self.BUTTON_ATCK_prev != 0)
472 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
473 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
475 self.BUTTON_ATCK_prev = 0;
478 if (self.BUTTON_ATCK2)
480 if (time >= self.electro_secondarytime)
481 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
484 self.electro_count = autocvar_g_balance_electro_secondary_count;
485 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
486 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
491 else if (req == WR_PRECACHE)
493 precache_model ("models/weapons/g_electro.md3");
494 precache_model ("models/weapons/v_electro.md3");
495 precache_model ("models/weapons/h_electro.iqm");
496 precache_sound ("weapons/electro_bounce.wav");
497 precache_sound ("weapons/electro_fire.wav");
498 precache_sound ("weapons/electro_fire2.wav");
499 precache_sound ("weapons/electro_impact.wav");
500 precache_sound ("weapons/electro_impact_combo.wav");
501 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
502 if(autocvar_g_balance_electro_lightning)
504 precache_sound ("weapons/lgbeam_fire.wav");
507 else if (req == WR_SETUP)
509 weapon_setup(WEP_ELECTRO);
510 self.current_ammo = ammo_cells;
512 else if (req == WR_CHECKAMMO1)
514 if(autocvar_g_balance_electro_lightning)
516 if(!autocvar_g_balance_electro_primary_ammo)
519 ammo_amount = self.ammo_cells > 0;
520 ammo_amount += self.(weapon_load[WEP_ELECTRO]) > 0;
524 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
525 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_primary_ammo;
529 else if (req == WR_CHECKAMMO2)
531 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.
533 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
534 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo + autocvar_g_balance_electro_primary_ammo;
538 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
539 ammo_amount += self.(weapon_load[WEP_ELECTRO]) >= autocvar_g_balance_electro_secondary_ammo;
543 else if (req == WR_RESETPLAYER)
545 self.electro_secondarytime = time;
547 else if (req == WR_RELOAD)
549 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");
555 float w_electro(float req)
557 if(req == WR_IMPACTEFFECT)
560 org2 = w_org + w_backoff * 6;
561 if(w_deathtype & HITTYPE_SECONDARY)
563 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
565 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
569 if(w_deathtype & HITTYPE_BOUNCE)
571 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
572 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
574 sound(self, CH_SHOTS, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
578 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
580 sound(self, CH_SHOTS, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
584 else if(req == WR_PRECACHE)
586 precache_sound("weapons/electro_impact.wav");
587 precache_sound("weapons/electro_impact_combo.wav");
589 else if (req == WR_SUICIDEMESSAGE)
591 if(w_deathtype & HITTYPE_SECONDARY)
592 w_deathtypestring = _("%s could not remember where they put their electro plasma");
594 w_deathtypestring = _("%s played with electro plasma");
596 else if (req == WR_KILLMESSAGE)
598 if(w_deathtype & HITTYPE_SECONDARY)
600 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
601 w_deathtypestring = _("%s just noticed %s's electro plasma");
602 else // unchecked: BOUNCE
603 w_deathtypestring = _("%s got in touch with %s's electro plasma");
607 if(w_deathtype & HITTYPE_BOUNCE) // combo
608 w_deathtypestring = _("%s felt the electrifying air of %s's electro combo");
609 else if(w_deathtype & HITTYPE_SPLASH)
610 w_deathtypestring = _("%s got too close to %s's blue electro bolt");
612 w_deathtypestring = _("%s was blasted by %s's blue electro bolt");