Jump to content
Sign in to follow this  
twiggy158

Need help with a Ready Up script.

Recommended Posts

I'm having trouble getting this script to work. I'm fairly new at scripting in ArmA 3 so I'm not entirely sure if I have everything setup right. Here's what it looks like:

    publicVariable "bluReady";
   publicVariable "opReady";

// ignore this bit
   flag_op addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];
   flag_us addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];
// ***************************************
   flag_us addAction ["<t color='#ff1111'>Team Ready</t>", { bluReady = true } ];
   flag_op addAction ["<t color='#ff1111'>Team Ready</t>", { opReady = true } ];

   if (bluReady) then
   {
   	MessageText = "Blufor is Ready.";
   	[MessageText,"hint",nil,true] call BIS_fnc_MP;
   };

   if (opReady) then
   {
   	MessageText = "Opfor is Ready.";
   	[MessageText,"hint",nil,true] call BIS_fnc_MP;
   };

   if (bluReady && opReady) then
   {
   	MessageText = "Both teams ready. Beginning match in 5 seconds.";
   	[MessageText,"hint",nil,true] call BIS_fnc_MP;

   	sleep 5;

   	execVM "Scripts\teleportBlufor.sqf";
   	execVM "Scripts\teleportOpfor.sqf";
   };    

The main issue lies with the boolean in the addAction lines. They don't work, and for the life of me I can't figure it out. I've searched up and down for a similar issue and haven't had much luck.

Share this post


Link to post
Share on other sites

You need to declare and define your public variables first, and then each time they are altered, they need to be publicVariabled again, I also made a change to it, that makes more sense, will explain further below:

    bluReady = false;
   publicVariable "bluReady";
   opReady = false;
   publicVariable "opReady";

// ignore this bit
   flag_op addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];
   flag_us addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];
// ***************************************
   flag_us addAction ["<t color='#ff1111'>Team Ready</t>", { bluReady = true; publicVariable "bluReady"; ["Blufor is Ready.","hint",nil,true] call BIS_fnc_MP;} ];
   flag_op addAction ["<t color='#ff1111'>Team Ready</t>", { opReady = true; publicVariable "opReady"; ["Opfor is Ready.","hint",nil,true] call BIS_fnc_MP;} ];

   _terminate = [] spawn { sleep 120; };//<<Change this time to how long you want the player to have to ready up.
   waitUntil {bluReady && opReady || scriptDone _terminate};

   if (bluReady && opReady || scriptDone _terminate) then
   {
       terminate _terminate;
   	MessageText = "Both teams ready. Beginning match in 5 seconds.";
   	[MessageText,"hint",nil,true] call BIS_fnc_MP;

       removeAllActions flag_us;
       removeAllActions flag_op;

   	sleep 5;

   	execVM "Scripts\teleportBlufor.sqf";
   	execVM "Scripts\teleportOpfor.sqf";
   };

So now the flags get the addAction and the script then waits for those 2 variables to be true, or for a certain time to go by, then it goes to do the rest of the code. The terminate time is just to make sure the script doesn't get stuck at that waitUntil forever, as well as adds the ability for you to say "Teams have X minutes to get ready, before the mission begins".

EDIT: Also added remove actions on the flags, don't want the publicVariables to be spammed on the network in case there are any players that just sit there and keep clicking the action :p.

Edited by JShock

Share this post


Link to post
Share on other sites

Thank you so much! I didn't realize you need to declare it as a publicVariable each time. And thank you for cleaning up the code and adding the wait timer! Much appreciated!

Share this post


Link to post
Share on other sites

How else would you be able to give it a value :)

Share this post


Link to post
Share on other sites

Sorry but the whole thing is still a bit fked up in terms of locality. It seems like you're running that script for everyone, yet it still uses BIS_fnc_MP when the condition is met.

Also, with that wait-timer you can get funny results as the script likely isn't run at exactly the same time on each client.

I'd suggest a slightly different setup:

if (isServer) then {
   bluReady = false;
   opReady = false;
   publicVariable "bluReady";
   publicVariable "opReady";

   _t = time;
   waitUntil { (bluReady && opReady) || ((time - _t) > 120) };

   MessageText = "Both teams ready. Beginning match in 5 seconds.";
   [MessageText,"hint",nil,true] call BIS_fnc_MP;

   sleep 5;

   execVM "Scripts\teleportBlufor.sqf";
   execVM "Scripts\teleportOpfor.sqf";

} else {
   flag_op addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];
   flag_us addAction ["<t color='#ff1111'>Teleport</t>", "Scripts\teleport.sqf" ];

   flag_us addAction ["<t color='#ff1111'>Team Ready</t>", {
       bluReady = true; publicVariable "bluReady";
   },"",1,false,true,"",'!bluReady'];
   flag_op addAction ["<t color='#ff1111'>Team Ready</t>", {
       opReady = true; publicVariable "opReady";
   },"",1,false,true,"",'!opReady'];
};

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
Sign in to follow this  

×