Jump to content
Sign in to follow this  
mattsmith94

FiredNear Event handler.

Recommended Posts

Is there a way of extending the range of the fired near event handler. I am looking to be able to detect a firer with in the range of up to 1km minimum. 

 

Thanks in advance

Share this post


Link to post
Share on other sites
this addEventHandler ["FiredNear", "if (drone1 distance (_this select 1) < 3500) then {hint 'unit in range';}"]

this is my current init line above in the the drone (drone1) how ever even if I change it to the following bellow

this addEventHandler ["FiredNear", "if (drone1 distance (_this select 1) > 1000) then {hint 'unit in range';}"]

 it doesnt seem to make a difference, the range still seems limited to 50m 

 

Again thanks to anyone who can shead some light on this

Share this post


Link to post
Share on other sites

because I want to have unit A ... a drone moving and detecting fire with in 1km .. i tried using fired but it ment needing to add an event handler to every other unit in the game.

Share this post


Link to post
Share on other sites

u only need to add the fired EH to every unit within 1000 m of the drone. if a unit leaves that circle u can delete the EH from it.

II know that not a good solution because u need an endless loop for it which should be avoided by the use of an EH.

Share this post


Link to post
Share on other sites

Exactly. What's stopping you from doing it?

Eventhandlers are the only performance friendly way to achieve what you want.

 

addEH.sqf:

somecondition= true;
_allUnits = allUnits;

while {somecondition} do {

    {

        if (_x getvariable ["MyFiringEH",-1] isEqualTo -1) then {

            _eventHandlerID = _x addEventHandler ["Fired",{"yourcodeHere"}];
            _x setvariable ["MyFiringEH",_eventHandlerID];

        };

    } foreach _allUnits;

    waituntil {sleep 1;!(_allUnits isEqualTo allUnits)};
    _allUnits = allUnits;

};

{

_x removeEventHandler ["Fired",(_x getvariable ["MyFiringEH",-1])];

} foreach allUnits;


Not that hard and shouldn't cost any performance unless you're running thousands of units (you won't).

Once somecondition turns false the eventhandlers will automatically be removed from all units.

 

Cheers

  • Like 1

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  

×