Jump to content

Recommended Posts

hi guys,

 

im trying to attach an Eventhandler to a plane, so when it is destroyed, all usermade actions get removed.

The script is run by an action.

Here is the script:

Spoiler

_plane = _this select 0;
_id = _this select 2;

if (!Transplanealive) then {
	Transplanealive = true;
	publicVariable "Transplanealive";
	_plane addAction ["load box","PATH"];
	_plane addAction ["Airshow","PATH"];
	_plane removeAction _id;
	_plane addEventHandler ["Killed",{
		Transplanealive = false;
		publicVariable "Transplanealive";
		removeAllActions _plane;
		_plane removeEventHandler ["Killed",0];
		}];
	}
	else {
	hint "You already own a transportplane!";
	};

 

am i missing something?

Share this post


Link to post
Share on other sites

yep, i defined it in the ini.sqf.

If it wasnt defined there would be an error message, but the script works, except for the eventhandler.

Share this post


Link to post
Share on other sites
1 minute ago, feldruebe said:

yep, i defined it in the ini.sqf.

If it wasnt defined there would be an error message, but the script works, except for the eventhandler.

Right, I'm not quite too sure either. Have you tried adding the event handler outside of the if statement?

it'll fire similarly.

Share this post


Link to post
Share on other sites
1 minute ago, Midnighters said:

Right, I'm not quite too sure either. Have you tried adding the event handler outside of the if statement?

it'll fire similarly.

Ok I tried it like this

Spoiler

_plane = _this select 0;
_id = _this select 2;

_plane addEventHandler ["Killed",{
	Transplanealive = false;
	publicVariable "Transplanealive";
	removeAllActions _plane;
	_plane removeEventHandler ["Killed",0];
	}];
		
if (!Transplanealive) then {
	Transplanealive = true;
	publicVariable "Transplanealive";
	_plane addAction ["load box","PATH"];
	_plane addAction ["Airshow","PATH"];
	_plane removeAction _id;
	}
	else {
	hint "You already own a transportplane!";
	};

 

same results :\

Share this post


Link to post
Share on other sites

Hmmm okay. Let's do some trial and error work here.

try and add a hint after the vehicle is killed.

see if it even triggers after being killed.

Share this post


Link to post
Share on other sites
2 minutes ago, feldruebe said:

The EH seems to work, the hint got printed

Hmm, well. Everything seems to be okay visually to what I see.

 

Share this post


Link to post
Share on other sites

try


 

_plane addMPEventHandler ["MPKilled",
{
	_plane = _this select 0;
	removeAllActions _plane;
	if (!local _plane) exitWith {};
	_plane removeMPEventHandler ["MPKilled", _thisEventHandler];
	Transplanealive = false;
	publicVariable "Transplanealive";
}];

 

Share this post


Link to post
Share on other sites
42 minutes ago, killzone_kid said:

try


 


_plane addMPEventHandler ["MPKilled",
{
	_plane = _this select 0;
	removeAllActions _plane;
	if (!local _plane) exitWith {};
	_plane removeMPEventHandler ["MPKilled", _thisEventHandler];
	Transplanealive = false;
	publicVariable "Transplanealive";
}];

 

There you go!

Share this post


Link to post
Share on other sites
17 hours ago, killzone_kid said:

try


 


_plane addMPEventHandler ["MPKilled",
{
	_plane = _this select 0;
	removeAllActions _plane;
	if (!local _plane) exitWith {};
	_plane removeMPEventHandler ["MPKilled", _thisEventHandler];
	Transplanealive = false;
	publicVariable "Transplanealive";
}];

 

Ok thanks, it works! But how?

I guess _plane = _this select 0; redefines _plane in the eventhandler as the object the EH is attached to.

But what is _thisEventHandler? The ID of this specific EH?

And what is the line if (_plane not local) exitWith{}; doing?

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

×