Jump to content
CollectiveS

Run once simulation script

Recommended Posts

Hey all,

Okay so what I'm trying to do is create a script that either uses or emulates dynamic simulation but only triggers once for any given unit. Essentially I want them to remain unsimulated until a condition is met (namely any player getting within x meters) and then to become simulated and remain that way. For context this is because of AI behaivour (especially from some mods) allowing them to call for backup, as the reinforcements hoof it towards the fight the players retreat or die. The AI are once again desimulated, sometimes in very visible lcoations and could now be visible from a long way away frozen mid run.

I was thinking of trying to do it with a while script in init.sqf like
 

while {isServer} do {

_nearby = player nearEntities ["east", 300];

{_x enableSimulation true} forEach units _nearby
};


or in each units init with something like

while (this nearEntities ["player", 300] != []) do {
this enableSimulation true
};

I'm not sure if that script is even remotely correct, but the idea is that all of the units on the mission begin unsimulated with dynamic simulation off and this script handles all simulation triggers. Has anyone made a run-once simulation script before? Or can help me build one here? Any help would be appreciated!

Share this post


Link to post
Share on other sites

The run once is easy;

 

0= [] spawn { // or any scheduled scope allowing a pause and the following loop
  if (isServer) then {    // usually AIs are on server
    While {true} do {  // never ending loop. (reason to spawn it)
      {                               // foreach scope
        if (<something true>) then {
          <do what you want>;
          _x setVariable ["hoNiceThisUnitIsTreated", true];  // no more need to treat this unit. That's the one shot script
        }  // end if
      } forEach (allUnits select { isNil {_x getVariable "hoNiceThisUnitIsTreated"} && <any other condition filtering units> });
      sleep 2;  // usually no need to speed up the loop
    };
  };
};

 

On the other hand, I don't know why you are trying to reinvent the dynamic simulation...    

     

 

 

Share this post


Link to post
Share on other sites

if (!isServer) exitWith {};
blacklistArray = [];
bor_actDist = 2000;

[] spawn
{
private "_unit";
for "_i" from 0 to 1 step 0 do 
    {
        {
        _unit = _x;
        
            if !(_unit in blacklistArray) then            
            {    
            
                if (({isPlayer _x AND (_x distance _unit) < bor_actDist} count playableUnits) != 0)
                then 
                {
                    _unit enableSimulationGlobal True;
                    _unit enableAI "ALL";
                    _unit hideObjectGlobal False;
                }
                else 
                {
                    _unit enableSimulationGlobal false;
                    _unit disableAI "ALL";
                    _unit hideObjectGlobal true;
                };            
            };
        } forEach (AllUnits + Vehicles);

    sleep 5;
    };
};

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

×