Jump to content

How to get value of 4 random flag values via simple script


Recommended Posts

I am trying to get the flag value of 4 random flags after mission start (using condition Time more than 40 seconds) and just have message on screen for 20 seconds. These represent 9%,25%, 33%, 90% random possibility. I found some code by Hardcard and was trying to adjust it but cannot get it to show. I also know little about LUA so would appreciate any help.

 

Code I have so far:

 

local function Flags_1()

 

local FlagTable_1 = { -- This table contains flags 109, 125, 133, 190

Flag_109 = trigger.misc.getUserFlag ( '109' ),

Flag_125 = trigger.misc.getUserFlag ( '125' ),

Flag_133 = trigger.misc.getUserFlag ( '133' ),

Flag_190 = trigger.misc.getUserFlag ( '190' )


}

 

trigger.action.outText("Flag_109 value = "..FlagTable_1.Flag_109.."\nFlag_125 value = "..FlagTable_1.Flag_125.."\nFlag_133 value = "..FlagTable_1.Flag_133..

"\nFlag_190 value = "..FlagTable_1.Flag_190, 20,true) --This message will show the status of flags 109, 125, 133, 190
end

 

I was getting values out with the following script message but it never changed value from "1" - so I guess it was just showing that flag was there?

 

trigger.action.outText( 'Flag 125 Injured: ' .. trigger.misc.getUserFlag ( '125' ), 20 )
trigger.action.outText( 'Flag 133 Escaped: ' .. trigger.misc.getUserFlag ( '133' ), 20 )

Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB

Link to post
Share on other sites

 trigger.misc.getUserFlag does just that - it returns the current value of that flag. So I guess the next question is: how do you set the flags, and to which values? Perhaps it helps if you show us that as well, and then explain what you would have expected to see vs. what you are seeing (if I read you correctly, you are getting '1' across the board)

 

Link to post
Share on other sites

From what I can see in the miz, you are simply setting the flags via Flag ON, which will set it to 1, so this tracks with what you see. What did you try to accomplish, or phrased differently: what did you expect?

 

 

Link to post
Share on other sites

Wait - I now see that you are using a Random condition to set the flags, so your question is probably: what is wrong with the random condition because it seems to always fire. Is that the question?

Link to post
Share on other sites

Yes that is the question. I wanted to only set a flag (true/1) dependant on the random possibility. So flag 109 only has a 9% chance of being set on. I am starting to get the picture that that will not work with Random condition.

Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB

Link to post
Share on other sites

Ok so after reading up a bit am I correct is saying:

Using simple Random condition and then checking value after a time span this was giving the Random Condition time to turn "True"?

In a test I changed from 'Once' to Mission Start and it seems to be giving changing values.

Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB

Link to post
Share on other sites

From the hoggitworld docs, the Random Condition has a side effect you may have overlooked (see third line):

 

Quote

Think of condition "Random 50%" to be a coin flip. Each time the trigger is checked, the simulator flips the coin.

If the coin lands on "heads" the condition will become true, and the action will execute.

If the coin lands on "tails" the condition will remain false, and the trigger will be checked again until the condition true.

 

Emphasis from the docs. This means that after 40 seconds, there is a great likelihood that all triggers have become true (1) since even at 9%, the Mission's had 40 shots at it.

 

Link to post
Share on other sites

Yes that was the Doc I looked at and have changed from 'Once' to 'Mission Start' for the flag setting which depend on Random.

 

Thanks

Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB

Link to post
Share on other sites

Hardcard was trying to get various different % to generate true flags (some low % some high %) to then use flags as triggers for different scenario's/outcomes in a MP mission.

Intel i7-7700@3.6GHz 16GB NVIDIA GeForce GTX1060 6GB

Link to post
Share on other sites
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...