Jump to content
mattjb

Add/Remove Vehicle Action on Enter/Leave

Recommended Posts

I'd like some suggestions to try here...

I've been trying to add an ACE action dynamically to players when they enter/leave vehicles.

I discovered why my actions were not visible if I just tried to attach the action to the player and assume that it would carry with whatever vehicle he got into... apparently it isn't the case, and it seems necessary to leverage a vehicle/getinman/getoutman EH.

Ideally the CBA_fnc_addPlayerEventHandler would be best here, as it triggers on Zeus actions and other scenarios; however, I cannot discern between an "enter" and "leave" condition...

The code segment I have for this:

	_unit = player;

            addVicAction = {
                _unit = _this select 0;
                _vehicle = _this select 1;
                _fullHealVic = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{true}] call ace_interact_menu_fnc_createAction;
                [[_vehicle, 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];
            };

            removeVicAction = {
                _unit = _this select 0;
                _vehicle = _this select 1;
                _fullHealVic = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{true}] call ace_interact_menu_fnc_createAction;
                [[_vehicle, 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_removeActionFromObject] remoteExec ["call", -2, true];
            };

            ["vehicle", {
                params ["_unit", "_vehicle"];
                _unit sideChat format ["unit: %1 :: vehicle: %2 :: vehicle _unit: %3", _unit, _vehicle, vehicle _unit];
                if (vehicle _unit != _unit) then {
                    [_unit, _vehicle] call addVicAction;
                }
                else {
                    [_unit, _vehicle] call removeVicAction;
                };
            }] call CBA_fnc_addPlayerEventHandler;

The else statement's 'removeVicAction' is never getting called to remove the action, resulting in +1 or +2 (enter or enter/leave) actions added.

Looking at the vars from the sideChat statement reveals that the vehicle var is being assigned after getting in, and before getting out...

See screenshot below for the sideChat messages after getting in and getting out -- all vars are identical:

 

6C86744ED5DE5FFE13835506D2E241CFD8FD0064

 

Share this post


Link to post
Share on other sites

The CBA handler fires as soon as the vehicle changes.

https://github.com/CBATeam/CBA_A3/blob/master/addons/events/fnc_addPlayerEventHandler.sqf#L175

So in both cases it fires after it changed. Atleast according to the code and also to personal experience it works like that.
 

Also why are you adding/removing the action constantly? Why not add it once and just use a "in vehicle" condition?

Also what are you using the remoteExec for? So that others can heal your vehicle?

Share this post


Link to post
Share on other sites

If there's a means to not have to add/remove it constantly, I'm open to suggestions/alternatives. :)

The reason why I resorted to looking into doing it that way is because I wasn't having any luck for the past 3 weeks in figuring out a way to have it carried with the player.

