Jump to content
Sign in to follow this  
HallyG

EMP Grenade

Recommended Posts

Hello all, I created a little script which I am going to use in my upcoming mission which allows the player to use an IR Grenade as an EMP (not really the most ideal use of that acronym but nevertheless) to destroy any active lights or engines within a certain radius.

Currently I am adding an Event Handler to the player to check if the IR grenade is thrown and to get it's position once it has been thrown.

player addEventHandler ["Fired", 
 { 
 if (_this select 5 == "B_IR_Grenade")  
  then { 
   _this spawn { 
                _bullet = _this select 6; 
                _newpos = getPosATL _bullet; 
                while {(_newpos select 2) > .1}  
                do { 
                    _newpos = getPos _bullet; 
                    sleep 0.1; 
                    }; 
                      [_bullet] execVM "HG_CutLights.sqf"; 
                }; 
        }; 
 }]; 

This works most of the time however it does not work all of the time such as if the grenade gets stuck on a window frame or on a fence/wall. Therefore, I was wondering if there is a better way for me to check whether the grenade has stopped moving?

I thought about using isNull or checking the alive status however I have not had any luck when I tried those, although it is quite possible that I used those commands incorrectly.

For those who want to try this script out, "HG_CutLights.sqf" contains:

_AOE = _this select 0;
 _Lights =  nearestObjects [_AOE , ["Lamps_Base_F", "PowerLines_base_F","PowerLines_Small_base_F","PowerLines_Wires_base_F","Land_PowerPoleWooden_F"], 50];
 _DamageOFF = 0.95;
 _DamageON = 0.00;
 _Vehicles = nearestObjects [(getpos _AOE), ["Car"], 50];

 _CountLights = count _Lights;
 (_Lights select 0) say3D "electricity_loop";
 sleep (floor(random 3) +2);

 for "_i" from 0 to _CountLights do
 {
if (getDammage (_Lights select _i) < 0.90) then
{
	(_Lights select _i) setDamage _DamageOFF;
	sleep 0.1;
	(_Lights select _i) setDamage _DamageON;
	sleep 0.1;
	(_Lights select _i) setDamage _DamageOFF;
	sleep 0.1;
};
 };
{ 
	if (isEngineOn _x) then {_x setHit ["motor", 1]}
} foreach _Vehicles;

Again this code might not be the most efficient because I am new to scripting, so any feedback would be appreciated!:p

Some eye candy for you ;):

Share this post


Link to post
Share on other sites

Here's some more lights to add to the list

"Lamps_Base_F", 
   "Land_LampAirport_F", 
   "Land_LampSolar_F", 
   "Land_LampStreet_F", 
   "Land_LampStreet_small_F", 
   "PowerLines_base_F", 
   "Land_LampDecor_F", 
   "Land_LampHalogen_F", 
   "Land_LampHarbour_F", 
   "Land_LampShabby_F", 
   "Land_PowerPoleWooden_L_F", 
   "Land_NavigLight", 
   "Land_runway_edgelight", 
   "Land_runway_edgelight_blue_F", 
   "Land_Flush_Light_green_F", 
   "Land_Flush_Light_red_F", 
   "Land_Flush_Light_yellow_F", 
   "Land_Runway_PAPI", 
   "Land_Runway_PAPI_2", 
   "Land_Runway_PAPI_3", 
   "Land_Runway_PAPI_4", 
   "Land_fs_roof_F", // Fuel station roof lights 
   "Land_fs_sign_F"];

Although all the base ones you have should cover them all.

Just got home, can't wait to try out your script.

---------- Post added at 23:42 ---------- Previous post was at 23:09 ----------

Just tried it, works great. How can you set it so that it only lasts for a set amount of time? Like 90 seconds effective then the lights come back on? Nevermind, figured it out.

_AOE = _this select 0; 
 _Lights =  nearestObjects [_AOE , ["Lamps_Base_F", "PowerLines_base_F","PowerLines_Small_base_F","PowerLines_Wires_base_F","Land_PowerPoleWooden_F"], 150]; 
 _DamageOFF = 0.95; 
 _DamageON = 0.00; 
 _Vehicles = nearestObjects [(getpos _AOE), ["Car"], 150]; 

 _CountLights = count _Lights; 
 (_Lights select 0) say3D "electricity_loop"; 
 sleep (floor(random 3) +2); 

 for "_i" from 0 to _CountLights do 
 { 
if (getDammage (_Lights select _i) < 0.90) then 
   { 
       (_Lights select _i) setDamage _DamageOFF; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageON; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageOFF; 
       sleep 0.1; 
   }; 
 }; 
   {  
       if (isEngineOn _x) then {_x setHit ["motor", 1]} 
   } foreach _Vehicles;  

Sleep 120;

  _CountLights = count _Lights; 
 (_Lights select 0) say3D "electricity_loop"; 
 sleep (floor(random 3) +2);

for "_i" from 0 to _CountLights do 
 { 
if (getDammage (_Lights select _i) > 0.90) then 
   { 
       (_Lights select _i) setDamage _DamageON; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageOFF; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageON; 
       sleep 0.1; 
   }; 
 }; 
   {  
       if (isEngineOn _x) then {_x setHit ["motor", 1]} 
   } foreach _Vehicles;  

I just reversed the script to stop EMP after 120 seconds. Works great. I also added that electric sound to when the EMP stops working. I'd like to delete the IR strobe once it quits working, or at least disable the pulse of the IR to go along with the feel of it. Not sure how to do that though.

Edited by RTEK

Share this post


Link to post
Share on other sites

Great script, I like the effects. There's room for improvement, but your level of skill is higher than most.

_AOE = _this select 0; 
 _Lights =  nearestObjects [_AOE , ["Lamps_Base_F", "PowerLines_base_F","PowerLines_Small_base_F","PowerLines_Wires_base_F","Land_PowerPoleWooden_F"], 50]; 
 _DamageOFF = 0.95; 
 _DamageON = 0.00; 
 _Vehicles = nearestObjects [(getpos _AOE), ["Car"], 50]; 

 _CountLights = count _Lights; 
 (_Lights select 0) say3D "electricity_loop"; 
 sleep (floor(random 3) +2); 

 for "_i" from 0 to _CountLights do //this will run 1 extra time
 //replace 0 with 1 or _CountLights with (_CountLights - 1)
 { 
if (getDammage (_Lights select _i) < 0.90) then 
   { 
       (_Lights select _i) setDamage _DamageOFF; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageON; 
       sleep 0.1; 
       (_Lights select _i) setDamage _DamageOFF; 
       sleep 0.1; 
   }; 
 }; 
   {  
       if (isEngineOn _x) then {_x setHit ["motor", 1]} 
   } foreach _Vehicles;

I only saw 1 logic error in the code

_position = (_this select 0);
_AOE = 50;

{
_x say3D "electricity_loop";
_x setHit ["light_1_hitpoint", 0.97]; //all possible light hitpoints
_x setHit ["light_2_hitpoint", 0.97]; //no lights escape this
_x setHit ["light_3_hitpoint", 0.97];
_x setHit ["light_4_hitpoint", 0.97];
} forEach (nearestObjects [_position, [
"Lamps_base_F", //These are all the lights' base classes
"PowerLines_base_F",
"PowerLines_Small_base_F"
], _AOE]);

This code should have the same effect, but without the light flashing before going out and it only works with lights not vehicles. I have faith that you'll be able to reproduce the effect, though.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×