Jump to content

Random Tasks that Never Repeat


Recommended Posts

Fix and Solution on Post #12!

 

 

Hello all,

 

I have a dilemma with a mission I am attempting to build that incorporates randomization. I accomplish randomization by using a "Mission Start: Set Random Flag Value" and then have an additional 10 triggers that are "Mission Start: If Flag W is more than X and less than Y, then Flag Z is true". This setup creates one of ten random tasks at mission start with no problems.

 

Here is my dilemma:

 

After this random mission task is completed, I want the framework to randomly pick another task of the 10 available, excluding the task previously finished. This process will continue until all ten tasks have been completed without repeating a task.

 

I would like to do this with triggers if at all possible, but I would be willing to work with scripts if that is the only solution. Thank you guys for your help.

 

Habu


Edited by Habu23

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Well the way you have it set up works pretty well, all you have to do is have a trigger activated whenever each task is complete to set the same flag with the same random value. The downside is that it could still create a random number that is in the range of an already spawned task. So you the more tasks it spawns the greater the chance a number is repeated.

 

If you want it to pick from a list simply have a condition of random 10% and flag x is true, with the action of setting flag x off for each task. Also make sure it is a "once" trigger. Whenever you want to pick a task you set X to true. The random 10% means that every second there is a 10% chance it becomes true, thus some options will be randomly evaluated as true earlier than others. By the nature of once triggers, after each one is executed it will be removed from the list.

 

Once> Time More 1 second> Flag 1 On

 

Once> Flag 1 Is True %% Random 10%> Activate Group A, Flag 1 Off

Once> Flag 1 Is True %% Random 10%> Activate Group B, Flag 1 Off

 

Once> Group B is Dead> Flag 1 On

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

Link to comment
Share on other sites

Hello Grimes,

 

Thank you very much for your help. "Picking from a list" is essentially what I want to do. If I am understanding this correctly, I would have 10 of the following setups:

 

"Once > Flag 1 is True && Random 10% > Start Task 1, Flag 1 off"

"Once > Flag 1 is True && Random 10% > Start Task 2, Flag 1 off"

"Once > Flag 1 is True && Random 10% > Start Task 3, Flag 1 off"

etc.....

 

All I would need to do is make Flag 1 = true and it will create a new task. Is there a bias for the triggers at the top of the list with this setup or is it simply a "footrace" until one of the 10 triggers fire?

 

Thanks again,

 

Habu


Edited by Habu23

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Yes there is bias toward the top of the list, but only if two or more triggers are evaluated true at the same time where it will always pick the "higher" trigger. You can use a lower random percentage to decrease the likely hood of two of them becoming true at the same time. But it should only trigger one at a time.

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

Link to comment
Share on other sites

After this random mission task is completed, I want the framework to randomly pick another task of the 10 available, excluding the task previously finished. This process will continue until all ten tasks have been completed without repeating a task.

 

I would like to do this with triggers if at all possible, but I would be willing to work with scripts if that is the only solution. Thank you guys for your help.

 

Habu

I have done this in Op Lagavulin using a combination of triggers and Lua.

In Lua I have created a task table which I then randomly re-order at mission start. As a task is assigned it is removed from the table of tasks. Once the task is completed the next task is taken off the top of the table, assigned then removed from the table. This also removes the bias problem.

 

The tasks in the table are essentially flag numbers which are set to true in Lua and picked up by Once triggers.

 

Take a look at my miz file, the Lua is in a lone soldier unit called Luaman at the North part of home base. The triggers are all at the begining of the long list and annotated clearly.

  • Like 1

i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q

Link to comment
Share on other sites

You could also make this with your original triggers set to continuous and trigger only when certain flag is off and then turn that flag on when new task has been activated. Then create triggers that check if the random task is completed and order a new randomization. If a already completed task is picked it will simply randomize again until it selects a task that's still untouched. This method will not instantly pick a new task when most of the tasks are completed but it shouldn't take too long as with 10 tasks the average time for choosing the last task would be 10 seconds.

 

