AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   win percent (https://forums.alliedmods.net/showthread.php?t=312365)

CrazY. 11-29-2018 08:27

win percent
 
Hello, I'm trying to announce a winner based in player's win chance percent. I already managed to calculate the chance percent but I'm getting some trouble to announce the winner.

The max money that player can gamble it's 50,000 and max win chance percent it's 50%. What I did then was generate a random number between 0 and win chance percent in 50,000 (50% = 25,000).I noticed that sometimes player with 1% of chance win against a player of 50% of chance, so my code it's not right.

Someone have idea?

Code:
// iMaxDeposit = 50,000 // rgJackpot[JP_PLAYER_CASH] = cash that player gambled something() {     ArraySort(g_aJackpot, "arrayJackpotSort");     for (new i = 0; i < iMax; i++)     {         ArrayGetArray(g_aJackpot, i, rgJackpot);         if (iWinner == -1)         {             iWinPercent = floatround(float(rgJackpot[JP_PLAYER_CASH]) / float(iMaxDeposit) * 50.0);             iRandomNum = floatround((float(iWinPercent) * float(iMaxDeposit)) / 100.0);             if (iRandomNum <= random_num(1, iMaxDeposit))                 iWinner = i;         }         iReward += rgJackpot[JP_PLAYER_CASH];     } } public arrayJackpotSort(Array:aWhich, iItem1, iItem2) {     new rgJackpot[2][eJackpot];     ArrayGetArray(aWhich, iItem1, rgJackpot[0]);     ArrayGetArray(aWhich, iItem2, rgJackpot[1]);     if (rgJackpot[0][JP_PLAYER_CASH] > rgJackpot[1][JP_PLAYER_CASH])         return 1;     return -1; }

klippy 11-29-2018 08:44

Re: win percent
 
I can't even wrap my head around what your code is actually trying to do, your algorithm just seems very wrong.
Describe the rules of your game precisely.

Natsheh 11-29-2018 09:05

Re: win percent
 
I already made an effective jackpot plugin take alook it might be helpful.
https://forums.alliedmods.net/showpo...2&postcount=17

As klippy said you have something wrong with your calculations, win chance it depends on the player money in jackpot divide by total amount of money in the jackpot multiplied by 100 so it would be an integer also it cant be 50 percent unless all players have the same amount of money in the jackpot.


All times are GMT -4. The time now is 07:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.