[HELP] Chance [++REP]
#1

Hi all
i'm trying to found a way to make a chance system on my Game Mode
what i'm looking for ?
well i'll try to explain every thing
I'm made a Command called /search, When the player is searching , he can found items, and i wanna make that this items will appear like : there is 30% chance to found ITEM A, 20% for Item B 40% for Item C 10% to found nothing.
before i was using the Random(X,Y) way but this isn't what i want
if anyone have ideas pleas share them
Reply
#2

pawn Код:
new result = random(100);
if(result <= 30) { do something  } //30%
if(result <= 40) { do something } //40%
etc.
Simple percentage. If there is a max of 100 percent, 30 percent of it will be 30/100, 40 percent will be 40/100 etc.

http://www.basic-mathematics.com/for...ercentage.html
Reply
#3

thiis should work thnks ++REP
Reply
#4

Quote:
Originally Posted by SaYrOn
Посмотреть сообщение
Why are you checking if result is equal or below?

If random will return 5, it will go through both of above if-statements. And chance will be equaled to 40.

You should rather check if result is in between two values, smth like:
pawn Код:
if(result >= 30 && result <= 39) { do something  } //30%
if(result >= 40 && result <= 49) { do something } //40%
What the fuck. The OP wants a 30% chance, not the value being between 30 and 40. 39-30 = 9, which means there will be a 9 percent chance. Go learn some simple maths please. This was just an example. I showed them how to calculate percentage.
Reply
#5

Both of them. The two lines were just example of how the OP can calculate the chance percentage.
Reply
#6

Nop i tested it and it's not working king_hual ...
Reply
#7

Code?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)