• 🏆 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 items with different %-chance of spawning

Status
Not open for further replies.
Level 5
Joined
Nov 7, 2007
Messages
134
I am making a map where a trigger will create a random item from a certain selection of item-types. I wonder if there is a way to make some item-types have a higher chances of spawning than others? For example, there could be a 50% chance of an item from the "bad item group" spawning, while there is a 20% chance of an item from the "good item group" spawning. How can this be done?

EDIT: I figured out how to spawn random items from one item group, by using a Item-type variable with an array of 5, and then storing different items in every index-number, and finally making an action that says "Create Item(Random number from 1 to 5)". But this still just creates items from one item group, with the same percent chance for every item, but I want some items to have a different chance of spawning.
 
Last edited:
Level 8
Joined
Aug 21, 2009
Messages
333
This wouldn't be too hard:

  • Item Drop
    • Events
      • Unit - A unit dies
    • Conditions
      • (Unit-type of (Dying Unit)) equals ("whatever unit type you are using")
    • Actions
      • Set (temp_rand) equal to random real between (0.00) and (1.00)
      • Set (temp_loc) equal to (Position of (Dying Unit))
      • If (All Conditions are True) then do (Then Actions), else do (Else Actions)
        • If - Conditions
          • (temp_rand) is less than (0.50)
        • Then - Actions
          • Item - Create (bad item) at (temp_loc)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions), else do (Else Actions)
            • If - Conditions
              • (temp_rand) is less than (0.70)
            • Then - Actions
              • Item - Create (good item) at (temp_loc)
            • Else - Actions
      • Custom Script: call RemoveLocation(udg_temp_loc)
That should do it :D
 
Level 5
Joined
Nov 7, 2007
Messages
134
Actually, I think I figured out a way to do it just before you posted that, but thank you anyway, you can have some rep for the trouble :)
 
Level 8
Joined
Aug 21, 2009
Messages
333
Also, if you are using an Item-Type array, you could just put the same item in a few times to make it more likely:

Item-type[1] = item 1
Item-type[2] = item 1
Item-type[3] = item 1
Item-type[4] = item 1
Item-type[5] = item 1
Item-type[6] = item 2
Item-type[7] = item 2
Item-type[8] = item 2
Item-type[9] = item 3
Item-type[10] = item 4
 
Level 5
Joined
Nov 7, 2007
Messages
134
Also, if you are using an Item-Type array, you could just put the same item in a few times to make it more likely:

Item-type[1] = item 1
Item-type[2] = item 1
Item-type[3] = item 1
Item-type[4] = item 1
Item-type[5] = item 1
Item-type[6] = item 2
Item-type[7] = item 2
Item-type[8] = item 2
Item-type[9] = item 3
Item-type[10] = item 4

Yeah, that was what I thought of as well :p
 
Status
Not open for further replies.
Top