Jump to content
Sign in to follow this  
avibird 1

How does the sleep command really work within a script/codeline?

Recommended Posts

I am a little lost about how the sleep command really works within a script. For example I am using the sleep command like this

hint "";

waituntil {moveToCompleted leader Group_}

sleep 120;

hint "";

Within a script that uses multiple waypoints for a tank group that is called in for support.

For example

wp1 = GroupTank addwaypoint [position Player, 0];

wp1 waypointAttachVehicle vehicle player;

wp1 setwaypointtype "SAD";

wp1 setWaypointCombatMode "RED";

wp1 setWaypointFormation "WEDGE";

wp1 setWaypointSpeed "FULL";

wp1 setWaypointBehaviour "COMBAT";

wp1 setWaypointCompletionRadius 25;

wp1 setWaypointStatements ["true", ""];

hint "Tank Platoon Attempting to move to Assault Position Alpha";

waituntil {moveToCompleted leader GroupTank};

sleep 120;

hint "";

wp2 = GroupTank addwaypoint [position Player, 0];

wp2 waypointAttachVehicle vehicle player;

wp2 setwaypointtype "SAD";

wp2 setWaypointCombatMode "RED";

wp2 setWaypointFormation "WEDGE";

wp2 setWaypointSpeed "FULL";

wp2 setWaypointBehaviour "COMBAT";

wp2 setWaypointCompletionRadius 25;

wp2 setWaypointStatements ["true", ""];

hint "Tank Platoon Attempting to move to Assault Position Bravo";

waituntil {moveToCompleted leader GroupTank};

sleep 120;

hint "";

ect,ect the script goes on..........

I know the SAD waypoint takes over one minute to complete it's movements and then sits for the rest of the time and then moves to the next waypoint however if enemy units are spotted the SAD waypoint will continue in that sector unitil all the enemy units are gone/dead.

The issue is that the sleep command does not wait to count down even if the move to completed command is not done. So all the other hints become active within the script out of order of the other waypoints.

My question is does the sleep command start to count down when the waypoint is trigged. Why does the waitutil command not hold the count down of the sleep time. Can I delay the hint until the SAD waypoint is done ie no enemy units in the sector and the tanks stop moving during that SAD waypoint.

Any input would be great. Just when you think you have all the issues done ARMA kicks you in the balls lol Thanks AVIBIRD

Edited by AVIBIRD 1

Share this post


Link to post
Share on other sites

My guess would be that moveToCompleted isnt the right command to check if the waypoint is completed.

I cant see why the sleep wouldnt be waiting for the waitUntil.

I remember reading you can use setWaypointStatements

to check if a waypoint is completed

but ive never used it before.

Edit:

I just noticed your using setWaypointStatements ["true", ""];

After reading the wiki, wouldnt this auto complete the waypoint?

Edited by Lifted86

Share this post


Link to post
Share on other sites

I don't know need to look into that a bit more, but I need it because it allows the player who called the script to actively set the next waypoint down during the gameplay so the player can react to a dynamic mission that I am working my ass off on lol.

---------- Post added at 03:40 ---------- Previous post was at 03:18 ----------

