Jump to content

Recommended Posts

The Event Handler should be applied to the player only and this should be done client side in initPlayerLocal.sqf. This way the server don't has to handle all vehicles but each player handles its the one vehicle he uses.

 

But there is no need for an CBA EH because this all can be done with the use of the following EHs:

GetIn

GetInMan

GetOut

GetOutMan

SwitchedSeat

SwitchedSeatMan

 

This will need a complete redesign of your solution:

1. apply GetInMan in  initPlayerLocal.sqf to player

2. If GetInMan fires then apply GetIn, GetOut, GetOutMan, SwitchedSeat, SwitchedSeatMan to handle all possible cases (someone enters or leaves vehicle, someone switches seats)

3. If GetOutMan fires then delete the EHs apllied in 2.

 

Those solution with local EHs on the clients will be much less cpu consuming for the server!

 

EDIT: And yes, always precompile a script if it runs more than once!

EDIT: look at Event Scripts for information to initPlayerLocal.sqf

Share this post


Link to post
Share on other sites

Okay, I set up a basic structure for a solution with EHs but there is a lot of work to be done:

 

initPlayerLocal.sqf  // executed local on each client

_EH_handle = player addEventHandler ["GetInMan", 
{
 params ["_unit", "_role", "_vehicle", "_turret"];
 [_role, _vehicle] call INQ_fnc_initVec;
}];

initVec.sqf

params ["_role", "_vehicle"];

// detect if player switches seat
EH_SSM_handle = player addEventHandler ["SeatSwitchedMan", 
{
 params ["_unit1", "_unit2", "_vehicle"];
 [_vehicle] call INQ_fnc_seatChangeMan;
}];

// detect if player leaves vehicle
EH_GOM_handle = player addEventHandler ["GetOutMan", 
{
 params ["_vehicle", "_role", "_unit", "_turret"];
 [_vehicle] call INQ_fnc_getOutMan;
}];

// if player did not get in as driver then we only need to 
// detect if he switches seat or if he leaves the vehicle
// therefore we can exit at this point
if !((toLower _role) isEqualTo "driver") exitWith {false};

// detect if someone switches seat in vehicle
EH_SS_handle = _vehicle addEventHandler ["SeatSwitched", 
{
 params ["_unit1", "_unit2", "_vehicle"];
 [_vehicle] call INQ_fnc_seatChange;
}];

// detect if someone enters vehicle
EH_GI_handle = _vehicle addEventHandler ["GetIn", 
{
 params ["_unit", "_role", "_vehicle", "_turret"];
 [_vehicle, _role, _unit] call INQ_fnc_getIn;
}];

// detect if someone leaves vehicle
EH_GO_handle = _vehicle addEventHandler ["GetOut", 
{
 params ["_vehicle", "_role", "_unit", "_turret"];
 [_vehicle] call INQ_fnc_getOut;
}];

seatChangeMan.sqf

deletes EHs if changed to other than driver seat and applies some EHs if changed to driver seat

 

seatChange.sqf

handles the cases when someone else changes from or to gunner seat

 

getIn.sqf

handles the cases when someone else gets in.

 

getOut.sqf

handles the cases when someone else gets out.

 

getOutMan.sqf

//player left vehicle therefore all apllied EHs have to be deleted here (except GetInMan)

if !(EH_SSM_handle isEqualTo objNull) then player removeEventHandler ["SeatSwitchedMan", EH_SSM_handle];
if !(EH_SS_handle isEqualTo objNull) then _vehicle removeEventHandler ["SeatSwitched", EH_SS_handle];
if !(EH_GI_handle isEqualTo objNull) then _vehicle removeEventHandler ["GetIn", EH_GI_handle];
if !(EH_GO_handle isEqualTo objNull) then _vehicle removeEventHandler ["GetOut", EH_GO_handle];
if !(EH_GOM_handle isEqualTo objNull) then player removeEventHandler ["GetOutMan", EH_GOM_handle];

EH_SSM_handle = objNull:
EH_SS_handle = objNull;
EH_GI_handle = objNull;
EH_GO_handle = objNull;
EH_GOM_handle = objNull;

 

Share this post


Link to post
Share on other sites

Great job on this guys.  I have a similar need where I want the two turrets on back of CUP landing craft to point to the rear so I can attach crates/etc.  to the craft and hide the turrets (turning it into a civilian craft).  This script will work perfectly for that.  So thanks for this!

 

Also this thread is a great example of cooperation that makes this community great.

Share this post


Link to post
Share on other sites
5 hours ago, johnnyboy said:

Great job on this guys.  I have a similar need where I want the two turrets on back of CUP landing craft to point to the rear so I can attach crates/etc.  to the craft and hide the turrets (turning it into a civilian craft).  This script will work perfectly for that.  So thanks for this!

 

Also this thread is a great example of cooperation that makes this community great.

If you wanted to account for both turrets you could check for second seat using FullCrew and if it exists add a second AI inside turretDir.sqf .

  • Thanks 1

Share this post


Link to post
Share on other sites
On 3/15/2019 at 10:06 PM, sarogahtyp said:

Okay, I set up a basic structure for a solution with EHs but there is a lot of work to be done:

 

Thanks for the effort - I might look at doing that later but for now I'd rather not redesign the entire thing. I have put all the scripts into functions though so they precompile (updated OP). 

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

×