Jump to content
Sign in to follow this  
gfresco

Help inserting a time delay into another script.

Recommended Posts

I've been trying to edit a script to have a time delay before one part of it completes, but I can't quite figure out how (I've only tried inserting sleep commands). This is a respawn script that currently respawns the group where it was placed in the editor instantly when it dies. I would like to create a time delay so the group respawns after some time has elapsed (for example 15 minutes).

 

Alas I am still learning to script and am fairly noobish, and my attempts to insert sleep commands or any brackets have been unsuccessful.

 

This is the script (from https://forums.bistudio.com/topic/172933-mission-template-stand-alone-gaia-make-missions-fast-by-using-mcc-gaia-engine/ )
 

 

//----------------------gaia------------------------------------------------------
if (isserver) then {call compile preprocessfile "gaia\gaia_init.sqf";};



//===============Delete Groups ====================
if (isServer ) then
{
    [] spawn
    {
        _gaia_respawn = [];
        while {true} do
        {
            //player globalchat "Deleting started.............."; sleep 5;
            
            {
                _gaia_respawn = (missionNamespace getVariable [ "GAIA_RESPAWN_" + str(_x),[] ]);
                //Store ALL original group setups
                if (count(_gaia_respawn)==0) then {[(_x)] call fn_cache_original_group;};
                
                if ((({alive _x} count units _x) == 0) ) then
                {
                    //Before we send him to heaven check if he should be reincarnated
                    if (count(_gaia_respawn)==2) then {    [_gaia_respawn,(_x getVariable  ["MCC_GAIA_RESPAWN",-1]),(_x getVariable  ["MCC_GAIA_CACHE",false]),(_x getVariable  ["GAIA_zone_intend",[]])] call fn_uncache_original_group;};                    
                    
                    //Remove the respawn group content before the group is re-used
                    missionNamespace setVariable ["GAIA_RESPAWN_" + str(_x), nil];
                    
                    deleteGroup _x;
                };
                
                sleep .1;
                
            } foreach allGroups;            
            
            sleep 2;
        };
    };
};

 

 

I need to insert a delay around this portion of the script:

 

 

                if ((({alive _x} count units _x) == 0) ) then
                {
                    //Before we send him to heaven check if he should be reincarnated
                    if (count(_gaia_respawn)==2) then {    [_gaia_respawn,(_x getVariable  ["MCC_GAIA_RESPAWN",-1]),(_x getVariable  ["MCC_GAIA_CACHE",false]),(_x getVariable  ["GAIA_zone_intend",[]])] call fn_uncache_original_group;};     

 

I would really appreciate any help a lot.

 

Share this post


Link to post
Share on other sites

This seems to be part of Spirit's Gaia framework. There's a topic re Gaia: https://forums.bistudio.com/topic/172933-mission-template-stand-alone-gaia-make-missions-fast-by-using-mcc-gaia-engine/ 

Probably best to drop in line a that thread.

I have as well, but I'm not sure people look at the last page of that thread so much.I figured I'd try a general discussion since (I hope) the general thing I'm attempting - inserting a delay in a script - is more general then his specific GAIA framework. Thanks though

 

Use the waitUntil command.

 

I've tried inserting both waitUntil { sleep 10; }; and a fresh     if (count(_gaia_respawn)==2) then waitUntil { sleep 10; }; right before this line

 

                    if (count(_gaia_respawn)==2) then {    [_gaia_respawn,(_x getVariable  ["MCC_GAIA_RESPAWN",-1]),(_x getVariable  ["MCC_GAIA_CACHE",false]),(_x getVariable  ["GAIA_zone_intend",[]])] call fn_uncache_original_group;};   

 

with no luck. If you or anyone feels up to giving me a bit more direction/suggestion, it'd be appreciated. I get I'm asking to be hand held a bit so I understand if people don't have the time to do so.

 

edit:

 

 waitUntil { sleep 10; if (count(_gaia_respawn)==2) then {    [_gaia_respawn,(_x getVariable  ["MCC_GAIA_RESPAWN",-1]),(_x getVariable  ["MCC_GAIA_CACHE",false]),(_x getVariable  ["GAIA_zone_intend",[]])] call fn_uncache_original_group; false}};  

 

This works, however it seems to cause an issue with the other scripts at hand (units keep "respawning/spawning" even though the 1st one hasn't been killed) but I guess thats beyond the scope of this topic.

Share this post


Link to post
Share on other sites

waitUntil pauses the script thread until the condition inside the curly brackets is met executes whatever is in the curly brackets every frame until it comes back as true (i.e. whatever is in the curly bracket computes to "true"). According to the wiki, sleep doesn't return anything, so if the wiki is to be believed, that code is an error and doing something weird.

I haven't tried this, but if you test it yourself, you might find that:

 

waitUntil {sleep 1337;};

Pauses the script forever?

 

waitUntil {if (something) then {call somethingelse}; false};

Also pauses the script forever while calling something infinity times?

 

Try looking through the scripts that call this script and the scripts called by this script. There might be something happening simultaneously.

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  

×