If I make the setWaypointStatements ["false", ""]; The units will just follow the human player who called the script like a dog all over the map not what I needed for this script lol. Maybe i need to add something to this waituntil {moveToCompleted leader GroupTank}; but have no clue at this time. So I am going to smoke a joint and sleep on it (:

Share this post


Link to post
Share on other sites

wp1 setWaypointTimeout [120, 120,120] ;

That should hold that unit at the waypoint for 2 minutes after it's finished searching.

Share this post


Link to post
Share on other sites

F2K Sel if that works I am going to kiss you lol not! thank you mate. I will test and let you know but I must eat now lol. Thanks and I wish I could help you with your issue but that script is way over my paygrade(: take care AVIBIRD

---------- Post added at 05:06 ---------- Previous post was at 04:30 ----------

Hey F2K Sel it makes the waypoint hold the position for what time you put but not the hint that the group is moving to the next waypoint that was the real issue. All The hints are out of timing in the script I have

hint "Tank Platoon Attempting to move to Assault Position Alpha";

waituntil {moveToCompleted leader GroupTank};

sleep 120;

hint "";

hint "Tank Platoon Attempting to move to Assault Position Bravo";

waituntil {moveToCompleted leader GroupTank};

sleep 120;

hint "";

ect ect all the way down the script. I guess the real question is how do I delay the hint from coming up until the waypoint is done ie finished searching using the SAD waypoint. The units will not move on until the waypoint is done searching or all enemy units are dead in that location with or without the setWaypointTimeout. I have test played and the tanks will stay for over 25 minutes trying to kill all the units in before rolling to the next waypoint that I set while in the game.

So how do I stop the hints within the script if the sleep command does not work that way? The unit movements are not the issue ): The hints are key for new players to know how to set the new waypoints for the tanks during the game.

Edited by AVIBIRD 1

Share this post


Link to post
Share on other sites

You'll want the unitReady command most likely. Also sleep is essentially a waitUntil without condition and set waiting time. FYI.

Share this post


Link to post
Share on other sites

Thanks for the suggestion Tryteyker but how would one go about to insert the unitReady command into a script/codeline above to get the unitReady command to delay the hint information within my script. I have never seen the unitReady command used before. Avibird.

Share this post


Link to post
Share on other sites

Not sure, what exactly this code should do, looks, like tank group should follow the player with additional 120 second delay after completing each waypoint, but anyway perhaps currentWaypoint would be useful:

hint "Tank Platoon Attempting to move to Assault Position Alpha";

wp1 = GroupTank addwaypoint [position player, 0];
wp1 waypointAttachVehicle vehicle player;
wp1 setwaypointtype "SAD";
wp1 setWaypointCombatMode "RED";
wp1 setWaypointFormation "WEDGE";
wp1 setWaypointSpeed "FULL";
wp1 setWaypointBehaviour "COMBAT";
wp1 setWaypointCompletionRadius 25;
wp1 setWaypointStatements ["true", ""];

waitUntil 
{
sleep 1;
_cw = currentWaypoint GroupTank;
not (_cw == (wp1 select 1))
};

sleep 120;

hint "Tank Platoon Attempting to move to Assault Position Bravo";

wp2 = GroupTank addwaypoint [position player, 0];
wp2 waypointAttachVehicle vehicle player;
wp2 setwaypointtype "SAD";
wp2 setWaypointCombatMode "RED";
wp2 setWaypointFormation "WEDGE";
wp2 setWaypointSpeed "FULL";
wp2 setWaypointBehaviour "COMBAT";
wp2 setWaypointCompletionRadius 25;
wp2 setWaypointStatements ["true", ""];

waitUntil 
{
sleep 1;
_cw = currentWaypoint GroupTank;
not (_cw == (wp2 select 1))
};

sleep 120;

hint "end";
//or whatever

Another possible version, without delay, where all waypoints are added at once, and then code just awaits for completing subsequent waypoints:

wp1 = GroupTank addwaypoint [position player, 0];
wp1 waypointAttachVehicle vehicle player;
wp1 setwaypointtype "SAD";
wp1 setWaypointCombatMode "RED";
wp1 setWaypointFormation "WEDGE";
wp1 setWaypointSpeed "FULL";
wp1 setWaypointBehaviour "COMBAT";
wp1 setWaypointCompletionRadius 25;
wp1 setWaypointStatements ["true", ""];

wp2 = GroupTank addwaypoint [position player, 0];
wp2 waypointAttachVehicle vehicle player;
wp2 setwaypointtype "SAD";
wp2 setWaypointCombatMode "RED";
wp2 setWaypointFormation "WEDGE";
wp2 setWaypointSpeed "FULL";
wp2 setWaypointBehaviour "COMBAT";
wp2 setWaypointCompletionRadius 25;
wp2 setWaypointStatements ["true", ""];

hint "Tank Platoon Attempting to move to Assault Position Alpha";

waitUntil 
{
sleep 1;
_cw = currentWaypoint GroupTank;
not (_cw == (wp1 select 1))
};

hint "Tank Platoon Attempting to move to Assault Position Bravo";

waitUntil 
{
sleep 1;
_cw = currentWaypoint GroupTank;
not (_cw == (wp2 select 1))
};

hint "end";

BTW time of "SAD" completion varies depends of kind of group and kind of surroundings:

SAD

Share this post


Link to post
Share on other sites

Thank you Rydygier for the input will test when I get home from work. Helpfully this will do the job. AVIBIRD.

Share this post


Link to post
Share on other sites

You could also try with:

waitUntil{ ((getPosATL leader GroupTank) distance (waypointPosition wp1) < 5) };

Share this post


Link to post
Share on other sites

F2K Sel, Rydygier and JW thank you but no luck. The problem is not the waypoint delay (having the units hold before they move to the next waypoint) The issue is getting the hint to run when the waypoint is over or the next waypoint is starting. I can run my script fine without the hints but this script is for MP/COOP so the hints are important to tell the SL's who called for the support what sector the support units will move to for a SAD and that is based on his current location. Then the SL can move to a new sector wait for the new hint so he knows that the support units will move to that location and so on and so on. I am lost lol this sucks when you have it almost done but can't get the last fit right in a script):

