Solved How do i add weight to an item so like 1/2 or 1/4 like chances of getting item

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

FindME

Active Member
Jul 5, 2023
58
3
8
on step on pressure plate:
if event-block is a iron pressure plate:
if block below event-location is iron block:
set {_number} to a random integer between 1 and 4
if {_number} is 1:
give player iron nugget named "&fIron Nugget" with lore "This is worth 25¢"
if {_number} is 2:
give player white dye named "&fIron Chunk" with lore "This is worth 5$"
if {_number} is 3:
give player iron ingot named "&fIron Ingot" with lore "This is worth 25$"
if {_number} is 4:
give player iron nugget named "&fIron Block" with lore "This is worth 500$"
wait 1 tick
 
The issue you have with your code is that you're checking for the specific number. In all of the weighted chances I've developed/made; I would approach this kinda thing like the code I have provided below:

Code:
set {_number} to a random integer between 1 and 100
if {_number} is between 1 and 50: # 50% chance basically
   give player 1 of iron nugget named "&fIron Nugget" with lore "This is worth 25¢"
else:
   give player 1 of white dye named "&fIron Chunk" with lore "This is worth 5$"

However, this is not the only way to do this kind of chance system! You can also simply use "chance of 50%:" or "chance of 25%:". Another final option is to set up a list variable to contain all the potential items you can get. Then you can just set a variable to a random element of said list variable and you will have an equal chance getting any potential item.

Hopefully this will resolve your issue and give you some great insights on how to resolve similar issues using a RNG based system!