Jump to content
SirBassi

addAction for switching Variable Values

Recommended Posts

Hi together,

 

I wrote my first lil longer and complex script ready and after a longer period of try and error and hard learning phase I am the happiest guy, now 😉

 

For stopping and starting my script(s) while the mission I set boolean variables for stopping and continue.

I have in my mind to set change this variables not every time by console, better with a easy addaction of local me Ingame.

 

But with this im a little in struggle and not sure if it could work and if I am on the "right path".

 

Idea:

Quote

//Based on a Pastebin Script idea of Alphapixel2

 

{player removeAction _x} forEach AdminActions;

AllowDamagePlayer=true;

AdminActions=[];

 

AdminActions append [ FIRST ADD ACTION

];

 

AdminActions append [ SECOND ADD ACTION

];

 

// Here it starts

//object addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, radius, unconscious, selection, memoryPoint]

 

AdminActions append

    [

        player addAction ["<t color='#b83317'>Stop Vehicles</t>",

                        {SpawnVehicles = false; publicVariableServer "SpawnVehicles";

                        _text= if (SpawnVehicles)

                        then {

                            player setUserActionText [(_this select 2),"<t color='#b83317'>Stop Vehicles</t>"]; SpawnVehicles = false; publicVariableServer "SpawnVehicles";

                        }

                        else {

                            player setUserActionText [(_this select 2),"<t color='#259f23'>Start Vehicles</t>"]; SpawnVehicles = true; publicVariableServer "SpawnVehicles";

                        }}]

    ];


 

AdminActions append [

player addAction ["<t color='#000000'>Remove Admin Tools</t>", {

{

player removeAction _x

}forEach AdminActions;

player AllowDamage true;

}]

]

 

The switching of the colors from the addaction works as expected. But the code wasn't executed. Maybe you get a idea for me.

Thanks a lot.
 

Share this post


Link to post
Share on other sites

You set the variable SpawnVehicles to false at the top of the addAction. So the variable is only ever going to be false so the only part of the IF statement that will run is the Else. The Else sets SpawnVehicles to true, but as soon as the action is triggered again SpawnVehicles is set to false immediately at the top of the addAction.

Also you only publicVariable to the server, so no other admins would see the update( that's if you depend on  this to be usable by multiple admins ) to the variable.

Spoiler

//Somewhere on server setup, set initial var value and propogate to all clients
missionNamespace setVariable[ "SpawnVehicles", true, true ];

//From your script
AdminActions append [
	player addAction [
		"<t color='#b83317'>Stop Vehicles</t>",
		{
			params[ "_target", "_caller", "_ID", "_args" ];
			
			if (SpawnVehicles) then {
				player setUserActionText[ _id, "<t color='#b83317'>Stop Vehicles</t>" ];
			} else {
				player setUserActionText[ _id, "<t color='#259f23'>Start Vehicles</t>" ];
			}
			
			missionNamespace setVariable[ "SpawnVehicles", !SpawnVehicles, true ];
		}
	]
]; 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks alot!

 

I completely overlooked this logic error and did not recognize it. The fact that the variable is not visible to other admins would not have been a problem, since only processes running on the server are running in the script and the addAction is then more or less just an emergency exit or re-entry.

But that's right, if I do other projects at some point, I should rather write it in such a way from the outset that such a potential error cannot occur in the first place. Good hint.

And the solution you showed is of course very smart and performant.

 

Thank you once again for the help .👍

  • 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

×