---------- Post added at 01:47 ---------- Previous post was at 00:53 ----------

Here is the full script

if (!((player getVariable "infantrysupportAvailable") == "infantrySupportAvailable")) exitWith {hint "Infantry Reinforcement Support not available"};
player setVariable ["infantrysupportAvailable", "infantrysupportUNAvailable"]; 

[] execVM "AISUPPORT\menu\close_menu.sqf";
inf = false;
publicVariable "inf";

player sideChat "Request Reinforcement Infantry Squad to my sector, Over";
sleep 2;
[West,"HQ"] SideChat "Roger that, an infantry squad Condor is moving towards the staging sector";
sleep 4;

_pos = [(getPosATL Player select 0) + (400 * sin(180)), (getPosATL Player select 1) + (400 * cos(180)), 0];
GroupA = CreateGroup WEST;

GroupA = CreateGroup WEST;
A1 = GroupA createUnit ["US_Soldier_SL_EP1",  _pos, [], 0, "FORM"];
A2 = GroupA createUnit ["US_Soldier_TL_EP1",  _pos, [], 0, "FORM"];
A3 = GroupA createUnit ["US_Soldier_TL_EP1",  _pos, [], 0, "FORM"];
A4 = GroupA createUnit ["US_Soldier_GL_EP1",  _pos, [], 0, "FORM"];
A5 = GroupA createUnit ["US_Soldier_GL_EP1",  _pos, [], 0, "FORM"];
A6 = GroupA createUnit ["US_Soldier_AR_EP1",  _pos, [], 0, "FORM"];
A7 = GroupA createUnit ["US_Soldier_AR_EP1",  _pos, [], 0, "FORM"];
A8 = GroupA createUnit ["US_Soldier_LAT_EP1", _pos, [], 0, "FORM"];
A9 = GroupA createUnit ["US_Soldier_LAT_EP1", _pos, [], 0, "FORM"];
A10 = GroupA createUnit ["US_Soldier_MG_EP1", _pos, [], 0, "FORM"];
A11 = GroupA createUnit ["US_Soldier_MG_EP1", _pos, [], 0, "FORM"];
A12 = GroupA createUnit ["US_Soldier_LAT_EP1", _pos,  [], 0, "FORM"];  
A13 = GroupA createUnit ["US_Soldier_LAT_EP1", _pos,  [], 0, "FORM"];
A14 = GroupA createUnit ["US_Soldier_Marksman_EP1", _pos, [], 0, "FORM"]; 
A15 = GroupA createUnit ["US_Soldier_Medic_EP1", _pos, [], 0, "FORM"];                       
A1 = leader GroupA;
{_x setSkill 1} foreach units GroupA;

sleep 1;

wp1 = GroupA addwaypoint [position Player, 20];
wp1 setwaypointtype "MOVE"; 
wp1 setWaypointCombatMode "YELLOW"; 
wp1 setWaypointFormation "DIAMOND"; 
wp1 setWaypointSpeed "FULL"; 
wp1 setWaypointBehaviour "AWARE"; 
wp1 setWaypointCompletionRadius 10; 
wp1 setWaypointStatements ["true", ""];  

