Jump to content
cc_kronus

help with eventhandler "engine".

Recommended Posts

Hi I need some help with the precise syntax of an Eventhandler but I don't know programming and need help with the precise syntax. 

 

I want to insert in the init of a helicopter than when it switches its engine off, it kicks out of the vehicle all players in cargo. 

 

According to Arma wiki

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Engine

 

the init shoul be something like this.

 

This addeventhandler "engine" [this, false] { moveOut this } forEach crew this;

 

But I can't make it work. Any idea of what I am doing wrong?

Share this post


Link to post
Share on other sites

Hey there,

let me try to help you on that:

_vehicle = _this; // for use within the mission.sqfm
_vehicle = cursorObject; //When you look at something and want it to be added there
_vehicle = (vehicle player); //When you sit in the vehicle and you want to add it to it

_vehicle addEventHandler ["Engine", {hint format["This vehicle: %1, not as the engine state %2",str(_this select 0),str(_this select 1)];}];

When you want to kick everybody out if the engine is turned off, for example, do this:

_vehicle addEventHandler ["Engine", {if(!(_this select 1))then{{moveOut _x;} foreach (crew (_this select 0));};}]

 

I hope that hep you out

 

Regards Arkensor

Share this post


Link to post
Share on other sites
this addEventHandler [
	"Engine", 
	{ 
		params ["_vehicle", "_engineOn"];
		if(!_engineOn) then {
			{moveOut _x} forEach crew _vehicle;
		};
	}
];

 

 

 

Share this post


Link to post
Share on other sites

Sorry mates, but no joy this time. 

 

@Arkensor

 

I got lost with your first part. 

_vehicle = _this; // for use within the mission.sqfm
_vehicle = cursorObject; //When you look at something and want it to be added there
_vehicle = (vehicle player); //When you sit in the vehicle and you want to add it to it

_vehicle addEventHandler ["Engine", {hint format["This vehicle: %1, not as the engine state %2",str(_this select 0),str(_this select 1)];}];

I should include this in the mission.sqm?? Where??  

 

going back to the init :

 

it gives an error:

'|#| _vehicle addeventhandler ["engine....

Error undefined variable in expression: _vehicle

the code is to be used on the init of the helicopter.  Please, excuse my ignorance, as my programming ability is close to a negative number, rather than zero, but would'nt it be this  instead of _vehicle?

 

@mrcurry

Thanks, for your reply, but unfortunately your proposed solution also produces an error.

 

it gives an error on  ...   if(!|#|_engineOn) ...

Error Undefined variable in expression _engineOn

 

BI say:

  • vehicle: Object - Vehicle the event handler is assigned to
  • engineState: Boolean - True when the engine is turned on, false when turned off

Shouldn't the engine state just be true or false? sorry if I am proposing a nonsense, as said before, I am lost with the code for this game. 

 

Share this post


Link to post
Share on other sites
15 hours ago, cc_kronus said:

Sorry mates, but no joy this time. 

 

@Arkensor

 

I got lost with your first part. 


_vehicle = _this; // for use within the mission.sqfm
_vehicle = cursorObject; //When you look at something and want it to be added there
_vehicle = (vehicle player); //When you sit in the vehicle and you want to add it to it

_vehicle addEventHandler ["Engine", {hint format["This vehicle: %1, not as the engine state %2",str(_this select 0),str(_this select 1)];}];

I should include this in the mission.sqm?? Where??  

 

going back to the init :

 

it gives an error:

'|#| _vehicle addeventhandler ["engine....

Error undefined variable in expression: _vehicle

the code is to be used on the init of the helicopter.  Please, excuse my ignorance, as my programming ability is close to a negative number, rather than zero, but would'nt it be this  instead of _vehicle?

 

I think that the intended implementation of @Arkensor's method (first part) is to be a script inside the mission folder rather than directly into the vehicles init field, so for that kind of situation, you wouldn't use the this keyword to add the handler - you'd refer to the vehicle object itself, which is what _vehicle = _this is doing - assigning the object that called the script to run into a variable. @mrcurry 's method however is intended for the init field, but you're getting that error. I'm assuming it has something to do with the params command being used, but I don't know.

 

You can just use @Arkensor 's example (second part), and instead of using _vehicle, use this. And as he also does, just use the passed arguments (vehicle, engineState) using _this select 0, and _this select 1.

 

I can't format code because of my current OS and browser, but here's the line you'd put into the init field.

 

this addEventHandler ["Engine", {if(!(_this select 1)) then {{moveOut _x;}foreach (crew (_this select 0));};}];

 

Share this post


Link to post
Share on other sites
16 hours ago, cc_kronus said:

Thanks, for your reply, but unfortunately your proposed solution also produces an error.

 

it gives an error on  ...   if(!|#|_engineOn) ...

Error Undefined variable in expression _engineOn

 

BI say:

  • vehicle: Object - Vehicle the event handler is assigned to
  • engineState: Boolean - True when the engine is turned on, false when turned off

Shouldn't the engine state just be true or false? sorry if I am proposing a nonsense, as said before, I am lost with the code for this game. 

 

 

I just re-tested it on my end and it's working fine. Like X Pro said the code is intended to be put in the vehicle's init as is, no change required.

 

The engine state is a boolean (true/false). All params does is parse it into a variable, in our case _engineOn, so we can use it in an easy and readable way.

Share this post


Link to post
Share on other sites

@X Pro Octane

@mrcurry

OK,  it now works with your codes, (I may have been doing sombething wrong before)  but it also ejects the crew (pilot, copilot and chief), and the pilot does not reenter the helicopter, rendering the helicopter as "combat innefective" when I try to recall it with ALiVE's player combat support.  Could the code eject/kick only players? (or just the units assigned as cargo?)

Share this post


Link to post
Share on other sites
2 hours ago, cc_kronus said:

@X Pro Octane

@mrcurry

OK,  it now works with your codes, (I may have been doing sombething wrong before)  but it also ejects the crew (pilot, copilot and chief), and the pilot does not reenter the helicopter, rendering the helicopter as "combat innefective" when I try to recall it with ALiVE's player combat support.  Could the code eject/kick only players? (or just the units assigned as cargo?)

this addEventHandler [
	"Engine", 
	{ 
		params ["_vehicle", "_engineOn"];
		if( !_engineOn ) then {
			{ 
				assignedVehicleRole _x params [["_vehicleRole", ""]];
				if( isPlayer _x or _vehicleRole == "Cargo" ) then { moveOut _x }; 
			} forEach crew _vehicle;
		};
	}
];

Just a simple check in the forEach loop.

EDIT:

Added support for kicking out AI assigned as cargo

EDIT 2:
An additional way would be to check the unit against the pilot's group. As long you don't have cargo units joining the crew's group (seems unlikely) this should be a safer approach.

this addEventHandler [
	"Engine", 
	{ 
		params ["_vehicle", "_engineOn"];
		if( !_engineOn ) then {
			private _pilotGroup = group driver _vehicle;
			{ 
				if( group _x != _pilotGroup ) then { moveOut _x }; 
			} forEach crew _vehicle;
		};
	}
];

 

Share this post


Link to post
Share on other sites

@mrcurry

 

Works like a dream, I do not know how to thank you for your help. I have been after this for weeks.  The medal is for you, mate!.

 

 

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

×