Jump to content
Rebitaay

Need help with addAction/removeAction in MP

Recommended Posts

Hey all,

 

I've been trying to set up a Mobile-HQ in my mission. The actual script isn't made yet, because I've been trying to get the actions working for some time now.

I'm attempting to add and remove actions from a vehicle using BIS_fnc_MP. It kind of works, but has very strange behavior which creates many issues.

 

initServer.sqf

[[MHQ1, ["Deploy MHQ", "Scripts\MHQ_Deploy.sqf"]], "addAction", true, true] call BIS_fnc_MP;

 

MHQ_Deploy.sqf

_MHQ = _this select 0;
_player = _this select 1;
_ID = _this select 2;

[[_MHQ, _ID], "removeAction", true, true] call BIS_fnc_MP;
sleep 0.5;
[[_MHQ, ["Pack-Up MHQ", "Scripts\MHQ_Packup.sqf"]], "addAction", true, true] call BIS_fnc_MP;

 

MHQ_Packup.sqf (Pretty much the same)

_MHQ = _this select 0;
_player = _this select 1;
_ID = _this select 2;

[[_MHQ, _ID], "removeAction", true, true] call BIS_fnc_MP;
sleep 0.5;
[[_MHQ, ["Deploy MHQ", "Scripts\MHQ_Deploy.sqf"]], "addAction", true, true] call BIS_fnc_MP;

 

 

I think the issue here is my vague understanding of BIS_fnc_MP, which the wiki doesn't explain very well. I've tried every combination of the two booleans (both set to true in the examples), and it always does something different that doesn't quite work. Sometimes it only shows for me, people see different options in different amounts, and sometimes a JIP player using the action will create duplicates on my end.

 

The intended way for it to work is when you use the "Deploy MHQ", it will remove the "Deploy MHQ" action and add the "Pack-Up MHQ" action, and vice-versa. The state it's in will need to apply to JIP players as well (e.g. If it's deployed, JIP should be able to pack it up). Other features are intended of course, but not yet scripted.

 

Am I doing something wrong with setting up the actions, or should I just be coding it with a different method?

Share this post


Link to post
Share on other sites

I suggest using setVariable and getVariable to broadcast the current MHQ status, rather than addAction and removeAction commands with BIS_fnc_MP

 

initPlayerLocal.sqf

MHQ1 addAction [MHQ1 getVariable ["action", "Deploy MHQ"], "Scripts\MHQ_Action.sqf"];

MHQ_Action.sqf

_MHQ = _this select 0;
_ID = _this select 2;

if (_MHQ getVariable ["action", "Deploy MHQ"] isEqualTo "Deploy MHQ") then {
	[_MHQ] execVM "Scripts\MHQ_Deploy.sqf";
    	_MHQ setVariable ["action", "Pack-Up MHQ", true];
        _MHQ setUserActionText [_ID, "Pack-Up MHQ"];
} else {
	[_MHQ] execVM "Scripts\MHQ_Packup.sqf";
    	_MHQ setVariable ["action", "Deploy MHQ", true];
        _MHQ setUserActionText [_ID, "Deploy MHQ"];
};

MHQ_Deploy.sqf

// Script deploys the MHQ
_MHQ = _this select 0;
...

MHQ_Packup.sqf

// Script packs up the MHQ
_MHQ = _this select 0;
...

 

Edited by Nikander

Share this post


Link to post
Share on other sites

@Nikander

 

Thanks, that looks promising. It works well so far, but I'll have to do multiplayer testing later.

I'll report back with my results for anyone else looking for something similar.

 

Edit:

It works great, thanks for the script @Nikander. One issue I had is that the "setUserActionText" was executing locally, so I changed it to:

[[_MHQ, [_ID, "Deploy MHQ"]], "setUserActionText", true, false] call BIS_fnc_MP;

But after changing it, everything worked great.

Edited by rebitaay
  • 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

×