hint "Squad Leader advance to the sector Position that you want Squad Condor to Assault, deployment time ETA 2 minutes from staging sector"; 
waituntil {moveToCompleted leader GroupA};
sleep 120; 
hint "";  

wp2 = GroupA addwaypoint [position Player, 20]; 
wp2 waypointAttachVehicle vehicle player;  
wp2 setwaypointtype "SAD"; 
wp2 setWaypointCombatMode "Yellow"; 
wp2 setWaypointFormation "WEDGE"; 
wp2 setWaypointSpeed "FULL"; 
wp2 setWaypointBehaviour "AWARE"; 
wp2 setWaypointCompletionRadius 10;
wp2 setWaypointStatements ["true", ""]; 

hint "Infantry Squad Attempting to Move to Assault Position Alpha";  
waituntil {moveToCompleted leader GroupA};
sleep 90; 
hint "";

wp3 = GroupA addwaypoint [position Player, 20]; 
wp3 waypointAttachVehicle vehicle player;  
wp3 setwaypointtype "SAD"; 
wp3 setWaypointCombatMode "YELLOW"; 
wp3 setWaypointFormation "VEE"; 
wp3 setWaypointSpeed "FULL"; 
wp3 setWaypointBehaviour "AWARE"; 
wp3 setWaypointCompletionRadius 10;
wp3 setWaypointStatements ["true", ""];  

hint "Infantry Squad Attempting to move to Assault Position Bravo"; 
waituntil {moveToCompleted leader GroupA};
sleep 90; 
hint "";

wp4 = GroupA addwaypoint [position Player, 20]; 
wp4 setwaypointtype "SAD"; 
wp4 setWaypointCombatMode "YELLOW"; 
wp4 setWaypointFormation "WEDGE"; 
wp4 setWaypointSpeed "FULL"; 
wp4 setWaypointBehaviour "AWARE"; 
wp4 setWaypointCompletionRadius 10;

hint "Infantry Squad Attempting to move to Assault Position Charlie"; 
waituntil {moveToCompleted leader GroupA};
sleep 90; 
hint "";

wp5 = GroupA addwaypoint [position Player, 20]; 
wp5 setwaypointtype "Cycle"; 
wp5 setWaypointCombatMode "YELLOW"; 
wp5 setWaypointFormation "DIAMOND"; 
wp5 setWaypointSpeed "FULL"; 
wp5 setWaypointBehaviour "AWARE"; 
wp5 setWaypointCompletionRadius 10;

hint "Infantry Squad Attempting to move to Assault Position Xray"; 
waituntil {moveToCompleted leader GroupB};
sleep 90; 
hint "Infantry Squad Condor will Establish a rally point at Charlie position to regroup for New Orders to Assault sectors";

inf1s = createTrigger ["EmptyDetector",getPos player];  
inf1s setTriggerArea [1000, 1000, 0, false];
inf1s setTriggerActivation ["EAST", "NOT PRESENT", false];
inf1s setTriggerTimeout [900, 900, 900, false ];
inf1s setTriggerStatements ["this", "player sideChat ""Infantry Squad: Returning back to HQ to rearm, OVER""; GroupA exec ""AISUPPORT\support-req\infdone.sqf""" , ""];

inf1f = createTrigger ["EmptyDetector", [0,0,0]]; 
inf1f setTriggerArea [0, 0, 0, false];
inf1f setTriggerActivation ["NONE", "present", false];
inf1f setTriggerStatements ["!(alive A1) && !(alive A2) && !(alive A3) && !(alive A4) && !(alive A5) && !(alive A6) && !(alive A7) && !(alive A8) && !(alive A9) && !(alive A10) && !(alive A11) && !(alive A12) && !(alive A13) && !(alive A14) && !(alive A15)", "GroupA exec ""AISUPPORT\support-req\infdone.sqf""", ""];
sleep 1500; 
player setVariable ["infantrysupportAvailable", "infantrysupportAvailable"];
hint "New Infantry Squad Reinforcements are available to move to the front line if needed!";

