Jump to content
Sign in to follow this  
scajolly

a setVariable only for whenever a pilot is in an aircraft

Recommended Posts

Hello, qualified editors!

I sure need some more help. I have a command for my pilots -- this setVariable ["ace_w_allow_dam",0] -- which disables ACE's damage system for the unit. This way aircraft can take a bit of flak or be mildly damaged before it has anything to say. I found it quite unrealistic how pilots would pass out after a few shots to the airframe, considering real life's not quite like that. Now to my question:

How can I make this setVariable happen for all the pilots I want in my multiplayer game, but only when they enter aircraft? Preferably, the script should take into consideration that both pilots and airframes can respawn - otherwise I'd have gone ahead and done individual checks on each airframe, admittedly quite cumbersome.

If you have any advice I'd be very grateful. Thank you in advance!

Share this post


Link to post
Share on other sites

How about using a "getin" eventhandler to set the variable when they get in an aircraft. You would need to monitor when they get out/eject though to change the variable and allow them to take damage.

Share this post


Link to post
Share on other sites

Just worked this out for someone else:

 {if (side _x == civilian && _x isKindOf "Air") then {_x addEventHandler ["GetIn", "(_this select 0) setVariable ['ace_w_allow_dam',0]"];}} forEach vehicles;

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#GetIn

Should add it to all empty aircraft.

Untested but has a reasonable chance of success, I hope!

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites
Just worked this out for someone else:

 {if (side _x == civilian && _x isKindOf "Air") then {_x addEventHandler ["GetIn", "(_this select 0) setVariable ['ace_w_allow_dam',0]"];}} forEach vehicles;

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#GetIn

Should add it to all empty aircraft.

Untested but has a reasonable chance of success, I hope!

Hello Mattar, thank you for your help but it has failed to work. I put myself as a pilot on the ground, next to me an AH-1 Cobra, and I take off to be shot down shortly after by the enemy SAM. I put both

{if (side _x == civilian && _x isKindOf "Air") then {_x addEventHandler ["GetIn", "(_this select 0) setVariable ['ace_w_allow_dam',0]"];}} forEach vehicles;

and

{if (side _x == west && _x isKindOf "Air") then {_x addEventHandler ["GetIn", "(_this select 0) setVariable ['ace_w_allow_dam',0]"];}} forEach vehicles;

with 'West' in, but it failed to work. The pilot is the one in need of the variable, mind - not the vehicles.

Share this post


Link to post
Share on other sites

Ahh - sorry thought it was the vehicle that required it.

If you look at the getIN EH it passes an array [vehicle, position, unit] so you need to select the right thingy - _this select 2:

try this if the vehicle starts empty:

{if (side _x == CIVILIAN && _x isKindOf "Helicopter") then {_x addEventHandler ["GetIn", "if ((_this select 1) == 'driver') then {(_this select 2) setVariable ['ace_w_allow_dam',0]}"];};} forEach vehicles;

Change CIVILIAN to WEST if there is an AI in gunners seat

Can't test ACE but similar code works - eg this turns light on only if you get in pilots seat:

{if (side _x == CIVILIAN && _x isKindOf "Helicopter") then {_x addEventHandler ["GetIn", "if ((_this select 1) == 'driver') then {(_this select 2) action ['lightOn', (_this select 0)] }"];};} forEach vehicles;

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

You could always just run a script locally on each pilot:

In init.sqf:

if (local player && typeOf player == "pilotClassName") then {

while {true} do {

	waitUntil {vehicle player isKindOf "AIR" && player == driver (vehicle player)};
	player setVariable ['ace_w_allow_dam',0];

	waitUntil {!(vehicle player isKindOf "AIR")};
	player setVariable ['ace_w_allow_dam',1];
};
};

Depends if your happy with it checking as often as waituntil does... you could always slow it down with a while loop with a sleep in it, or create a trigger to check when the pilot gets out if your extremely concerned about the resource usage. Soo many possibilities.

Or if you want to use the eventhandler system:

plane1 addEventhandler ["GETIN", {

if (!local player) exitwith {};        

_aircraft = _this select 0;

if (player != driver _aircraft) exitwith {};

player setVariable ['ace_w_allow_dam',0];

[] spawn {
	waitUntil {!(vehicle player isKindOf "AIR")};
	player setVariable ['ace_w_allow_dam',1];
};
}];

It would be good if there was an "EJECT" EH which would save the constant monitoring of the whether the pilot is still in the aircraft, but there isn't.

Anyway, tested both systems (locally only atm) and they both work. Personally, for simplicity, I would use the first one I think. Hope that's helpful.

Oh and I don't know if you would need that variable to be set globally or just locally, player setVariable ['ace_w_allow_dam',0,true]; sets it globally if need be.

