DCS editor Randomization

From DCS World Wiki - Hoggitworld.com
Revision as of 09:01, 13 April 2018 by Grimes (talk | contribs) (Created page with "'''Random Condition''' The trigger condition "Random %" has proven to be a source of confusion to many mission builders. This page is meant to clarify how ''Random'' is used...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Random Condition The trigger condition "Random %" has proven to be a source of confusion to many mission builders. This page is meant to clarify how Random is used in the simulator and gives some samples.

Intro

Randomization triggers rely on the rules of how triggers are checked. Please familiarize yourself with how triggers operate if needed: Trigger Basics

The mission editor and the simulator scripting engine have several options to create random events. This article is focused mainly on the mission editor and its trigger functions, however some scripting engine topics will be covered.

The mission editor has three separate sections which contain randomization.

  • Triggers
  • Group Condition
  • Group Waypoint Actions/Triggered Actions

Triggers

  • Condition: Random x%
  • Action: Flag Set Random Value

Group Condition

The group condition is comprised of two values, a lua condition and a percentage. Both are checked while the mission loads to determine of a group will exist in the mission.


Group Waypoint Actions/Triggered Actions

  • Probability

The wiki article uses pseudo code to represent triggers and are written in the following format.

Breakdown Condition Type > Trigger Condition > Trigger Action
Psuedo Code Once > Random 50% > Flag 1 On

How it Works

Triggers

Consider the following trigger condition:

Once > Random 50% > Flag 1 On

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.

As long as the conditions allow the trigger to be checked again, any trigger with the condition "Random x%" will eventually become true! The value of X simply dictates the chance the condition will be true on each check.

Mission Start> Random 50% > Flag 1 On

Is checked only once at mission start.

Once> Time Less than 5> Set Flag 1 Random Value from 1 to 5

This trigger sets a random value for flag 1 to inclusively within the range 1 and 5. Thus the options are 1, 2, 3, 4, or 5. It is similar to setting a random 20% condition, but not quite.

  • Use Random 20% if you have ONE option that you want to have a 20% chance of spawning
  • Use Flag Set Flag 1 Random Value from 1 to 5 if you want ONE OF FIVE options to spawn

Group Condition

Condition is a lua script that is run during the mission loading process. Anything in this box will run after the "initialization script" but before scripts ran via "mission start" triggers.

Percentage is a raw percentage chance of the group existing within the mission. If deemed to be false the group is effectively removed similar to a "Group Deactivate" trigger and can no longer be spawned at a later time.

Group Waypoint Actions/Triggered Actions

The Probability entry exists within a groups waypoint and triggered actions "Start Condition" and "Stop Condition" boxes. This condition can be checked when the task starts or the conditions for the task to end are true. Thus you can have several actions that may randomly occur without utilizing triggers to randomize the action. Keep in mind that waypoint actions are processed sequentially.


Examples

The most common uses for random % and Flag Set Random Value is to randomly make a choice or make an event occur at a randomized time. Random choices or timings can add to the replay-ability of a mission by adding an unknown layer to the mission. The more random options, the less likely a player is to experience a mission the exact same way as a previous playthrough.

Random Choice

Random Choices are most often used to randomly spawn in an enemy threat or objective. Common methods and how they work are described below.

Mission Start

Mission Start> Random 50% > Activate Group 1
Mission Start> Random 50% > Activate Group 2
Mission Start> Random 50% > Activate Group n

These triggers have a chance to spawn anywhere from 0 to n groups into the mission at mission start. The Random x% value heavily influences the number of groups that spawn. PRO: Easy to use, only checked once CON: Purely random, there is no control over what does and doesn't spawn.

Group Condition

Set condition 50% for Group 1
Set condition 30% for Group 2
Set condition 20% for Group n

Setting a group condition is functionally similar to Mission Start conditions but is little more direct. PRO: Easiest to use, only checked once CON: Group is removed from existence and cannot be spawned later.

Single Choice from List

Once > Random 5% AND Flag 1 is False > Activate Group 1 AND Set Flag 1 True
Once > Random 5% AND Flag 1 is False > Activate Group 2 AND Set Flag 1 True
Once > Random 5% AND Flag 1 is False > Activate Group n AND Set Flag 1 True

This method works on the idea that the condition must become true eventually and that each trigger requires flag 1 to be false in order to evaluate. When a choice is made it performs the desired action and it sets flag 1 to true. By setting flag 1 to true the remaining triggers will not evaluate. If desired, flag 1 can be set false later in the mission to prompt another choice from whichever triggers is remaining.

Multiple Choice from List

Once > Random 5% AND Flag 1 is less than 2 > Activate Group 1 AND Flag 1 Increase 1
Once > Random 5% AND Flag 1 is less than 2 > Activate Group 2 AND Flag 1 Increase 1
Once > Random 5% AND Flag 1 is less than 2 > Activate Group n AND Flag 1 Increase 1

This example will randomly pick 2 groups to activate. This method is similar to "Single Choice From List", however it uses slightly different conditions and actions to allow for multiple choices be made. Flag 1 defaults to a value of 0 (false), when each random choice is made the value of flag 1 is increased by 1. The conditions are permitted to evaluate as long as flag 1 is less than 2.

Random Integer List

Once> Time Less than 5> Set Flag 1 Random Value from 1 to 5
Once > Flag 1 Equals 1> Activate Group 1
Once > Flag 1 Equals 2 > Activate Group 2
Once > Flag 1 Equals 3 > Activate Group n

This example sets an initial random flag value and each option has a single value which can be true to activate the relevant group.

Randomized Multiple Choice from List

Once> Time Less than 5> Set Flag 2 Random Value from 2 to 5
Once > Random 5% AND Flag 1 is less than flag 2 > Activate Group 1 AND Flag 1 Increase 1
Once > Random 5% AND Flag 1 is less than flag 2 > Activate Group 2 AND Flag 1 Increase 1
Once > Random 5% AND Flag 1 is less than flag 2 > Activate Group n AND Flag 1 Increase 1

This example sets a random value between 2 and 5 to define how many groups can activate. This example is similar to "Multiple Choice From List", with the key difference being that the number of groups spawned is randomized.

Choice Range from List

Once> Time Less than 5> Set Flag 1 Random Value from 10 to 50
Once > Flag 1 is greater than 0 AND Flag 1 is Less than 15> Activate Group 1
Once > Flag 1 is greater than 10 AND Flag 1 is Less than 25 > Activate Group 2
Once > Flag 1 is greater than 20 AND Flag 1 is Less than 35 > Activate Group n

This example sets a random value for a single flag and each option has a value range for the randomized flag in order to become true. Depending on the value overlap, this method can produce different results, however the randomization depends on the grouping overlap. In this example the first trigger will never also be true at the same time as the 3rd trigger.

True/False Combination

Mission Start > Random 50% > Set Flag 1 True
Mission Start > Random 50% > Set Flag 2 True
Once > Flag 1 is False AND Flag 2 False> Activate Group 1
Once > Flag 1 is False AND Flag 2 True> Activate Group 2
Once > Flag 1 is True AND Flag 2 False> Activate Group 3
Once > Flag 1 is True AND Flag 2 True> Activate Group 4

This is the true/false or also known as a binary method. It depends on the total random possibilities that exist with n coin flips. Generally this method is only used with one or two random chances, anything more than that and it gets confusing.

Random Time Delay

Simple

Once > Random 10% > Set Flag 1 True
Once > Random 2% > Set Flag 2 True

By the logic that these conditions are constantly re-evaluated, both of these triggers will evaluate true if given enough time. The smaller a chance, the longer it will take for the condition to become true. In this example flag 1 will likely become true before flag 2. You can use multiple Random x% conditions to make more complex numbers.

Once > Random 2% AND Random 2%> Set Flag 1 True
Once > Random 1% AND Random 1%> Set Flag 2 True
  • First trigger is the same as a random 1%
  • Second trigger is the same as random 0.5%

Inverse

Continuous > Random 95% > Set Flag 1 True
Once >Time Since Flag 1 is 2 seconds > Activate Group 1

This method is basically the same as the one above, however it uses the inverse approach and applies flag logic to get an interesting result. 95% of the time Flag 1 is set to true. Thus the "Time Since Flag" is nearly constantly reset back to 0. 5% of the time it won't get reset, when its not reset the group will activate.

Random Countdown

Once > Time Less than 5 > Set Flag 1 Random Value from 50 to 100
Switched Condition >Time Since Flag 1 is 30 seconds > Flag 1 Decrease 1
Once > Flag 1 Equals 1 > Activate Group

This method is based on setting an initial value and then counting down by 1 at a set rate until the value equals 1 to spawn a group. In this example the group will spawn somewhere between 25 and 50 minutes. It is highly flexible in that the random time it takes for the group to activate is easily defined. The "rate" in this example, the 2nd trigger, can be raised or lowered to drastically change the time it takes for the group to spawn. Changeing the 2nd trigger to the following will result in a random time between 4.1 and 8.3 minutes.

Switched Condition >Time Since Flag 1 is 5 seconds > Flag 1 Decrease 1