Jump to content
Stormmy1950

AddAction enable/disable

Recommended Posts

ok guys all i want when player enables the earplugs go to disabling earplugs.

i have manage to eneable earplugs but i cant disable i dont know what i did wrong if somebody can help

 

_a = 0;

// call enableEarplugs;

enableEarplugs = {
removeAllActions player;
player addaction ["Enable Earplugs","earplugsPutIn.sqf"]; 
};

disableEarplugs = {
removeAllActions player;
player addaction ["Disable Earplugs","earplugsTakeOut.sqf"];
};

if(_a isEqualto 0) then {
_disableEarPlugsVariable = [""]  call disableEarplugs;
_a = 1;
};

if(_a isEqualto 1) then {
_enableEarPlugsVariable = [""] call enableEarplugs;
_a = 0;
};

 

Share this post


Link to post
Share on other sites

You just need one addAction. The menu text is defined by setuserActionText

 

 

 player addAction ["plugs on ",{
        params ["_plyr","_caller","_id"];
        private _actMenu = (_plyr actionParams _id) select 0;
        if (_actMenu isEqualTo "plugs off") then {
          _actMenu = "plugs on";
          call disableEarplugs;
        } else {
          _actMenu = "plugs off";
          call enableEarplugs;
        };
        _plyr setUserActionText [_id,_actMenu];
      },nil,0.8,false,true,"", "!isnull objectParent _this"];

 

i can't test but you see the principle.

NOTE: the !isnull objectParent _this is a condition for player inside a vehicle. (optional)

Share this post


Link to post
Share on other sites

The way it's written, _a is 0 so it hits the first if statement, calls disableEarplugs, sets _a to 1 which makes the next if-statement true, immediately calling enableEarplugs. This will of course remove the disable earplugs, there's no way to set it on with the script above. Might be easier to have the actual earplugs putin and takeout scripts directly do the remove action and add action commands, removing the need for the middleman script above. Or possibly what Pierre wrote above before I could finish this :)

Share this post


Link to post
Share on other sites

yea when i run that script that you sent me @pierremgi it dosent event give me a option of addAction btw i am running this on Init.sqf.

I am going to switch after to initPlayerLocal just for testing i am in Init

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

×