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.owner, other))
34 if(other.deadflag == DEAD_NO)
36 AnnounceTo(self.owner, "electrobitch");
38 self.event_damage = SUB_Null;
39 self.takedamage = DAMAGE_NO;
40 if (self.movetype == MOVETYPE_BOUNCE)
42 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);
46 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
47 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);
53 void W_Plasma_Explode_Combo (void)
55 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
57 self.event_damage = SUB_Null;
58 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
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, CHAN_PROJECTILE, "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)
86 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
87 self.health = self.health - damage;
90 self.takedamage = DAMAGE_NO;
91 self.nextthink = time;
92 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
94 // change owner to whoever caused the combo explosion
95 self.owner = inflictor.owner;
96 self.classname = "plasma_chain";
97 self.think = W_Plasma_Explode_Combo;
98 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
99 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
103 self.use = W_Plasma_Explode;
104 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
109 void W_Electro_Attack()
113 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_reload_ammo);
115 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
117 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
120 proj.classname = "plasma_prim";
122 proj.bot_dodge = TRUE;
123 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
124 proj.use = W_Plasma_Explode;
125 proj.think = adaptor_think2use_hittype_splash;
126 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
127 PROJECTILE_MAKETRIGGER(proj);
128 proj.projectiledeathtype = WEP_ELECTRO;
129 setorigin(proj, w_shotorg);
131 proj.movetype = MOVETYPE_FLY;
132 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
133 proj.angles = vectoangles(proj.velocity);
134 proj.touch = W_Plasma_TouchExplode;
135 setsize(proj, '0 0 -3', '0 0 -3');
136 proj.flags = FL_PROJECTILE;
138 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
141 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
143 other = proj; MUTATOR_CALLHOOK(EditProjectile);
146 void W_Electro_Attack2()
150 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_electro_secondary_ammo, autocvar_g_balance_electro_reload_ammo);
152 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
154 w_shotdir = v_forward; // no TrueAim for grenades please
156 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
159 proj.classname = "plasma";
161 proj.use = W_Plasma_Explode;
162 proj.think = adaptor_think2use_hittype_splash;
163 proj.bot_dodge = TRUE;
164 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
165 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
166 PROJECTILE_MAKETRIGGER(proj);
167 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
168 setorigin(proj, w_shotorg);
170 //proj.glow_size = 50;
171 //proj.glow_color = 45;
172 proj.movetype = MOVETYPE_BOUNCE;
173 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
174 proj.touch = W_Plasma_Touch;
175 setsize(proj, '0 0 -4', '0 0 -4');
176 proj.takedamage = DAMAGE_YES;
177 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
178 proj.health = autocvar_g_balance_electro_secondary_health;
179 proj.event_damage = W_Plasma_Damage;
180 proj.flags = FL_PROJECTILE;
182 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
183 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
188 copyentity(proj, p2);
189 setmodel(p2, "models/ebomb.mdl");
190 setsize(p2, proj.mins, proj.maxs);
193 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
195 other = proj; MUTATOR_CALLHOOK(EditProjectile);
198 .vector hook_start, hook_end;
199 float lgbeam_send(entity to, float sf)
201 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
203 if(sound_allowed(MSG_BROADCAST, self.owner))
205 WriteByte(MSG_ENTITY, sf);
208 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
209 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
213 WriteCoord(MSG_ENTITY, self.hook_start_x);
214 WriteCoord(MSG_ENTITY, self.hook_start_y);
215 WriteCoord(MSG_ENTITY, self.hook_start_z);
219 WriteCoord(MSG_ENTITY, self.hook_end_x);
220 WriteCoord(MSG_ENTITY, self.hook_end_y);
221 WriteCoord(MSG_ENTITY, self.hook_end_z);
227 float lgbeam_checkammo()
229 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
231 else if(autocvar_g_balance_electro_reload_ammo)
232 return self.owner.clip_load > 0;
234 return self.owner.ammo_cells > 0;
240 owner_player = self.owner;
242 owner_player.prevlgfire = time;
243 if (self != owner_player.lgbeam)
249 if (owner_player.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || owner_player.deadflag != DEAD_NO || !owner_player.BUTTON_ATCK || owner_player.freezetag_frozen)
251 if(self == owner_player.lgbeam)
252 owner_player.lgbeam = world;
257 self.nextthink = time;
259 makevectors(owner_player.v_angle);
264 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
265 if not(owner_player.items & IT_UNLIMITED_WEAPON_AMMO)
267 if(autocvar_g_balance_electro_primary_ammo)
269 if(autocvar_g_balance_electro_reload_ammo)
271 dt = min(dt, owner_player.clip_load / autocvar_g_balance_electro_primary_ammo);
272 owner_player.clip_load = max(0, owner_player.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
273 owner_player.weapon_load[WEP_ELECTRO] = owner_player.clip_load;
277 dt = min(dt, owner_player.ammo_cells / autocvar_g_balance_electro_primary_ammo);
278 owner_player.ammo_cells = max(0, owner_player.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
283 W_SetupShot_Range(owner_player, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
284 WarpZone_traceline_antilag(owner_player, w_shotorg, w_shotend, MOVE_NORMAL, owner_player, ANTILAG_LATENCY(owner_player));
290 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
292 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));
294 if(accuracy_isgooddamage(owner_player, trace_ent))
295 accuracy_add(owner_player, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
296 Damage (trace_ent, owner_player, owner_player, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
298 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, owner_player);
301 if(w_shotorg != self.hook_start)
304 self.hook_start = w_shotorg;
306 if(w_shotend != self.hook_end)
309 self.hook_end = w_shotend;
313 // experimental lightning gun
314 void W_Electro_Attack3 (void)
316 // only play fire sound if 0.5 sec has passed since player let go the fire button
317 if(time - self.prevlgfire > 0.5)
318 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
320 entity beam, oldself;
322 self.lgbeam = beam = spawn();
323 beam.classname = "lgbeam";
324 beam.solid = SOLID_NOT;
325 beam.think = lgbeam_think;
327 beam.movetype = MOVETYPE_NONE;
328 beam.shot_spread = 0;
329 beam.bot_dodge = TRUE;
330 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
331 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
341 weapon_action(WEP_ELECTRO, WR_PRECACHE);
342 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
343 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
344 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
345 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
348 void spawnfunc_weapon_electro (void)
350 weapon_defaultspawnfunc(WEP_ELECTRO);
353 void w_electro_checkattack()
355 if(self.electro_count > 1)
356 if(self.BUTTON_ATCK2)
357 if(weapon_prepareattack(1, -1))
360 self.electro_count -= 1;
361 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
368 .float bot_secondary_electromooth;
369 .float BUTTON_ATCK_prev;
370 float w_electro(float req)
375 self.BUTTON_ATCK=FALSE;
376 self.BUTTON_ATCK2=FALSE;
377 if(vlen(self.origin-self.enemy.origin) > 1000)
378 self.bot_secondary_electromooth = 0;
379 if(self.bot_secondary_electromooth == 0)
383 if(autocvar_g_balance_electro_primary_speed)
384 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
386 shoot = bot_aim(1000000, 0, 0.001, FALSE);
390 self.BUTTON_ATCK = TRUE;
391 if(random() < 0.01) self.bot_secondary_electromooth = 1;
396 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
398 self.BUTTON_ATCK2 = TRUE;
399 if(random() < 0.03) self.bot_secondary_electromooth = 0;
403 else if (req == WR_THINK)
405 if(autocvar_g_balance_electro_reload_ammo) // forced reload
407 if(autocvar_g_balance_electro_lightning)
409 if(self.clip_load > 0)
412 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
414 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
419 weapon_action(self.weapon, WR_RELOAD);
423 if (self.BUTTON_ATCK)
425 if(autocvar_g_balance_electro_lightning)
426 if(self.BUTTON_ATCK_prev)
428 // prolong the animtime while the gun is being fired
429 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
430 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
432 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
434 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
436 if(autocvar_g_balance_electro_lightning)
438 if ((!self.lgbeam) || wasfreed(self.lgbeam))
442 if(!self.BUTTON_ATCK_prev)
444 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
445 self.BUTTON_ATCK_prev = 1;
451 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
455 if(autocvar_g_balance_electro_lightning)
457 if (self.BUTTON_ATCK_prev != 0)
459 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
460 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
462 self.BUTTON_ATCK_prev = 0;
465 if (self.BUTTON_ATCK2)
467 if (time >= self.electro_secondarytime)
468 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
471 self.electro_count = autocvar_g_balance_electro_secondary_count;
472 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
473 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
478 else if (req == WR_PRECACHE)
480 precache_model ("models/weapons/g_electro.md3");
481 precache_model ("models/weapons/v_electro.md3");
482 precache_model ("models/weapons/h_electro.iqm");
483 precache_sound ("weapons/electro_bounce.wav");
484 precache_sound ("weapons/electro_fire.wav");
485 precache_sound ("weapons/electro_fire2.wav");
486 precache_sound ("weapons/electro_impact.wav");
487 precache_sound ("weapons/electro_impact_combo.wav");
488 precache_sound ("weapons/reload.wav");
489 if(autocvar_g_balance_electro_lightning)
491 precache_sound ("weapons/lgbeam_fire.wav");
494 else if (req == WR_SETUP)
496 weapon_setup(WEP_ELECTRO);
497 self.current_ammo = ammo_cells;
499 else if (req == WR_CHECKAMMO1)
501 if(autocvar_g_balance_electro_lightning)
503 if(!autocvar_g_balance_electro_primary_ammo)
506 ammo_amount = self.ammo_cells > 0;
507 ammo_amount += self.weapon_load[WEP_ELECTRO] > 0;
511 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
512 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_primary_ammo;
516 else if (req == WR_CHECKAMMO2)
518 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
519 ammo_amount += self.weapon_load[WEP_ELECTRO] >= autocvar_g_balance_electro_secondary_ammo;
522 else if (req == WR_RESETPLAYER)
524 self.electro_secondarytime = time;
526 else if (req == WR_RELOAD)
528 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");
534 float w_electro(float req)
536 if(req == WR_IMPACTEFFECT)
539 org2 = w_org + w_backoff * 6;
540 if(w_deathtype & HITTYPE_SECONDARY)
542 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
544 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
548 if(w_deathtype & HITTYPE_BOUNCE)
550 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
551 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
553 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
557 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
559 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
563 else if(req == WR_PRECACHE)
565 precache_sound("weapons/electro_impact.wav");
566 precache_sound("weapons/electro_impact_combo.wav");
568 else if (req == WR_SUICIDEMESSAGE)
570 if(w_deathtype & HITTYPE_SECONDARY)
571 w_deathtypestring = _("%s could not remember where they put plasma");
573 w_deathtypestring = _("%s played with plasma");
575 else if (req == WR_KILLMESSAGE)
577 if(w_deathtype & HITTYPE_SECONDARY)
579 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
580 w_deathtypestring = _("%s just noticed %s's blue ball");
581 else // unchecked: BOUNCE
582 w_deathtypestring = _("%s got in touch with %s's blue ball");
586 if(w_deathtype & HITTYPE_BOUNCE) // combo
587 w_deathtypestring = _("%s felt the electrifying air of %s's combo");
588 else if(w_deathtype & HITTYPE_SPLASH)
589 w_deathtypestring = _("%s got too close to %s's blue beam");
591 w_deathtypestring = _("%s was blasted by %s's blue beam");