If anyone would like to take a shot I need the hints to run only when the waypoints are done/completed FYI sometimes the SAD can last for a long time when enemy are in the sector the units are in.

The way the watpoints work-

1. the SL can call the support to a staging sector the units will wait for 2 minutes ( this gives the SL time to select move to an Assault Position that he wants support in) the units will move and do a SAD.

2. the SL then can move to a new sector Bravo and when the the support units are done in Assault Position Alpha the will move to Bravo then Charlie and XRAY at this point the support units will more to 5th sector after that they will return back to Charlie and move to the SL position do a SAD and then return back to Charlie to move back to the SL position over and over again until the script calls the units back to the HQ after 15 minutes. however if enemy units are within 1000 meters they will stay on the map. The SL can call the support back after 25 minutes from the first deployment time in the game. I have this for all types of support units within the mission. Only two SL an call for the support.

Share this post


Link to post
Share on other sites

Doesn't this bring up the hint when done.

wp1 setWaypointStatements ["true", "hint 'Squad Leader advance to the sector Position that you want Squad Condor to Assault, deployment time ETA 2 minutes from staging sector'; "];

Share this post


Link to post
Share on other sites
If anyone would like to take a shot I need the hints to run only when the waypoints are done/completed FYI sometimes the SAD can last for a long time when enemy are in the sector the units are in.

If you need hint after SAD completion, just relocate hint line after waituntil line. With currentWaypoint check method SAD may take any time, waituntil will pass code further only, when SAD is completed. That's why this is good solution IMHO. Check yourself on BIKI, how works currentWaypoint command. Waypoints statements should do this too. But in both cases code will not wait, if enemy is spotted just after SAD completion, what is possible, for waiting for eliminating all enemies you can use trigger with opfor not present condition, but then code may never pass further, if some enemy will stay undetected in the area.

I did not fully understood 1 and 2 points after quick read, but seems, that there is about something more complicated. Haven't time for going deeper into this, sorry. Anyway - will hints work in MP at all? MP scripting in some cases is more troublemaking than SP. Also - found problem here:

GroupA exec ""AISUPPORT\support-req\infdone.sqf""

Shouldn't be here execVM, not exec? Exec is for sqs, execVM for sqf. In general, good idea for learning practice may be reading descriptions of each used command:

Scripting_Commands_ArmA2

and looking there for new commands. Good luck.

Edited by Rydygier

Share this post


Link to post
Share on other sites

WOW that was hard but workout using F2k Sel last suggestion of simply using the setWaypointStatement command that I had in the code originally. I know you can get the same results using many different scripting approaches however for example just in this post there was 3 to 4 different ways that people were saying to attempt to try to get this done. I made a post about how the wiki scripting command page or in fact the whole ARMA community is lacking real working examples/demo of how the scripting commands really work within the game engine. I know some of you are going to say all the information is there but like I have said before if you can't read chinese how are you going to understand the information before your eyes. This is an area that really needs to be talk about more and more just my two cents.

I would like to thank all of you who gave me feedback on this. This was one of the last major stumbling blocks that I needed to complete my ultimate combat support/FOB demo/script before I can release it along with a mission called domination company of heroes. Solo player, coop 12 west alone or 12 vs 3 player vs player. Which could easily add player slots for large servers and not make the mission unbalanced to one side.

Thank you F2K, Rydygier, tryteyker, JW. I now can move on to someother issues that I have, god help us all LOL AVIBIRD.

Share this post


Link to post
Share on other sites
if you can't read chinese how are you going to understand the information before your eyes.

And I agree with that, as I remember, how it was, when I tried to do first steps - at this stage BIKI's command library was not helpful at all. I simply did not know, what to do with info available there, even with examples, and mostly did not understand it (perhaps for some regular programmer this is fully understandable at first look, but not for guy, that "just came straight from the street"). It is very helpful, but later, when you know some basics. For people, that are knowledgeable, some things, not clear for the others, looks too obvious to explain.

Edited by Rydygier

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  

×