In the following example I choose flag 11 as the "do not randomize" flag, flag 1-10 as task 1-10 complete, and flag 12 as the random flag.

 

The blueprint for the trigger for ordering new randomization and determining task completion:

 

Type:

continuous

 

Rules:

flag 12 is 0 (continue only if this task is selected)

flag 1 is true (if the task is already completed it's faster to check one flag than many conditions that might also have turned to false since task completion)

or

Flag 12 is 0 (continue only if this task is selected)

Task complete condition

 

Actions:

Set flag 1 (mark task 1 as completed)

Clear flag 11 ( when flag 11 is cleared, randomizing will trigger)

 

Change the mission start randomize triggers to continuous and make them so that they fire only when flag 11 is cleared. And add "set flag 11 true" action to the triggers that activate the tasks. Also make it so that the randomize trigger is the top one, followed by the task activation triggers and in the bottom the task completion checking triggers.

 

If you need to know when all the tasks have been completed add a trigger between task activation and completion triggers that checks if all the tasks have been completed and then set the random flag to a value outside of the task values so that none of them will trigger and no new tasks will be randomized.

 

Here's the whole thing but with 3 tasks only:

 

continuous > flag 11 is false > set flag 12 to random value between 0 and 2

continuous > flag 11 is false, flag 12 is 0 > activate task 1, set flag 11

continuous > flag 11 is false, flag 12 is 1 > activate task 2, set flag 11

continuous > flag 11 is false, flag 12 is 2 > activate task 3, set flag 11

once > flag 1 is true, flag 2 is true, flag 3 is true > set flag 12 to 3, message ("All tasks completed, RTB")

continuous > (flag 12 is 0, flag 1 is true) or (flag 12 is 0, task completion conditions) > set flag 1, clear flag 11

continuous > (flag 12 is 1, flag 2 is true) or (flag 12 is 1, task completion conditions) > set flag 2, clear flag 11

continuous > (flag 12 is 2, flag 3 is true) or (flag 12 is 2, task completion conditions) > set flag 3, clear flag 11

 

This might be a bit confusing post but hopefully it helps (and works as I haven't actually tested).

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

Hello Druid,

 

I am first trying the script method before I move on to Bushmanni's.

 

I have taken your advice and setup the triggers like your Op. Lagavulin. I have made Flags 1 through 10 as the flags that start Tasks #1 to #10. In addition, I have edited the "Initialise Menu" script on the Luaman unit as follows:

 

local lowest_flag = 1

local highest_flag = 10

 

Whenever I want to start a new task from the random list, do I just make a trigger that does the following: AITask > Run "Get Random Flag"?

 

Thank you very much for your help. Attached you will find an example mission to make sure i'm doing it correctly. Be advised that each task does not have an end trigger.

 

Habu

Randomized_Table.miz

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Whenever I want to start a new task from the random list, do I just make a trigger that does the following: AITask > Run "Get Random Flag"?

Yes that is correct.

I will be home in a couple of days when I can download yr miz and check it but it all sounds good to me. Have you tested it to see if it works,? if it does then you've done it all correctly.

 

The nice thing about this method is that all you have to do is change 2 numbers in the lua code to add more random trigger flags & clone more triggers with a simple change in each.

i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q

Link to comment
Share on other sites

Hello Bushmanni,

 

EDIT: Moderator- please delete attached file to this post.

 

I finally got your framework working and I am quite impressed! Initially I was having trouble because I was defining the task end flags in the following parts:

 

continuous > flag 11 is false, flag 12 is 0 > activate task 1, set flag 11

continuous > flag 11 is false, flag 12 is 1 > activate task 2, set flag 11

continuous > flag 11 is false, flag 12 is 2 > activate task 3, set flag 11

 

Please disregard the attached file as it has errors in it. I will make a new post with the correct template for making a "list" of randomized tasks that never repeat.

 

Thank you for your help!

 

Habu

Random_TriggerTask_Framework.miz


Edited by Habu23

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Haven't read all the thread in detail, but here's a link to mission I added to a previous thread on what appears to be the same subject. (whole thread's probably worth reading)

http://forums.eagle.ru/showpost.php?p=1355429&postcount=19

Here's something half finished that I think has what you're after but using the set flag between triggers...

 

Fly into an 'on station' zone, get assigned one of 5 tasks (gives a bulls reference, & a JTAC contact name & Hz).

At the moment when you've finished one it assigns another ( I think - I can't remember where I got to with it.) maybe you have to go back into the 'on station' zone - if not it should be easy enough to finish that off & make it that you have to go back to the zone.

 

Uploaded because there's no scripts in it just triggers to get the same effect.

 

 

(when I say half finished, I mean all the tasks aren't completely tested for playability, not that it doesn't work. The code works fine - or did in December when I last looked at it... )


Edited by Weta43

Cheers.

Link to comment
Share on other sites

It's like Nylon

(New York - London :-)

 

Don't know if you're interested Habu32, but you could trim the number of triggers you've used by rolling a few of them up into a single trigger using 'or' and 'and', and by using flag = a value rather than " flag < value + 1 and flag > value - 1 ".

 

From memory you had to do the way you did prior to the latest patch, but not any more...

 

In the end the same number of evaluations need to be done by the code (well less with flag =), but it's easier to read if you cut the number of 'triggers' by 30%.

Cheers.

Link to comment
Share on other sites

Attached is a working mission template that randomly picks one of 10 tasks. When this task is completed, it randomly selects another task without repeating until all tasks have been completed. To switch tasks, simply set one of the "end flags" as true.

 

Habu

 

Glad it worked. You might need to add a rule to check the current task flag to be active when checking if task is completed but that depends on the other stuff your mission is going to have but I would do it just to be safe. And what Weta43 said. Easier to read means less chance of making mistakes with triggers and easier and faster to debug.


Edited by Bushmanni
Added some more stuff

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

@Weta43:

 

I see what you are saying. Its more efficient to make the trigger "If Flag 1 = value 1" then "If flag 1 is greater than 0 and less than 2". It will probably lead to overall greater performance

 

@Bushmanni

 

Flags 100 through 1000 are the end task variables. I made it so that a task can only be selected if its "end task variable, 100, 200, 300, etc." is not defined for its given task. Simply defining any of these end task variables will permanently remove that task from the play-through.

 

Is this what you were recommending or am I mistaken?

 

Habu

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Habu,

 

yep your implementation of my lua random task generator was spot on, although in your triggers you had message to country USA so the messages weren't displaying (I changed them to message to all). Also you only had the Hawg triggering once. I added a switch to waypoint in the route so that it would continue to fly through the trigger zone.

 

I added some lua code to the 'AI get random task' to check when there are no tasks left. When this is so flag 999 is set to true. The hawg will then RTB on a switch waypoint condition of flag 99 true.

 

-- check to see if table is now empty & if it is set flag 999 to true
-- if not empty then set a task flag
if #random_flag_table == 0 
then trigger.setUserFlag(999,true) 
else
trigger.setUserFlag(random_flag_table[1],true)  -- sets a task flag to be checked for true in triggers
table.remove(random_flag_table,1)  -- remove the assigned task from the table
end

 

 

miz attached.

 

By the way I would save flags 1 to 99 for conditions on triggered actions e.g. switch waypoint, orbit. (you can only use flags 1-99 for those).

Randomized_Table.miz


Edited by Druid_

i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q

Link to comment
Share on other sites

@Bushmanni

 

Flags 100 through 1000 are the end task variables. I made it so that a task can only be selected if its "end task variable, 100, 200, 300, etc." is not defined for its given task. Simply defining any of these end task variables will permanently remove that task from the play-through.

 

Is this what you were recommending or am I mistaken?

 

Habu

 

Currently your "task complete" triggers will trigger even if the task is not active. So if you fly through the zones from 1 to 10 and 10 is the first active task you will complete all other tasks also even though only 10 was active. I'm not sure if this is problem for your final implementation but I just thought it would be good to point out.

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

Yes the "zones" were simply placed to test the framework. It was the only way I could think of testing it with my knowledge of mathematical logic hah. In real missions the end conditions would be a lot more elaborate "group destroyed, flag X, flag y, etc.)" so end conditions cannot be prematurely activated. Good notice, however.

 

Habu

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Hmm, know very little about the triggering of the mission builder, but on an item of logic maybe someone can answer.

 

What is the difference in taking 10 numbers and randomising them, then stepping through them in the random order, and taking the same 10 numbers, removing the first, then randomising the remainder and removing the first of what left. Does the first approach not yield the same result, the randomisation of the sequence of numbers.

 

I'm sure i'm missing something here.

Fish's Flight Sim Videos

[sIGPIC]I13700k, RTX4090, 64gb ram @ 3600, superUltraWide 5120x1440, 2560x1440, 1920x1080, Warthog, Tusba TQS, Reverb VR1000, Pico 4, Wifi6 router, 360/36 internet[/sIGPIC]

Link to comment
Share on other sites

There's no difference in end result, just how it's done in the mission editor. Or actually the latter one executes slightly slower but the difference is irrelevant. The main reason for existence for the latter approach is that it can be realized with editor triggers whereas the first one requires lua scripting.

DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community

--------------------------------------------------

SF Squadron

Link to comment
Share on other sites

What is the difference in taking 10 numbers and randomising them, then stepping through them in the random order, and taking the same 10 numbers, removing the first, then randomising the remainder and removing the first of what left. Does the first approach not yield the same result, the randomisation of the sequence of numbers.

You are correct in your assumption, although I'm not sure where you derived the second approach from. In the Lua method the task table is created at mission start then randomised. No further randomisation is done. Tasks are taken off the top of the list then removed in order. The trigger method uses flags to control the assignment but randomisation takes place only once for each task.

i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q

Link to comment
Share on other sites

"taking the same 10 numbers, removing the first, then randomising the remainder and removing the first of what left. Does the first approach not yield the same result, the randomisation of the sequence of numbers. "

 

That's not quite how I'd describe the trigger method, but you're right the end result for .LUA & Triggers is the same.

 

The trigger approach says -

 

(once some conditions are met)

keep picking random numbers between 1 and the number of tasks you have till you get one you haven't used. (first time - first number generated)

assign that task.

stop picking random numbers

 

once that task is complete, (& optionally once some conditions are met)

keep picking random numbers between 1 and the number of tasks you have till you get one you haven't used.

assign that task.

stop picking random numbers

 

etc....

 

once all numbers are used, don't re-start looking for random numbers.


Edited by Weta43

Cheers.

Link to comment
Share on other sites

  • 7 months later...

@Druid

 

I have a problem when I call "trigger.setUserFlag" it throw an exception

 

Seem that the current function call is trigger.action.setUserFlag!

But how can I convert an Integer value to a string in your solution????

 

Regards

My Rig: Windows 11 Pro, Intel i7-13700k@5.4GHz, 64GB DDR5 5200 RAM, Gigabyte Z790 AORUS Elite AX, 1TB Samsung EVO 970, RTX4080, Thrustmaster HOTAS WARTHOG + Saitek Pro Flight Pedals, LG 32" 4K 60FPS, ACER 30" 4K 60FPS GSync Display, HP Reverb G2 V2

Link to comment
Share on other sites

Yes the trigger.setUserFlag function changed to trigger.action.setUserFlag() sometime over the summer.

 

I don't understand what you are trying to do by converting an integer value to a string. However LUA does have the tostring() function.

 

newstring = tostring(integer)

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

Link to comment
Share on other sites

  • Recently Browsing   0 members

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