Edited by Foxy

Share this post


Link to post
Share on other sites

This works perfectly, thank you Mattar! How, then, do you think I should best monitor the pilot getting out so I can set the variable to 1 again?

Share this post


Link to post
Share on other sites

{
if (side _x == CIVILIAN && _x isKindOf "Air") then {

	_x addEventHandler ["GetIn", "if ((_this select 1) == 'driver') then {

		_pilot = _this select 2;
		_pilot setVariable ['ace_w_allow_dam', 0];

		[_pilot] spawn {
			_pilot = _this select 0;
			waitUntil {!(vehicle _pilot isKindOf 'Air')};
			_pilot setVariable ['ace_w_allow_dam', 1];
		};
	}"];
};

} forEach vehicles;

Adjusted Mattars solution to include the getout/eject check. Switched it to check for all aircraft rather than just helicopters since I was testing on a plane... obviously if you want it to be applied to just choppers then switch "Air" back to helicopters.

Bear in mind you would need to re-add the eventhandler to the any aircraft that respawns using this system.

Share this post


Link to post
Share on other sites

Just use the getOut event handler and change the 0 to a 1:

{if (side _x == CIVILIAN && _x isKindOf "Helicopter") then {_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {(_this select 2) setVariable ['ace_w_allow_dam',1]}"];};} forEach vehicles;

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#GetOut

(I don't do much MP scripting but thought EH's were automatically readded after respawn? It says this on the wiki:

Multiplayer: Event handlers are persistent (i.e. they stay attached to a unit, even after it dies and respawns).

http://community.bistudio.com/wiki/addEventHandler

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

The getout eventhandler won't work if the pilot ejects (unless the getout eventhandler covers ejecting too, i'll check). Since vehicle respawn scripts don't recreate the same vehicle but spawn a new one the eventhandler won't be added to the new aircraft. Thats why I said it would be good to have an eject eventhandler too. That's my understanding anyway.

EDIT: Ok so the getout eventhandler does cover ejecting too! Cool! But you do need to re-add the eventhandler using a vehicle respawn script that creates a new vehicle. Or is there a way round this? I don't think so, but I've already been wrong once today...

Soo,

{
if (side _x == CIVILIAN && _x isKindOf "Air") then {

	_x addEventHandler ["GetIn", "if ((_this select 1) == 'driver') then {
		(_this select 2) setVariable ['ace_w_allow_dam', 0];
	}"];

	_x addEventHandler ["GetOut", "if ((_this select 1) == 'driver') then {
		(_this select 2) setVariable ['ace_w_allow_dam', 1];
	}"];
};

} forEach vehicles;

Out of curiosity which vehicle respawn script are you using?

Edited by Foxy

Share this post


Link to post
Share on other sites

GetOut EH works with eject - already tested - not sure about the respawn thing, Foxy is right - it probably only refers to units (players) not vehicles so you would need to re-add it for a new vehicle.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Thats really good to know about getout EH though... saves all that constant monitoring! Also regarding MP... these eventhandlers have global effects so they should probably only be added serverside I guess. I don't have access to a server atm to test.

Share this post


Link to post
Share on other sites

I attempted your solution above directly pasted into the helicopter. It did not work. I then had a suspicion that you were not wrong, but that the setVariable would not permit a change (for whatever reason). It seems once you've set allow_dam to 0, you can't set it back to 1. I guess this is the end of my issue, and I'll simply have to circumvent poor wound handling some other way. I appreciate all the help!

To answer your question, now irrelephant, I am using Simple Vehicle Respawn Script v1.7 by Tophe of Östgöta Ops [OOPS]

if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do 
{	
sleep (2 + random 10);
     if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
	if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then 
	{
		_timeout = time + _deserted;
		sleep 0.1;
	 	waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
		if ({alive _x} count crew _unit > 0) then {_dead = false}; 
		if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true}; 
		if !(alive _unit) then {_dead = true; _nodelay = false}; 
	};
};

// Respawn vehicle
     if (_dead) then 
{	
	if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
	if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
	if (_explode) then {_effect = "M_TOW_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
	sleep 0.1;

	deleteVehicle _unit;
	sleep 2;
	_unit = _type createVehicle _position;
	_unit setPosASL _position;
	_unit setDir _dir;

	if (_haveinit) then 
				{_unit setVehicleInit format ["%1;", _unitinit];
				processInitCommands;};
	if (_hasname) then 
				{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];
				processInitCommands;};
	_dead = false;

	// Check respawn amount
	if !(_noend) then {_rounds = _rounds + 1};
	if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
};

Share this post


Link to post
Share on other sites

Any chance you could send me the test mission? I'm quite curious about this.

Have you tried using allowDamage instead of the ACE system?

Edited by Foxy

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  

×