My initial instinct was to try something like: 

 [[(vehicle _unit), 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];

But when testing this, I observed that when an injured player gets into the vehicle, the passenger action doesn't appear; however, if the player spawns in the vehicle (i.e. mission start), the action appears...

I concluded that the addActionToObject was being added to the vehicle, and not the player itself.

 

The action is for passengers in the vehicle, not the vehicle itself. The actions work perfectly in targeting the player when used in the above context and my initial post (with EH), just the problems I'm having with either solution...

remoteExec's are in there as it's a purely client-driven script targeting other players. 

For reference, the entire init sqf code is below (_fullHealVic is just temporary, _fullHeal is the real action -- I got tired of shooting myself with remote controlled units so I went with a {true} condition). This is for a mod I've been developing in my spare time for my group that wanted a simpler solution to utilizing a fully customizable PAK solution in ACE Basic Medical -- without deleting the ace_medical.pbo - as they are too devoted to using Steam Workshop:

if (isServer) exitWith {};

[[], {
    waitUntil {
        !(isNull player) &&
        {(player == player)} &&
        {!isNil "BIS_fnc_init"}
    };

    _unit = player;

    if (hasInterface) then {
        if (isNil {_unit getVariable ["WolfPAKActive", nil]}) then {
            _unit setVariable ["WolfPAKActive", true];
            // WolfPAK v1.5 - initialization code
            _fullHeal = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{(('ACE_personalAidKit' in (items _player + assignedItems _player)) or ('ACE_personalAidKit' in (items _target + assignedItems _target))) and ( (!(_target getVariable ['ACE_medical_bodyPartStatus',[0,0,0,0,0,0]] isEqualTo [0,0,0,0,0,0])) or (_target getVariable ['ACE_medical_pain',0] > 0) or (_target getVariable ['ACE_isUnconscious',false] isEqualTo true))}] call ace_interact_menu_fnc_createAction;

            [[_unit, 0, ["ACE_MainActions"], _fullHeal],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];
            [_unit, 1, ["ACE_SelfActions"], _fullHeal] call ace_interact_menu_fnc_addActionToObject;

            addVicAction = {
                _unit = _this select 0;
                _vehicle = _this select 1;
                _fullHealVic = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{true}] call ace_interact_menu_fnc_createAction;
                [[_vehicle, 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];
            };

            removeVicAction = {
                _unit = _this select 0;
                _vehicle = _this select 1;
                _fullHealVic = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{true}] call ace_interact_menu_fnc_createAction;
                [[_vehicle, 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_removeActionFromObject] remoteExec ["call", -2, true];
            };

            ["vehicle", {
                params ["_unit", "_vehicle"];
                _unit sideChat format ["unit: %1 :: vehicle: %2 :: vehicle _unit: %3",_unit,_vehicle, vehicle _unit];
                if (vehicle _unit != _unit) then {
                    [_unit, _vehicle] call addVicAction;
                }
                else {
                    [_unit, _vehicle] call removeVicAction;
                };
            }] call CBA_fnc_addPlayerEventHandler;

            systemChat "Initialized WolfPAK v1.5 (PBO)";
            // End of WolfPAK v1.5 - initialization code
        };
    };
}] remoteExec ["spawn", -2, true];

 

Share this post


Link to post
Share on other sites
12 hours ago, mattjb said:

