[HELP] Chance [++REP] - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Chance [++REP] (
/showthread.php?tid=382406)
[HELP] Chance [++REP] -
Amine_Mejrhirrou - 03.10.2012
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
Re: [HELP] Chance [++REP] -
KingHual - 03.10.2012
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
Re : [HELP] Chance [++REP] -
Amine_Mejrhirrou - 03.10.2012
thiis should work thnks ++REP
Re: [HELP] Chance [++REP] -
KingHual - 03.10.2012
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.
Re: [HELP] Chance [++REP] -
KingHual - 03.10.2012
Both of them. The two lines were just example of how the OP can calculate the chance percentage.
Re : [HELP] Chance [++REP] -
Amine_Mejrhirrou - 04.10.2012
Nop i tested it and it's not working king_hual ...
Re: [HELP] Chance [++REP] -
KingHual - 04.10.2012
Code?