Jump to content

Recommended Posts

Posted (edited)

I've been working with the flag random value triggers but I want to prevent the system from re-rolling the same value twice. Desired result is thus:

Aircraft enters zone. 1 of 5 scenarios is spawned at random. Aircraft exits zone. Enters zone again, 1 of remaining 4 scenarios is spawned at random. Repeat until all 5 scenarios are spawned.

To do this my triggers are:

Switched condition > part of coalition in zone > set flag random value (8, 1-5)

It works, but here's the problem:

The first roll gives two random spawns as expected. The next three rolls repeat already used values so nothing spawns. The next two rolls give two random spawns. The next two or three rolls repeat already used values so nothing spawns.

So effectively, out of 9-10 dice rolls only 4 result in desired group spawn. That's a 55-60% "failure" rate for the random flag value.

How can I turn this into a 0% "failure" rate so that something is spawned each time the dice is rolled?

Edited by Nealius
Posted

Let me know if you have more questions about this ..

-- MS, code.Create F5Dict
Flag5Dict = {1,2,3,4,5}
do
 local Flag5Value = trigger.misc.getUserFlag('5')
 local indexsearch = 0
 for index, data in pairs(Flag5Dict) do
  if (data == Flag5Value) then indexSearch = index end
 end
 table.remove(Flag5Dict,indexSearch)
end

-- SC, code.F5 Next Random Value, F18T
do
 local Flag5ValueOld = trigger.misc.getUserFlag('5')
 if #Flag5Dict > 0 then
  local indexRand = math.ceil(math.random(#Flag5Dict))
  trigger.action.setUserFlag(5, Flag5Dict[indexRand])
  trigger.action.outText('Flag 5 old value was ' .. Flag5ValueOld .. ', and the new value is: ' .. trigger.misc.getUserFlag('5'), 5)
  -- remove the new value
  table.remove(Flag5Dict,indexRand)
  if #Flag5Dict == 0 then
   trigger.action.outText('The Flag 5 Dictionary is now empty.  That is the last random value.'), 5, false)
  else
   -- test stuff
   -- print the dict
   trigger.action.outText('\n Flag5Dict', 5)
   for index, data in pairs(Flag5Dict) do
    trigger.action.outText(tostring(data), 5, false)
   end 
  end
 else
  trigger.action.outText('The final Flag 5 value is ' .. trigger.misc.getUserFlag('5'), 5)
 end
end

-- SC, Select Next Killbox, F75T
do
 if #Flag5Dict > 0 then
  local indexRand = math.ceil(math.random(#Flag5Dict))
  trigger.action.setUserFlag(5, Flag5Dict[indexRand])
  -- remove the new value
  table.remove(Flag5Dict,indexRand)
 end
end

 

 

This ^^^ is from Boxcutter Aleppo .miz

Boxcutter Aleppo 04.lua

Boxcutter Aleppo 28S1m.miz

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Posted

That would be a lot of questions. I've messed with airboss scripting but in general I have a lot of difficulty with coding. There's no way to prevent the random values being re-rolled without lua scripting?

Posted

I did a study on the DCS Random generator some time ago and it is pretty random  😎

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

Posted
On 8/29/2023 at 12:08 PM, Nealius said:

I've been working with the flag random value triggers but I want to prevent the system from re-rolling the same value twice.

That means that you don't really want a random number. You want to randomize the sequence in which specific values appear, a very different task. I believe looking at the problem this way will ease your development of a solution.

On 8/29/2023 at 12:08 PM, Nealius said:

Aircraft enters zone. 1 of 5 scenarios is spawned at random. Aircraft exits zone. Enters zone again, 1 of remaining 4 scenarios is spawned at random. Repeat until all 5 scenarios are spawned.

That is an almost perfect description of the solution, so you already have worked out how it could be solved 🙂 @Wrecking Crew already was kind enough to provide a script that can be used to achive what you want - the core is to store the possible outcomes into an array or dict, and then, each time that you want to 'draw' a number, access one item randomly, and delete that item, making the array smaller. A more capable version would not simply remove the drawn item but add it to a 'used' array/dict, and when the source array falls empty, replace it with the used items, so you can endlessly go though this.

10 hours ago, Nealius said:

There's no way to prevent the random values being re-rolled without lua scripting?

I believe that to be true. Then again, Lua is your friend - or wants to be your friend if you let it 🙂 

 

  • Like 1
Posted
19 hours ago, Nealius said:

That would be a lot of questions. I've messed with airboss scripting but in general I have a lot of difficulty with coding. There's no way to prevent the random values being re-rolled without lua scripting?

https://wiki.hoggitworld.com/view/DCS_editor_Randomization#Single_Choice_from_List

That is the trigger equivalent. It won't be instant, but you can set the random % to be higher to make it faster. 10% would be plenty fast with it occurring within a few seconds. A super simple lua way would be something like this: 

 

local flagChoices = {"flag1", "flag2", "flag3", "flag4", "flag5"}    -- flag names
local picks = {}   -- empty table that gets filled with flags that are still false
for i = 1, #flagChoices do
   if trigger.misc.getUserFlag(flagChoices[i]) == 0 then   -- checks value of the flag
      table.insert(picks, flagChoices[i])   -- add flags that are still false
   end
end
if #picks > 0 then  -- if a choice is to be made
  local flagInd = math.random(#picks)  -- pick one
  trigger.action.setUserFlag(picks[flagInd], 1) -- set that to true
end

 

 

  • Like 2

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
17 hours ago, Grimes said:

https://wiki.hoggitworld.com/view/DCS_editor_Randomization#Single_Choice_from_List

That is the trigger equivalent. It won't be instant, but you can set the random % to be higher to make it faster. 10% would be plenty fast with it occurring within a few seconds. A super simple lua way would be something like this: 

 

 

 

You make it look soo easy!  🙂

Visit the Hollo Pointe DCS World server -- an open server with a variety of COOP & H2H missions including Combined Arms. All released missions are available for free download, modification and public hosting, from my Wrecking Crew Projects site.

  • Recently Browsing   0 members

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