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 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) / cvar("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, cvar("g_balance_electro_secondary_damage"), cvar("g_balance_electro_secondary_edgedamage"), cvar("g_balance_electro_secondary_radius"), world, cvar("g_balance_electro_secondary_force"), self.projectiledeathtype, other);
46 W_Plasma_TriggerCombo(self.origin, cvar("g_balance_electro_primary_comboradius"), self.owner);
47 RadiusDamage (self, self.owner, cvar("g_balance_electro_primary_damage"), cvar("g_balance_electro_primary_edgedamage"), cvar("g_balance_electro_primary_radius"), world, cvar("g_balance_electro_primary_force"), self.projectiledeathtype, other);
53 void W_Plasma_Explode_Combo (void)
55 W_Plasma_TriggerCombo(self.origin, cvar("g_balance_electro_combo_comboradius"), self.owner);
57 self.event_damage = SUB_Null;
58 RadiusDamage (self, self.owner, cvar("g_balance_electro_combo_damage"), cvar("g_balance_electro_combo_edgedamage"), cvar("g_balance_electro_combo_radius"), world, cvar("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)
65 if (other.takedamage == DAMAGE_AIM) {
68 spamsound (self, CHAN_PROJECTILE, "weapons/electro_bounce.wav", VOL_BASE, ATTN_NORM);
69 self.projectiledeathtype |= HITTYPE_BOUNCE;
73 void W_Plasma_TouchExplode (void)
79 void W_Plasma_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
83 // note: combos are usually triggered by W_Plasma_TriggerCombo, not damage
84 self.health = self.health - damage;
87 self.takedamage = DAMAGE_NO;
88 self.nextthink = time;
89 if (inflictor.classname == "plasma_chain" || inflictor.classname == "plasma_prim")
91 // change owner to whoever caused the combo explosion
92 self.owner = inflictor.owner;
93 self.classname = "plasma_chain";
94 self.think = W_Plasma_Explode_Combo;
95 self.nextthink = time + min(cvar("g_balance_electro_combo_radius"), vlen(self.origin - inflictor.origin)) / cvar("g_balance_electro_combo_speed"); // delay combo chains, looks cooler
96 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bounding the length, because inflictor may be in a galaxy far far away (warpzones)
100 self.use = W_Plasma_Explode;
101 self.think = adaptor_think2use; // not _hittype_splash, as this runs "immediately"
106 void W_Electro_Attack()
110 W_SetupShot_ProjectileSize (self, '0 0 -3', '0 0 -3', FALSE, 2, "weapons/electro_fire.wav", cvar("g_balance_electro_primary_damage"));
112 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
115 proj.classname = "plasma_prim";
117 proj.bot_dodge = TRUE;
118 proj.bot_dodgerating = cvar("g_balance_electro_primary_damage");
119 proj.use = W_Plasma_Explode;
120 proj.think = adaptor_think2use_hittype_splash;
121 proj.nextthink = time + cvar("g_balance_electro_primary_lifetime");
122 PROJECTILE_MAKETRIGGER(proj);
123 proj.projectiledeathtype = WEP_ELECTRO;
124 setorigin(proj, w_shotorg);
126 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
127 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_primary_ammo");
128 proj.movetype = MOVETYPE_FLY;
129 W_SETUPPROJECTILEVELOCITY(proj, g_balance_electro_primary);
130 proj.angles = vectoangles(proj.velocity);
131 proj.touch = W_Plasma_TouchExplode;
132 setsize(proj, '0 0 -3', '0 0 -3');
133 proj.flags = FL_PROJECTILE;
135 //sound (proj, CHAN_PAIN, "weapons/electro_fly.wav", VOL_BASE, ATTN_NORM);
138 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO_BEAM, TRUE);
140 other = proj; MUTATOR_CALLHOOK(EditProjectile);
143 void W_Electro_Attack2()
147 W_SetupShot_ProjectileSize (self, '0 0 -4', '0 0 -4', FALSE, 2, "weapons/electro_fire2.wav", cvar("g_balance_electro_secondary_damage"));
148 w_shotdir = v_forward; // no TrueAim for grenades please
150 pointparticles(particleeffectnum("electro_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
153 proj.classname = "plasma";
155 proj.use = W_Plasma_Explode;
156 proj.think = adaptor_think2use_hittype_splash;
157 proj.bot_dodge = TRUE;
158 proj.bot_dodgerating = cvar("g_balance_electro_secondary_damage");
159 proj.nextthink = time + cvar("g_balance_electro_secondary_lifetime");
160 PROJECTILE_MAKETRIGGER(proj);
161 proj.projectiledeathtype = WEP_ELECTRO | HITTYPE_SECONDARY;
162 setorigin(proj, w_shotorg);
164 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
165 self.ammo_cells = self.ammo_cells - cvar("g_balance_electro_secondary_ammo");
166 //proj.glow_size = 50;
167 //proj.glow_color = 45;
168 proj.movetype = MOVETYPE_BOUNCE;
169 W_SETUPPROJECTILEVELOCITY_UP(proj, g_balance_electro_secondary);
170 proj.touch = W_Plasma_Touch;
171 setsize(proj, '0 0 -4', '0 0 -4');
172 proj.takedamage = DAMAGE_YES;
173 proj.damageforcescale = cvar("g_balance_electro_secondary_damageforcescale");
174 proj.health = cvar("g_balance_electro_secondary_health");
175 proj.event_damage = W_Plasma_Damage;
176 proj.flags = FL_PROJECTILE;
181 copyentity(proj, p2);
182 setmodel(p2, "models/ebomb.mdl");
183 setsize(p2, proj.mins, proj.maxs);
186 CSQCProjectile(proj, TRUE, PROJECTILE_ELECTRO, FALSE); // no culling, it has sound
188 other = proj; MUTATOR_CALLHOOK(EditProjectile);
191 .vector hook_start, hook_end;
192 float lgbeam_send(entity to, float sf)
194 WriteByte(MSG_ENTITY, ENT_CLIENT_LGBEAM);
196 if(sound_allowed(MSG_BROADCAST, self.owner))
198 WriteByte(MSG_ENTITY, sf);
201 WriteByte(MSG_ENTITY, num_for_edict(self.owner));
202 WriteCoord(MSG_ENTITY, cvar("g_balance_electro_primary_range"));
206 WriteCoord(MSG_ENTITY, self.hook_start_x);
207 WriteCoord(MSG_ENTITY, self.hook_start_y);
208 WriteCoord(MSG_ENTITY, self.hook_start_z);
212 WriteCoord(MSG_ENTITY, self.hook_end_x);
213 WriteCoord(MSG_ENTITY, self.hook_end_y);
214 WriteCoord(MSG_ENTITY, self.hook_end_z);
222 self.owner.prevlgfire = time;
223 if (self != self.owner.lgbeam)
228 if (self.owner.weaponentity.state != WS_INUSE || (self.owner.ammo_cells <= 0 && !(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)) || self.owner.deadflag != DEAD_NO || !self.owner.BUTTON_ATCK)
230 if(self == self.owner.lgbeam)
231 self.owner.lgbeam = world;
236 self.nextthink = time;
238 makevectors(self.owner.v_angle);
242 if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
244 if(cvar("g_balance_electro_primary_ammo"))
246 dt = min(dt, self.owner.ammo_cells / cvar("g_balance_electro_primary_ammo"));
247 self.owner.ammo_cells = max(0, self.owner.ammo_cells - cvar("g_balance_electro_primary_ammo") * frametime);
251 W_SetupShot_Range(self.owner, TRUE, 0, "", cvar("g_balance_electro_primary_damage") * dt, cvar("g_balance_electro_primary_range"));
252 WarpZone_traceline_antilag(self.owner, w_shotorg, w_shotend, MOVE_NORMAL, self.owner, ANTILAG_LATENCY(self.owner));
258 force = w_shotdir * cvar("g_balance_electro_primary_force") + '0 0 1' * cvar("g_balance_electro_primary_force_up");
260 f = ExponentialFalloff(cvar("g_balance_electro_primary_falloff_mindist"), cvar("g_balance_electro_primary_falloff_maxdist"), cvar("g_balance_electro_primary_falloff_halflifedist"), vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos) - w_shotorg));
262 Damage (trace_ent, self.owner, self.owner, cvar("g_balance_electro_primary_damage") * dt * f, WEP_ELECTRO, trace_endpos, force * dt);
263 Damage_RecordDamage(self.owner, WEP_ELECTRO, cvar("g_balance_electro_primary_damage") * dt * f);
265 W_Plasma_TriggerCombo(trace_endpos, cvar("g_balance_electro_primary_comboradius"), self.owner);
268 if(w_shotorg != self.hook_start)
271 self.hook_start = w_shotorg;
273 if(w_shotend != self.hook_end)
276 self.hook_end = w_shotend;
280 // experimental lightning gun
281 void W_Electro_Attack3 (void)
283 // only play fire sound if 0.5 sec has passed since player let go the fire button
284 if(time - self.prevlgfire > 0.5)
286 sound (self, CHAN_WEAPON, "weapons/lgbeam_fire.wav", VOL_BASE, ATTN_NORM);
289 entity beam, oldself;
291 self.lgbeam = beam = spawn();
292 beam.solid = SOLID_NOT;
293 beam.think = lgbeam_think;
295 beam.movetype = MOVETYPE_NONE;
296 beam.shot_spread = 0;
297 beam.bot_dodge = TRUE;
298 beam.bot_dodgerating = cvar("g_balance_electro_primary_damage");
299 Net_LinkEntity(beam, FALSE, 0, lgbeam_send);
309 weapon_action(WEP_ELECTRO, WR_PRECACHE);
310 electro_shotorigin[0] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 1);
311 electro_shotorigin[1] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 2);
312 electro_shotorigin[2] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 3);
313 electro_shotorigin[3] = shotorg_adjust_values(CL_Weapon_GetShotOrg(WEP_ELECTRO), FALSE, FALSE, 4);
316 void spawnfunc_weapon_electro (void)
318 weapon_defaultspawnfunc(WEP_ELECTRO);
321 void w_electro_checkattack()
323 if(self.electro_count > 1)
324 if(self.BUTTON_ATCK2)
325 if(weapon_prepareattack(1, -1))
328 self.electro_count -= 1;
329 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
336 .float bot_secondary_electromooth;
337 .float BUTTON_ATCK_prev;
338 float w_electro(float req)
342 self.BUTTON_ATCK=FALSE;
343 self.BUTTON_ATCK2=FALSE;
344 if(vlen(self.origin-self.enemy.origin) > 1000)
345 self.bot_secondary_electromooth = 0;
346 if(self.bot_secondary_electromooth == 0)
348 if(bot_aim(cvar("g_balance_electro_primary_speed"), 0, cvar("g_balance_electro_primary_lifetime"), FALSE))
350 self.BUTTON_ATCK = TRUE;
351 if(random() < 0.01) self.bot_secondary_electromooth = 1;
356 if(bot_aim(cvar("g_balance_electro_secondary_speed"), cvar("g_balance_grenadelauncher_secondary_speed_up"), cvar("g_balance_electro_secondary_lifetime"), TRUE))
358 self.BUTTON_ATCK2 = TRUE;
359 if(random() < 0.03) self.bot_secondary_electromooth = 0;
363 else if (req == WR_THINK)
365 if (self.BUTTON_ATCK)
367 if (weapon_prepareattack(0, (cvar("g_balance_electro_lightning") ? 0 : cvar("g_balance_electro_primary_refire"))))
369 if(cvar("g_balance_electro_lightning"))
371 if ((!self.lgbeam) || wasfreed(self.lgbeam))
375 self.BUTTON_ATCK_prev = 1;
381 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_electro_primary_animtime"), w_ready);
384 if(cvar("g_balance_electro_lightning"))
386 if (self.BUTTON_ATCK_prev != 0)
388 ATTACK_FINISHED(self) = time + cvar("g_balance_electro_primary_refire") * W_WeaponRateFactor();
390 self.BUTTON_ATCK_prev = 0;
394 if (self.BUTTON_ATCK2)
395 if (time >= self.electro_secondarytime)
396 if (weapon_prepareattack(1, cvar("g_balance_electro_secondary_refire")))
399 self.electro_count = cvar("g_balance_electro_secondary_count");
400 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_electro_secondary_animtime"), w_electro_checkattack);
401 self.electro_secondarytime = time + cvar("g_balance_electro_secondary_refire2");
404 else if (req == WR_PRECACHE)
406 precache_model ("models/weapons/g_electro.md3");
407 precache_model ("models/weapons/v_electro.md3");
408 precache_model ("models/weapons/h_electro.iqm");
409 precache_sound ("weapons/electro_bounce.wav");
410 precache_sound ("weapons/electro_fire.wav");
411 precache_sound ("weapons/electro_fire2.wav");
412 precache_sound ("weapons/electro_impact.wav");
413 precache_sound ("weapons/electro_impact_combo.wav");
414 if(cvar("g_balance_electro_lightning"))
416 precache_sound ("weapons/lgbeam_fire.wav");
419 else if (req == WR_SETUP)
420 weapon_setup(WEP_ELECTRO);
421 else if (req == WR_CHECKAMMO1)
423 if(cvar("g_balance_electro_lightning"))
424 return !cvar("g_balance_electro_primary_ammo") || (self.ammo_cells > 0);
426 return self.ammo_cells >= cvar("g_balance_electro_primary_ammo");
428 else if (req == WR_CHECKAMMO2)
429 return self.ammo_cells >= cvar("g_balance_electro_secondary_ammo");
430 else if (req == WR_RESETPLAYER)
432 self.electro_secondarytime = time;
438 float w_electro(float req)
440 if(req == WR_IMPACTEFFECT)
443 org2 = w_org + w_backoff * 6;
444 if(w_deathtype & HITTYPE_SECONDARY)
446 pointparticles(particleeffectnum("electro_ballexplode"), org2, '0 0 0', 1);
448 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
452 if(w_deathtype & HITTYPE_BOUNCE)
454 // this is sent as "primary (w_deathtype & HITTYPE_BOUNCE)" to distinguish it from (w_deathtype & HITTYPE_SECONDARY) bounced balls
455 pointparticles(particleeffectnum("electro_combo"), org2, '0 0 0', 1);
457 sound(self, CHAN_PROJECTILE, "weapons/electro_impact_combo.wav", VOL_BASE, ATTN_NORM);
461 pointparticles(particleeffectnum("electro_impact"), org2, '0 0 0', 1);
463 sound(self, CHAN_PROJECTILE, "weapons/electro_impact.wav", VOL_BASE, ATTN_NORM);
467 else if(req == WR_PRECACHE)
469 precache_sound("weapons/electro_impact.wav");
470 precache_sound("weapons/electro_impact_combo.wav");
472 else if (req == WR_SUICIDEMESSAGE)
474 if(w_deathtype & HITTYPE_SECONDARY)
475 w_deathtypestring = "%s could not remember where they put plasma";
477 w_deathtypestring = "%s played with plasma";
479 else if (req == WR_KILLMESSAGE)
481 if(w_deathtype & HITTYPE_SECONDARY)
483 if(w_deathtype & HITTYPE_SPLASH) // unchecked: BOUNCE
484 w_deathtypestring = "%s just noticed %s's blue ball";
485 else // unchecked: BOUNCE
486 w_deathtypestring = "%s got in touch with %s's blue ball";
490 if(w_deathtype & HITTYPE_BOUNCE) // combo
491 w_deathtypestring = "%s felt the electrifying air of %s's combo";
492 else if(w_deathtype & HITTYPE_SPLASH)
493 w_deathtypestring = "%s got too close to %s's blue beam";
495 w_deathtypestring = "%s was blasted by %s's blue beam";