• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to setup chances?

Status
Not open for further replies.
Level 6
Joined
Dec 9, 2014
Messages
176
I have a few instances where I need the game to choose something based on a set up chance such as a few items that an drop from certain npcs. A chance for a dialog button click to do one thing or another, like an "intimidate" success or fail for instance. Any help is much appreciated!
 
Level 25
Joined
May 11, 2007
Messages
4,651
  • dz is so sexy oh yees Im going to get the golden ring and will conquer the world
    • Events
      • Destructible - A destructible within (Initial camera bounds) dies
    • Conditions
    • Actions
      • Set tempInt = (Random integer number between 1 and 10)
      • -------- 10% chance to do something --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempInt Equal to 5
        • Then - Actions
          • Game - Display to (All players) the text: I WANT TO RULE THE ...
        • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Although random integers are probably the fastest approach there are other ways. Specifically random integers do not map well with probability theory since they behave more like a dice (something to model) rather than using probabilities directly.

In mathematics probability is often represented as a real number in the range of 0 (impossible) to 1 (always). Various formula can be applied to combine or remove probabilities in various ways. As such what you can do is use a random real between 0 and 1 and test if it is less than or equal to the desired probability. This is particularly useful if your probability is computed from some formula using probability theory. The main disadvantage is that unlike real numbers which are continuous, the WC3 real type is based on float so is not continuous. As such it is possible for probability distribution to be slightly skewed and some probabilities being impossible to represent exactly.
 
Level 6
Joined
Dec 9, 2014
Messages
176
Although random integers are probably the fastest approach there are other ways. Specifically random integers do not map well with probability theory since they behave more like a dice (something to model) rather than using probabilities directly.

In mathematics probability is often represented as a real number in the range of 0 (impossible) to 1 (always). Various formula can be applied to combine or remove probabilities in various ways. As such what you can do is use a random real between 0 and 1 and test if it is less than or equal to the desired probability. This is particularly useful if your probability is computed from some formula using probability theory. The main disadvantage is that unlike real numbers which are continuous, the WC3 real type is based on float so is not continuous. As such it is possible for probability distribution to be slightly skewed and some probabilities being impossible to represent exactly.

Fortunately, I don't need exact chances. I just want low chances for good items, really low chances for great items, and higher chances for basic items. For the intimidate check, I'm just going to have that a 50/50 chance in the beginning of the game and have that chance change based off certain factors like level or stats.
 
Level 6
Joined
Dec 9, 2014
Messages
176
I'm having a bit of trouble here. I think one of the triggers is wrong. I made it tell me what the number is during testing to make sure it's doing the right thing but even when the number is greater than 50 it still does the success trigger. The reason why I have the number between 1 and 100 is that I plan to change the variable later in game and I'd like to be able to make the chances better. Any help here?

  • Tybalt Intimidate Check
    • Events
      • Dialog - A dialog button is clicked for TybaltResponseWindow2
    • Conditions
      • (Clicked dialog button) Equal to TybaltResponseButton2[2]
    • Actions
      • Set IntimidateCheck = (Random integer number between 1 and 100)
      • Game - Display to (All players) the text: (String(IntimidateCheck))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IntimidateCheck Equal to (Min(50, 100))
        • Then - Actions
          • Sound - Play Warning <gen>
          • Unit - Replace Captain Tybalt 0005 <gen> with a Captain Tybalt (Targetable) using The old unit's relative life and mana
          • Set TybaltHostile = (Last replaced unit)
          • Unit - Change ownership of TybaltHostile to Player 10 (Light Blue) and Retain color
          • Sound - Play FootmanYesAttack3 <gen> at 100.00% volume, attached to TybaltHostile
          • Unit - Replace Brom 0006 <gen> with a Brom (Targetable) using The old unit's relative life and mana
          • Set BromHostile = (Last replaced unit)
          • Unit - Change ownership of BromHostile to Player 10 (Light Blue) and Retain color
          • Set ApprenticesHostile = Apprentice Mage
          • Unit Group - Pick every unit in (Units owned by Neutral Passive of type ApprenticesHostile) and do (Actions)
            • Loop - Actions
              • Unit - Replace (Picked unit) with a Apprentice Mage (Targetable) using The old unit's relative life and mana
              • Set ApprenticesHostile = (Unit-type of (Last replaced unit))
              • Unit - Change ownership of (Picked unit) to Player 10 (Light Blue) and Retain color
        • Else - Actions
          • Sound - Play GoodJob <gen>
          • Game - Display to Player Group - Player 1 (Red) the text: |cff7777aaCapt Tyba...
          • Wait 6.50 seconds
          • Unit - Order Captain Tybalt 0005 <gen> to Move To (Center of ByTheCrates <gen>)
          • Wait 6.00 seconds
          • Unit - Order Captain Tybalt 0005 <gen> to Move To (Center of ByTheFire <gen>)
          • Wait 3.00 seconds
          • Item - Create Tybalts Rations at (Center of ByTheFire <gen>)
          • Item - Create Ring of Gypsies at (Center of ByTheFire <gen>)
          • Unit - Make Captain Tybalt 0005 <gen> face Sorceress over 0.80 seconds
          • Unit - Make Captain Tybalt 0005 <gen> face Wizard over 0.80 seconds
 
Level 6
Joined
Dec 9, 2014
Messages
176
How would I make it so it looks for a number between 2 numbers without using a different integer variable? What I mean is, it will generate a random integer between 1-100, if the number is between 1 - 40 then it does one thing, but if its between 41 - 70 it does something different, if it's between 71 - 80 then it does another, 81-85, and finally if it's between 86 - 100 then nothing happens.
 
Level 21
Joined
Aug 13, 2011
Messages
739
  • Events
  • Conditions
  • Actions
    • Set TempInteger = (Random integer number between 1 and 100)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInteger Less than or equal to 40
      • Then - Actions
        • -------- Action 1 --------
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInteger Greater than 40
        • TempInteger Less than or equal to 70
      • Then - Actions
        • -------- Action 2 --------
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInteger Greater than 70
        • TempInteger Less than or equal to 80
      • Then - Actions
        • -------- Action 3 --------
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInteger Greater than 80
        • TempInteger Less than or equal to 85
      • Then - Actions
        • -------- Action 4 --------
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • TempInteger Greater than 85
      • Then - Actions
        • -------- Action 5 --------
      • Else - Actions
Note that all of the Less Than have Less Than or Equal To.
 
Status
Not open for further replies.
Top