Jump to content
Havok66

Passing unit position to a script from EventHandler

Recommended Posts

I'm trying to pass a unit's position to a script whenever it's "killed" eventhandler fires. It doesn't seem to be working as the script does not recieve it.

 

This function applies an eventhandler to all independent units.

if (isServer or isDedicated) then {
	fnc_ehkilledindependent = {
		independent_units = [];

		{
			if ((side _x) == resistance) then {
				independent_units = independent_units + [_x];
				{_x removeAllEventHandlers "killed"} forEach independent_units; 
			}; 
		} foreach allUnits;

		{_x addEventHandler ["killed", {[position this]execvm "the_script.sqf";}]} forEach independent_units; 
	};
};

I know the eventhandler properly fires for all independents when they are killed, but their position isn't passed to my script. If anyone could tell me what's wrong it would be much appreciated. Thanks!

Share this post


Link to post
Share on other sites

Try:

{_x addEventHandler ["killed", {[position _this] execvm "the_script.sqf";}]} forEach independent_units;

 

 

edit. ooops. Yeah, _this select 0 of course.

  • Like 1

Share this post


Link to post
Share on other sites
position (_this select 0)
Killed gets passed two parameters, the unit that got killed and what ever killed it, in _this variable. So you want the position of the first 0.
  • Like 1

Share this post


Link to post
Share on other sites

Try:

{_x addEventHandler ["killed", {[position _this] execvm "the_script.sqf";}]} forEach independent_units;

I also had thought that might be the problem, but it creates this error.

 8:49:02 Error in expression <[position _this]execvm "the_script.sqf";>
 8:49:02   Error position: <position _this]execvm "the_script.sqf";>
 8:49:02   Error position: Type Array, expected Object,Location

Share this post


Link to post
Share on other sites
position (_this select 0)
Killed gets passed two parameters, the unit that got killed and what ever killed it, in _this variable. So you want the position of the first 0.

 

That was it! Thank you so much. Simple mistake and it had me scratching my head for hours.

 

I should've realized when I got an error about an array type!

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

×