• 🏆 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!

Random Resource Problem

Status
Not open for further replies.
  • Random Resource Button
    • Events
      • Dialog - A dialog button is clicked for ResourceChooseDialog
    • Conditions
      • (Clicked dialog button) Equal to ResourceChooseButtons[4]
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 3) Equal to 1
        • Then - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Player - Set (Picked player) Current gold to 10000
              • Player - Set (Picked player) Current lumber to 5000
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 3) Equal to 2
            • Then - Actions
              • Player Group - Pick every player in (All players) and do (Actions)
                • Loop - Actions
                  • Player - Set (Picked player) Current gold to 5000
                  • Player - Set (Picked player) Current lumber to 2000
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 3) Equal to 3
                • Then - Actions
                  • Player Group - Pick every player in (All players) and do (Actions)
                    • Loop - Actions
                      • Player - Set (Picked player) Current gold to 2100
                      • Player - Set (Picked player) Current lumber to 1100
                • Else - Actions

sometimes, I got 0 resources (only some rare occasions)
wat is the problem :C
and what should I do?
 
The problem is the false usage of random.
Either you save the random number before the if and then compare it to 1, 2 and 3 or you change the borders:
first if: random(1,3)==1
second if: random(1,2)==1
third if: inexistant, use the else of the second if.

the current script will give you with the chance 2/3*2/3*2/3= 8/27 no ressources becaude the three random numbers he calculates are each different from the one wich is checked
 
  • Random Resource Button
    • Events
      • Dialog - A dialog button is clicked for ResourceChooseDialog
    • Conditions
      • (Clicked dialog button) Equal to ResourceChooseButtons[4]
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 3) Equal to 1
        • Then - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Player - Set (Picked player) Current gold to 10000
              • Player - Set (Picked player) Current lumber to 5000
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 3) Equal to 2
            • Then - Actions
              • Player Group - Pick every player in (All players) and do (Actions)
                • Loop - Actions
                  • Player - Set (Picked player) Current gold to 5000
                  • Player - Set (Picked player) Current lumber to 2000
            • Else - Actions
              • Player Group - Pick every player in (All players) and do (Actions)
                • Loop - Actions
                  • Player - Set (Picked player) Current gold to 2100
                  • Player - Set (Picked player) Current lumber to 1100
like this?
 
  • Random Resource Button
  • Events
  • Dialog - A dialog button is clicked for ResourceChooseDialog
  • Conditions
  • (Clicked dialog button) Equal to ResourceChooseButtons[4]
  • Actions
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • (Random integer number between 1 and 3) Equal to 1
  • Then - Actions
  • Player Group - Pick every player in (All players) and do (Actions)
  • Loop - Actions
  • Player - Set (Picked player) Current gold to 10000
  • Player - Set (Picked player) Current lumber to 5000
  • Else - Actions
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • (Random integer number between 1 and 2) Equal to 2
  • Then - Actions
  • Player Group - Pick every player in (All players) and do (Actions)
  • Loop - Actions
  • Player - Set (Picked player) Current gold to 5000
  • Player - Set (Picked player) Current lumber to 2000
  • Else - Actions
  • Player Group - Pick every player in (All players) and do (Actions)
  • Loop - Actions
  • Player - Set (Picked player) Current gold to 2100
  • Player - Set (Picked player) Current lumber to 1100
more like this. you forgot to change the second if. the chances there should be 1/2, 1/2 and not 1/3, 2/3.
Edit: Oups, spaces messed up. But i think you got the point
 
Status
Not open for further replies.
Top