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;
}
__________________