Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

??Random system??

This is my 1st post im making here and i REALLY need help making a random system for a prize chest that gives a random item i need help on how to go about doing this.

i want a system that when the user press enter when facing the chest (like an event) it will give an absoluley random item BUT more chance of giving say a potion than a rare item. i was thinking and i tryed making a random number sytem where the system picks 10 random numbers and if to are alike then the player recives the item wich corrosponse with the number (eg; if 001 is picked twice then the user would recive a potion as the potions ID number is 001) and yea.
 
First off, you'd need to set your items up so that common items come before the rare items - in this example I'll assume common items in places 1-100 and rare items in 101-120.


Now, here's some code for your event:
(V1 and V2 are variables)

Label: try again
V1 = random(1..120)
If V1 > 100
  V2 = random(1..10)
  If V2 < 5
    Go to label: try again
  End
End
Gain item with index V1


EDIT::
  What this does is set V1 to a random number between 1 and the highest item index in your database. If the index is high enough to be a random item, there's a 50% chance of it selecting a new index. Finally, the item is given to the party.
 
Well there's an easier way to do it, using only one variable, but it might take more time.

First make a variable called RANDOM, and try this:
Code:
@>Control Variables: [0001: RANDOM] = Random No. (0...5)
@>Conditional Branch: Variable [0001: RANDOM] <= 3
  @>Change Items: [Potion], += 1
  @>
 : Else
  @>Change Items: [Rare Item], +=1
 : Branch End
@>

What this does is, if the random variable is equal to 1, 2, or 3, you get a potion; but if it's 4 or 5, you get a rare item. So you basically have a 2/5 chance to getting a rare item. You can change the random number, from say 1-10 for different results. Hope that helped.
 
Both systems are effective. Jimme's requires less commands, but limits the items to 'classes' or 'types', each class having a probability.  Regimos is a lot more commands, but allows you to set the probability for each item.
Fatefullme, what are you looking for? and will you have 'special' items that aren't available from chests?

Be Well
 
Brewmeister":22dglacp said:
Both systems are effective. Jimme's requires less commands, but limits the items to 'classes' or 'types', each class having a probability.  Regimos is a lot more commands, but allows you to set the probability for each item.
Fatefullme, what are you looking for? and will you have 'special' items that aren't available from chests?

Be Well
Yea like specific items for each chest, like a fire maze chest containing a piece of fire armor and a earth maze chest containing earth armor. also like "Lucky dip" things for minigames
 
Regimos":oq2bgqe5 said:
Well there's an easier way to do it, using only one variable, but it might take more time.

First make a variable called RANDOM, and try this:
Code:
@>Control Variables: [0001: RANDOM] = Random No. (0...5)
@>Conditional Branch: Variable [0001: RANDOM] <= 3
  @>Change Items: [Potion], += 1
  @>
 : Else
  @>Change Items: [Rare Item], +=1
 : Branch End
@>

What this does is, if the random variable is equal to 1, 2, or 3, you get a potion; but if it's 4 or 5, you get a rare item. So you basically have a 2/5 chance to getting a rare item. You can change the random number, from say 1-10 for different results. Hope that helped.

I very much like this system. thanks!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top