2 REGISTER_WEAPON(ELECTRO, w_electro, IT_CELLS, 5, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "electro", "electro", _("Electro"));
6 .float electro_secondarytime;
8 // weapon load persistence, for weapons that support reloading
11 void W_Electro_SetAmmoCounter()
13 // set clip_load to the weapon we have switched to, if the gun uses reloading
14 if(!autocvar_g_balance_electro_reload_ammo)
15 self.clip_load = 0; // also keeps crosshair ammo from displaying
18 self.clip_load = self.electro_load;
19 self.clip_size = autocvar_g_balance_electro_reload_ammo; // for the crosshair ammo display
23 void W_Electro_ReloadedAndReady()
27 // now do the ammo transfer
28 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
29 while(self.clip_load < autocvar_g_balance_electro_reload_ammo && self.ammo_cells) // make sure we don't add more ammo than we have
34 self.electro_load = self.clip_load;
36 t = ATTACK_FINISHED(self) - autocvar_g_balance_electro_reload_time - 1;
37 ATTACK_FINISHED(self) = t;
41 void W_Electro_Reload()
43 // return if reloading is disabled for this weapon
44 if(!autocvar_g_balance_electro_reload_ammo)
47 if(!W_ReloadCheck(self.ammo_cells, min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo)))
52 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
54 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_electro_reload_time + 1;
55 ATTACK_FINISHED(self) = t;
57 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_electro_reload_time, W_Electro_ReloadedAndReady);
59 self.old_clip_load = self.clip_load;
63 void W_Plasma_Explode_Combo (void);
65 void W_Plasma_TriggerCombo(vector org, float rad, entity own)
68 e = WarpZone_FindRadius(org, rad, TRUE);
71 if (e.classname == "plasma")
73 // change owner to whoever caused the combo explosion
75 e.takedamage = DAMAGE_NO;
76 e.classname = "plasma_chain";
77 e.think = W_Plasma_Explode_Combo;
78 e.nextthink = time + vlen(e.WarpZone_findradius_dist) / autocvar_g_balance_electro_combo_speed; // delay combo chains, looks cooler
84 void W_Plasma_Explode (void)
86 if(other.takedamage == DAMAGE_AIM)
87 if(other.classname == "player")
88 if(IsDifferentTeam(self.owner, other))
89 if(other.deadflag == DEAD_NO)
91 AnnounceTo(self.owner, "electrobitch");
93 self.event_damage = SUB_Null;
94 self.takedamage = DAMAGE_NO;
95 if (self.movetype == MOVETYPE_BOUNCE)
97 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);
101 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_primary_comboradius, self.owner);
102 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);
108 void W_Plasma_Explode_Combo (void)
110 W_Plasma_TriggerCombo(self.origin, autocvar_g_balance_electro_combo_comboradius, self.owner);
112 self.event_damage = SUB_Null;
113 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
117 void W_Plasma_Touch (void)
119 //self.velocity = self.velocity * 0.1;
122 if (other.takedamage == DAMAGE_AIM) {
125 //UpdateCSQCProjectile(self);
126 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
127 self.projectiledeathtype |= HITTYPE_BOUNCE;
131 void W_Plasma_TouchExplode (void)
137 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
141 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
142 self.health = self.health - damage;
143 if (self.health <= 0)
145 self.takedamage = DAMAGE_NO;
146 self.nextthink = time;
147 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
149 // change owner to whoever caused the combo explosion
150 self.owner = inflictor.owner;
151 self.classname = "plasma_chain";
152 self.think = W_Plasma_Explode_Combo;
153 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
154 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
158 self.use = W_Plasma_Explode;
159 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
164 void W_Electro_Attack()
168 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
169 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
171 if(autocvar_g_balance_electro_reload_ammo)
173 self.clip_load -= autocvar_g_balance_electro_primary_ammo;
174 self.electro_load = self.clip_load;
177 self.ammo_cells -= autocvar_g_balance_electro_primary_ammo;
180 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", CHAN_WEAPON, autocvar_g_balance_electro_primary_damage);
182 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
185 proj.classname = "plasma_prim";
187 proj.bot_dodge = TRUE;
188 proj.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
189 proj.use = W_Plasma_Explode;
190 proj.think = adaptor_think2use_hittype_splash;
191 proj.nextthink = time + autocvar_g_balance_electro_primary_lifetime;
192 PROJECTILE_MAKETRIGGER(proj);
193 proj.projectiledeathtype = WEP_ELECTRO;
194 setorigin(proj, w_shotorg);
196 proj.movetype = MOVETYPE_FLY;
197 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
198 proj.angles = vectoangles(proj.velocity);
199 proj.touch = W_Plasma_TouchExplode;
200 setsize(proj, '0 0 -3', '0 0 -3');
201 proj.flags = FL_PROJECTILE;
203 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
206 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
208 other = proj; MUTATOR_CALLHOOK(EditProjectile);
211 void W_Electro_Attack2()
215 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
216 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
218 if(autocvar_g_balance_electro_reload_ammo)
220 self.clip_load -= autocvar_g_balance_electro_secondary_ammo;
221 self.electro_load = self.clip_load;
224 self.ammo_cells -= autocvar_g_balance_electro_secondary_ammo;
227 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", CHAN_WEAPON, autocvar_g_balance_electro_secondary_damage);
229 w_shotdir = v_forward; // no TrueAim for grenades please
231 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
234 proj.classname = "plasma";
236 proj.use = W_Plasma_Explode;
237 proj.think = adaptor_think2use_hittype_splash;
238 proj.bot_dodge = TRUE;
239 proj.bot_dodgerating = autocvar_g_balance_electro_secondary_damage;
240 proj.nextthink = time + autocvar_g_balance_electro_secondary_lifetime;
241 PROJECTILE_MAKETRIGGER(proj);
242 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
243 setorigin(proj, w_shotorg);
245 //proj.glow_size = 50;
246 //proj.glow_color = 45;
247 proj.movetype = MOVETYPE_BOUNCE;
248 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
249 proj.touch = W_Plasma_Touch;
250 setsize(proj, '0 0 -4', '0 0 -4');
251 proj.takedamage = DAMAGE_YES;
252 proj.damageforcescale = autocvar_g_balance_electro_secondary_damageforcescale;
253 proj.health = autocvar_g_balance_electro_secondary_health;
254 proj.event_damage = W_Plasma_Damage;
255 proj.flags = FL_PROJECTILE;
257 proj.bouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
258 proj.bouncestop = autocvar_g_balance_electro_secondary_bouncestop;
263 copyentity(proj, p2);
264 setmodel(p2, "models/ebomb.mdl");
265 setsize(p2, proj.mins, proj.maxs);
268 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
270 other = proj; MUTATOR_CALLHOOK(EditProjectile);
273 .vector hook_start, hook_end;
274 float lgbeam_send(entity to, float sf)
276 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
278 if(sound_allowed(MSG_BROADCAST, self.owner))
280 WriteByte(MSG_ENTITY, sf);
283 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
284 WriteCoord(MSG_ENTITY, autocvar_g_balance_electro_primary_range);
288 WriteCoord(MSG_ENTITY, self.hook_start_x);
289 WriteCoord(MSG_ENTITY, self.hook_start_y);
290 WriteCoord(MSG_ENTITY, self.hook_start_z);
294 WriteCoord(MSG_ENTITY, self.hook_end_x);
295 WriteCoord(MSG_ENTITY, self.hook_end_y);
296 WriteCoord(MSG_ENTITY, self.hook_end_z);
302 float lgbeam_checkammo()
304 if(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
306 else if(autocvar_g_balance_electro_reload_ammo)
307 return self.owner.clip_load > 0;
309 return self.owner.ammo_cells > 0;
314 self.owner.prevlgfire = time;
315 if (self != self.owner.lgbeam)
321 if (self.owner.weaponentity.state != WS_INUSE || !lgbeam_checkammo() || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK || self.owner.freezetag_frozen)
323 if(self == self.owner.lgbeam)
324 self.owner.lgbeam = world;
329 self.nextthink = time;
331 makevectors(self.owner.v_angle);
335 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
336 if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
338 if(autocvar_g_balance_electro_primary_ammo)
340 if(autocvar_g_balance_electro_reload_ammo)
342 dt = min(dt, self.owner.clip_load / autocvar_g_balance_electro_primary_ammo);
343 self.owner.clip_load = max(0, self.owner.clip_load - autocvar_g_balance_electro_primary_ammo * frametime);
344 self.owner.electro_load = self.owner.clip_load;
348 dt = min(dt, self.owner.ammo_cells / autocvar_g_balance_electro_primary_ammo);
349 self.owner.ammo_cells = max(0, self.owner.ammo_cells - autocvar_g_balance_electro_primary_ammo * frametime);
354 W_SetupShot_Range(self.owner, TRUE, 0, "", 0, autocvar_g_balance_electro_primary_damage * dt, autocvar_g_balance_electro_primary_range);
355 WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
361 force = w_shotdir * autocvar_g_balance_electro_primary_force + '0 0 1' * autocvar_g_balance_electro_primary_force_up;
363 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));
365 if(accuracy_isgooddamage(self.owner, trace_ent))
366 accuracy_add(self.owner, WEP_ELECTRO, 0, autocvar_g_balance_electro_primary_damage * dt * f);
367 Damage (trace_ent, self.owner, self.owner, autocvar_g_balance_electro_primary_damage * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
369 W_Plasma_TriggerCombo(trace_endpos, autocvar_g_balance_electro_primary_comboradius, self.owner);
372 if(w_shotorg != self.hook_start)
375 self.hook_start = w_shotorg;
377 if(w_shotend != self.hook_end)
380 self.hook_end = w_shotend;
384 // experimental lightning gun
385 void W_Electro_Attack3 (void)
387 // only play fire sound if 0.5 sec has passed since player let go the fire button
388 if(time - self.prevlgfire > 0.5)
389 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
391 entity beam, oldself;
393 self.lgbeam = beam = spawn();
394 beam.classname = "lgbeam";
395 beam.solid = SOLID_NOT;
396 beam.think = lgbeam_think;
398 beam.movetype = MOVETYPE_NONE;
399 beam.shot_spread = 0;
400 beam.bot_dodge = TRUE;
401 beam.bot_dodgerating = autocvar_g_balance_electro_primary_damage;
402 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
412 weapon_action(WEP_ELECTRO, WR_PRECACHE);
413 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
414 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
415 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
416 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
419 void spawnfunc_weapon_electro (void)
421 weapon_defaultspawnfunc(WEP_ELECTRO);
424 void w_electro_checkattack()
426 if(self.electro_count > 1)
427 if(self.BUTTON_ATCK2)
428 if(weapon_prepareattack(1, -1))
431 self.electro_count -= 1;
432 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
439 .float bot_secondary_electromooth;
440 .float BUTTON_ATCK_prev;
441 float w_electro(float req)
446 self.BUTTON_ATCK=FALSE;
447 self.BUTTON_ATCK2=FALSE;
448 if(vlen(self.origin-self.enemy.origin) > 1000)
449 self.bot_secondary_electromooth = 0;
450 if(self.bot_secondary_electromooth == 0)
454 if(autocvar_g_balance_electro_primary_speed)
455 shoot = bot_aim(autocvar_g_balance_electro_primary_speed, 0, autocvar_g_balance_electro_primary_lifetime, FALSE);
457 shoot = bot_aim(1000000, 0, 0.001, FALSE);
461 self.BUTTON_ATCK = TRUE;
462 if(random() < 0.01) self.bot_secondary_electromooth = 1;
467 if(bot_aim(autocvar_g_balance_electro_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_electro_secondary_lifetime, TRUE))
469 self.BUTTON_ATCK2 = TRUE;
470 if(random() < 0.03) self.bot_secondary_electromooth = 0;
474 else if (req == WR_THINK)
476 if(autocvar_g_balance_electro_reload_ammo) // forced reload
478 if(autocvar_g_balance_electro_lightning)
480 if(self.clip_load > 0)
483 else if(self.clip_load >= autocvar_g_balance_electro_primary_ammo)
485 if(self.clip_load >= autocvar_g_balance_electro_secondary_ammo)
494 if (self.BUTTON_ATCK)
496 if(autocvar_g_balance_electro_lightning)
497 if(self.BUTTON_ATCK_prev)
499 // prolong the animtime while the gun is being fired
500 if(self.animstate_startframe == self.anim_shoot_x && self.animstate_numframes == self.anim_shoot_y)
501 weapon_thinkf(WFRAME_DONTCHANGE, autocvar_g_balance_electro_primary_animtime, w_ready);
503 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
505 if (weapon_prepareattack(0, (autocvar_g_balance_electro_lightning ? 0 : autocvar_g_balance_electro_primary_refire)))
507 if(autocvar_g_balance_electro_lightning)
509 if ((!self.lgbeam) || wasfreed(self.lgbeam))
513 if(!self.BUTTON_ATCK_prev)
515 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
516 self.BUTTON_ATCK_prev = 1;
522 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
526 if(autocvar_g_balance_electro_lightning)
528 if (self.BUTTON_ATCK_prev != 0)
530 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_electro_primary_animtime, w_ready);
531 ATTACK_FINISHED(self) = time + autocvar_g_balance_electro_primary_refire * W_WeaponRateFactor();
533 self.BUTTON_ATCK_prev = 0;
536 if (self.BUTTON_ATCK2)
538 if (time >= self.electro_secondarytime)
539 if (weapon_prepareattack(1, autocvar_g_balance_electro_secondary_refire))
542 self.electro_count = autocvar_g_balance_electro_secondary_count;
543 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_electro_secondary_animtime, w_electro_checkattack);
544 self.electro_secondarytime = time + autocvar_g_balance_electro_secondary_refire2 * W_WeaponRateFactor();
549 else if (req == WR_PRECACHE)
551 precache_model ("models/weapons/g_electro.md3");
552 precache_model ("models/weapons/v_electro.md3");
553 precache_model ("models/weapons/h_electro.iqm");
554 precache_sound ("weapons/electro_bounce.wav");
555 precache_sound ("weapons/electro_fire.wav");
556 precache_sound ("weapons/electro_fire2.wav");
557 precache_sound ("weapons/electro_impact.wav");
558 precache_sound ("weapons/electro_impact_combo.wav");
559 precache_sound ("weapons/reload.wav");
560 if(autocvar_g_balance_electro_lightning)
562 precache_sound ("weapons/lgbeam_fire.wav");
565 else if (req == WR_SETUP)
567 weapon_setup(WEP_ELECTRO);
568 W_Electro_SetAmmoCounter();
570 else if (req == WR_CHECKAMMO1)
572 if(autocvar_g_balance_electro_lightning)
574 ammo_amount = !autocvar_g_balance_electro_primary_ammo || (self.ammo_cells > 0);
575 if(autocvar_g_balance_electro_lightning)
576 ammo_amount += self.electro_load > 0;
580 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_primary_ammo;
581 if(autocvar_g_balance_electro_lightning)
582 ammo_amount += self.electro_load >= autocvar_g_balance_electro_primary_ammo;
586 else if (req == WR_CHECKAMMO2)
588 ammo_amount = self.ammo_cells >= autocvar_g_balance_electro_secondary_ammo;
589 ammo_amount += self.electro_load >= autocvar_g_balance_electro_secondary_ammo;
592 else if (req == WR_RESETPLAYER)
594 self.electro_secondarytime = time;
596 // all weapons must be fully loaded when we spawn
597 self.electro_load = autocvar_g_balance_electro_reload_ammo;
599 else if (req == WR_RELOAD)
607 float w_electro(float req)
609 if(req == WR_IMPACTEFFECT)
612 org2 = w_org + w_backoff * 6;
613 if(w_deathtype & HITTYPE_SECONDARY)
615 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
617 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
621 if(w_deathtype & HITTYPE_BOUNCE)
623 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
624 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
626 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
630 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
632 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
636 else if(req == WR_PRECACHE)
638 precache_sound("weapons/electro_impact.wav");
639 precache_sound("weapons/electro_impact_combo.wav");
641 else if (req == WR_SUICIDEMESSAGE)
643 if(w_deathtype & HITTYPE_SECONDARY)
644 w_deathtypestring = _("%s could not remember where they put plasma");
646 w_deathtypestring = _("%s played with plasma");
648 else if (req == WR_KILLMESSAGE)
650 if(w_deathtype & HITTYPE_SECONDARY)
652 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
653 w_deathtypestring = _("%s just noticed %s's blue ball");
654 else // unchecked: BOUNCE
655 w_deathtypestring = _("%s got in touch with %s's blue ball");
659 if(w_deathtype & HITTYPE_BOUNCE) // combo
660 w_deathtypestring = _("%s felt the electrifying air of %s's combo");
661 else if(w_deathtype & HITTYPE_SPLASH)
662 w_deathtypestring = _("%s got too close to %s's blue beam");
664 w_deathtypestring = _("%s was blasted by %s's blue beam");