Rework the "Chance" trigger

Hello. Currently, in AoE2 DE, the Chance trigger in the scenario editor has a very peculiar effect. Basically, you give it a value, from 1-100 (as far as I can tell), and it effectively continually roles a dice until it gets a value less than or equal to your input (I think). Then it performs the effects of the trigger. This is incredibly stupid. I cannot see why or how anyone would ever use this.

My suggestion:
The die only roles once, as a random number. The input is made clearly a probabilty value, so people know that the die will perform a success if it gets a value less than or equal to the input value. Maybe add a looping option if anyone wants it to perform the way it does currently. Then also possibly: each chance trigger can be assigned to a “chance variable”. The purpose of this is say, you have three chance triggers. The first is a 33% chance, the second is 66%, and the third is 100%. All three triggers are assigned to chance variable one. When it runs the triggers it runs the highest trigger in each group, on a success it deactivates all other triggers in the group. On a failure it moves on to the next trigger in that group. This would be a much better thing to do than the current system in my opinion.
What do people think?

I made a acneario, exploding bird nothing, that relies on the chance triggers.

But they do not seem perfectly random and appear have the standard problems of linead congruent number generators (I. E. they repeat itself and the same values all over again instead of truly random)

Atleast last time I checked

I agree the Chance trigger is very unintuitive. Understanding how it works really requires an in-depth understanding of the trigger system and the “trigger loop”.

Once every in-game second:

  • The list of triggers is checked from top to bottom.
  • If a trigger is active, then its condition list is checked from top to bottom.
  • If all of the conditions succeed, then the trigger effects are executed and, if the trigger is not set to “looping”, then it is deactivated.

How the chance trigger then works is that every time the game checks the list of triggers, it will generate a random number to determine if the chance condition passes or fails. If it fails, the trigger remains active, and its list of conditions is checked again on the iteration of this trigger loop.

I typically use Chance conditions by combining multiple triggers.

Trigger 1:
  Condition: Whatever you want to happen that starts the random number generation.
  Effect: Activate Trigger 2
  Effect: Activate Trigger 3
Trigger 2:
  Starting State: Off
  Condition: Chance
  Effect: Whatever you want to happen when the chance succeeds.
Trigger 3:
  Starting State: Off
  Effect: Deactivate Trigger 2

Here you setup the conditions in your scenario for activating a random number generation. Perhaps if you bring a hero to a certain location, you have a random chance of getting a reward. That is the condition for the first trigger. When the condition succeeds, the next two triggers are activated.

The second trigger generates the random number. The effect is executed only when the chance condition is passed by the random number generator. Then the third trigger deactivates the second trigger. That way the chance condition is checked only once, not repeatedly every game second.

There’s more you can do here, such as having the 2nd trigger deactivate the 3rd and giving the 3rd trigger effects for what to do when the chance “fails”. The important part is making sure the triggers are created in the correct “order” so you can control their activation/deactivation.

It’s definitely a confusing topic that could benefit from being redesigned. I’m just not exactly sure what that redesign should be (perhaps introduce a new Chance condition that automatically deactivates the trigger regardless of whether it passes or fails, but that could still be awkward in situations where the Chance is combined with other conditions).

Unless DE changed this, then Aoe2 uses a linear congruential generator seeded by time at the start of the game.


Do you know the parameters de uses for its congruential generator? Other than the seed

Here is a Javascript re-implementation of it:

1 Like

First thank you t-West!

Do you know, What’s the point of those bitwise | 0, does that even do anything, because in my understanding it doesn’t?

I think that’s to ensure Javascript uses 32 bit integers.

1 Like