if (isNil {_unit getVariable ["WolfPAKActive", nil]}) then {

if (!_unit getVariable ["WolfPAKActive", false]) then {

 

 

Commy:

His screenshot shows three times the same thing, because that is how a vehicle without varname looks: exactly the same as the stringified effective commander.

So it looks like he gets the player trice, but he doesn't.

 

This can easily be checked by replacing:
`_unit sideChat format ["unit: %1 :: vehicle: %2 :: vehicle _unit: %3", _unit, _vehicle, vehicle _unit];`
with a proper:
`systemChat format ["unit: %1 :: vehicle: %2 :: vehicle _unit: %3", typeOf _unit, typeOf _vehicle, typeOf vehicle _`

 

And his `removeVicAction`  fails, because he uses:
`[_vehicle, ...] ... ace_interact_menu_fnc_removeActionFromObject`

Dedmen: But after getting out _vehicle doesn't point to the old vehicle anymore. After getting out it's the player aka the new vehicle the player is now occupying.
Commy:
Could store it inside a global variable. That'd be the best.
But then again, I wouldn't constantly remove and readd the action any way.

Use a proper condition for the action instead (i.e. "player is inside vehicle").

Share this post


Link to post
Share on other sites

I'd like to use a "player is inside vehicle" based condition... But I'm lost on how to attach it to the player and have the action carried between vehicles.

The addActionToObject works if I am in a vehicle at mission start.

If I get out, and get back in, it still works for that vehicle.

However, if I get out and go to another vehicle, the action doesn't appear -- leading me to think that vehicle _unit only registered the vehicle that the player started in, and is not being dynamically reassigned when the player changes vehicles.

i.e.

[[(vehicle _unit), 0, ["ACE_MainActions", "ACE_Passengers", str _unit], _fullHealVic],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];

 

Would you happen to know how to get it to show up dynamically?

 

I'm already using a hefty condition as can be seen by _fullHeal --- {(('ACE_personalAidKit' in (items _player + assignedItems _player)) or ('ACE_personalAidKit' in (items _target + assignedItems _target))) and ( (!(_target getVariable ['ACE_medical_bodyPartStatus',[0,0,0,0,0,0]] isEqualTo [0,0,0,0,0,0])) or (_target getVariable ['ACE_medical_pain',0] > 0) or (_target getVariable ['ACE_isUnconscious',false] isEqualTo true))}

 

I'm assuming this is where a "player is inside vehicle" condition would go, right? But again, getting the action to even show up in the first place between various vehicles is the main problem.

Share this post


Link to post
Share on other sites

Just giving a quick update - still haven't figured this out yet, but I did discover a param (enableInside) in createAction that I've been tinkering with as it sounds suspicious -- initial testing still no go, but maybe I'm missing something:

 

[ACE] fnc_createAction.sqf

 * Arguments:
 * 0: Action name <STRING>
 * 1: Name of the action shown in the menu <STRING>
 * 2: Icon <STRING>
 * 3: Statement <CODE>
 * 4: Condition <CODE>
 * 5: Insert children code <CODE> (Optional)
 * 6: Action parameters <ANY> (Optional)
 * 7: Position (Position array, Position code or Selection Name) <ARRAY>, <CODE> or <STRING> (Optional)
 * 8: Distance <NUMBER> (Optional)
 * 9: Other parameters [showDisabled,enableInside,canCollapse,runOnHover,doNotCheckLOS] <ARRAY> (Optional)
 * 10: Modifier function <CODE> (Optional)



params [
    "_actionName",
    "_displayName",
    "_icon",
    "_statement",
    "_condition",
    ["_insertChildren", {}],
    ["_customParams", []],
    ["_position", {[0, 0, 0]}],
    ["_distance", 2],
    ["_params", [false, false, false, false, false]],
    ["_modifierFunction", {}]
];

 

My modified createAction:

_fullHeal = ["full_heal", "<t color='#00ff00'>WolfPAK (Full Heal)</t>","", {[_target,_player] execVM "wolfpak\scripts\wolfpak_aceaction.sqf"},{(('ACE_personalAidKit' in (items _player + assignedItems _player)) or ('ACE_personalAidKit' in (items _target + assignedItems _target))) and ( (!(_target getVariable ['ACE_medical_bodyPartStatus',[0,0,0,0,0,0]] isEqualTo [0,0,0,0,0,0])) or (_target getVariable ['ACE_medical_pain',0] > 0) or (_target getVariable ['ACE_isUnconscious',false] isEqualTo true))},{},[],[0,0,0],3,[false,true,false,false,false]] call ace_interact_menu_fnc_createAction;

 

Share this post


Link to post
Share on other sites

I think I figured it out (still need to do testing with 2+ people), but the issue was the usage of addActionToObject.

Thanks, Dedmen! Your typeOf clue gave me a hint in trying addActionToClass instead, as follows:

[[typeOf _unit, 0, ["ACE_MainActions"], _fullHeal],ace_interact_menu_fnc_addActionToClass] remoteExec ["call", -2, true];

Instead of:

[[_unit, 0, ["ACE_MainActions"], _fullHeal],ace_interact_menu_fnc_addActionToObject] remoteExec ["call", -2, true];

Doing this, there's no need for the EH as the action appears in both the ACE_MainActions when outside a vehicle, and inside the vehicle via Vehicle -> Passengers -> Unit's Name subaction menu as well.

I still need to test with more human players, as I lose remote control when controlling an AI unit entering the same vehicle as myself, but testing from outside -> inside is working. 

I will update this thread with results from inside -> inside when I get around to it, for anyone else with the same issue that stumbles by this thread.

Share this post


Link to post
Share on other sites
On 29.7.2018 at 9:05 PM, mattjb said:

Thanks, Dedmen! Your typeOf clue gave me a hint in trying addActionToClass instead

Didn't even know that existed. Certainly very good to know ^^

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

×