Jump to content

Recommended Posts

Posted

Is there an elequent way to randomize turning off ground AI for 5-10 minutes at random times during a mission?

 

Currently using two switched conditions with set/unset flags and time since flag. It works but requires multiple triggers and doesn't seem all that random as it's using time since flag. Was hoping for some ideas on how to do this with a single trigger per ground unit using the Random % trigger condition. The idea is to make these units seem like they take lunch or a smoke break througout a long running mission at random intervals without scripting.

Posted (edited)

Scripting would be the optimal and easy way to do this as it'd take multiple triggers to get more randomized behavior on a per group basis.  This is more or less a countdown timer, you set a flag to a random value then at a set rate reduce the value of that flag, once it reaches a value of 1 execute a command. In this example it can take anywhere between 10 and 30 minutes to occur. 

 

Switched Condition>Whatever>Set Flag Random Value(x, 10, 30)

Switched Condition>Time Since Flag X is 60 > Flag Decrease X by 1

Switched Condition> Flag X is 1> AI Off, Flag Y On

Switched Condition> Time since flag y is whatever> Flag y Off, AI On. 

 

 

Where-as with scripting its pretty much the following. Point is you just have to edit the groups entry to add stuff and not make copies of the same however many triggers per group you want it to do. That is where the power of lua scripting makes things easier and shouldn't be that scary. 

 

 

env.info( '*** RANDOMIZER INCLUDE START *** ' )

local groups = {"Ground", "GroundB"} -- list of group names. 
local state = {}

local function coffee(gp)
  if Group.getByName(gp) and #Group.getByName(gp):getUnits() > 0 then  -- only executes if group is still alive
     
     if state[gp] == true then
      	state[gp] = false
        trigger.action.outText(gp .. " is going on break!", 30)
        timer.scheduleFunction(coffee, gp, timer.getTime() + math.random(30, 60))  -- coffee break is 5 to 10 minutes
     else
      	state[gp] = true
        trigger.action.outText(gp .. " is back from break!", 30)
        timer.scheduleFunction(coffee, gp, timer.getTime() + math.random(90, 360)) -- takes coffee break between 15 and 60 minutes
     end 
     Group.getByName(gp):getController():setOnOff(state[gp]) -- sets AI on/off based on the value. 
  end
end

for i = 1, #groups do
  state[groups[i]] = true   -- adds initial state to table
  timer.scheduleFunction(coffee, groups[i], timer.getTime() + math.random(30, 60)) -- same rules for when it can take break
end

env.info( '*** RANDOMIZER INCLUDE STOP *** ' )

 

 

Edited by Grimes
Fixed Code.
  • Like 1
  • Thanks 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

Some typos on my part. Pro-tip always test code used in advice you give to someone even if you think it'll work. Edited code from my earlier post and added some debug messages + reduced the time so it is easier to check. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

  • 11 months later...
Posted

Hi Grimes,

I tried your random function, but it's not working. I used smaller value just for test as follow :

 

Switched Condition>Whatever>Flag Set Random Value(1, 5, 15)

Switched Condition>Time Since Flag 1 is 1 > Flag Decrease 1 by 1

Switched Condition> Flag 1 is 1> AI Off, Flag 2 On

Switched Condition> Time since flag 2 is 10> Flag 2 Off, AI On.

Any chance to have more infos?

Thanks,

Vincent

IAMD Ryzen 9 5900X 12x 3.7 to 4.8Ghz - 32Go DDR4 3600Mhz - GeForce RTX 3080 - Samsung Odyssey G7 QLED - AIMXY

  • 2 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...