Jump to content
LCpl N. Harrison

Help Adding Event Handler (Solved)

Recommended Posts

Really at a loss here, probably should've asked sooner. Thank you in advance to anyone who helps.

 

So, I'm trying to spawn a boat in via a function executed from a server-side addon, and prevent the AI inside from dismounting when the vehicle is disabled. While I am aware this is the Mission Editing board, I felt my issue sorta spans both mission editing and addon editing, so I just picked one.

 

After some experimentation and research, I decided the best method for this would be to add a "GetOut" event handler that moves the dismounting unit back into the boat.

 

Here is the method I am using to spawn (and lock) the boat:

    _boatModel = selectRandom(getArray(_eventSetting >> "pe_boatClasses"));
    _boat = createVehicle[_boatModel, _pos];
    _boat lock true;

It works perfectly fine, I just wanted to provide it for reference.

 

As for the event handler:

    _boat addEventHandler ["GetOut", {
        private _veh = _this select 0;
        private _seat = _this select 1;
        private _unit = _this select 2;

        

        if (_seat isEqualTo "driver") then {
            _unit moveInDriver _veh;
        } else {
            _unit moveInCargo _veh;
        };
    }];

They are in the same scope, so referencing _boat should not be an issue, and the actual process of moving units back into the boat when they dismount works when I add it into the init of a vehicle in the editor. I am guessing there is a locality issue I am not completely able to wrap my head around here, because I see on the biki that "It can be assigned to a remote vehicle but will only fire on the PC where the actual addEventHandler command was executed." My issue I haven't work much with event handlers before, and certainly haven't ever tried to use them in a server-only addon, so I am hoping someone will be able to point me in the right direction here.

Share this post


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

Try and use this command instead: allowCrewInImmobile

Thanks for the reply!

 

I actually tried that initially, but my understanding was that it only worked for tracked/wheeled vehicles, which seemed to be the case when I tried it myself. I did not, however, try disabling FSM, as that page suggests. Do you know for sure that it works on boats?

Share this post


Link to post
Share on other sites

It seems you're right, as soon as we disable the engine of the boat (e.g. boat1 setHitIndex [1, 1]), the crew starts to disembark with or without allowCrewInImmobile and even with disableAI "all".

 

For your workaround try adding event handler "GetOutMan" to the boat crew instead of the boat.

  • Like 1

Share this post


Link to post
Share on other sites

I managed to fix it last night, forgot to reply this morning. I ended up moving the event handler code to its own variable, and spawning the variable from inside of the main variable. This fixed the locality issue (somehow, frankly I don't understand why).

  • Like 1

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

×