23.07.2012, 08:44
ok, if i didnt get you wrong, you got a simple lottery system, where any player can chose a /lotto number, ranging up from 1 to 100 - then at a time/command, the server shall see which numbers are being chosen by players, and draw one of them?
if so, heres some thoughts about solving your little problem:
-each player choses a number, and its supposed to be chosen once only. since this is the case,
-an array holding each number - chosen by which players aswell later - is required:
...now no number can be chosen twice, the array will get filled up with 1's when players play different numbers.
-the sizeof the numbers array is 100, a linear search through NumberTaken[] to collect all drawn numbers is a start..
-after all "only bet on" numbers are known, the new temoprary array AllNumbersTaken[] <= NumberTaken[100] after counting/collecting the players' bets.
-what when the 13 wins? the server knows THAT its the 13, and that there is 1 winner only indeed, due to the nature of "1 player per number" - so instead of looping through all players and checking for the /lotto number, the winner can be estimated the same way as the lotto number 13 itself. use an array, filled with pointers! an array like
...will serve as a pointer table - each cell contains a playerid, yours should be stored in cell [13], right?
when you type /lotto 13, and the NumberTaken[13]==0, thhe following line will set the same cell (13) to your playerid, to let the script get pointed to your playerid by accessing the winner cell 13:
so a loop to get the winner, could look like:
now, to get the playerid(yours) of the winner, simply read it out of the NumberTakenByID array which holds the playerid in each lotto-number cell, thats where the pointer steps in:
hm.. i hope i didnt forget something vital.. ah, the new declarations are missing, but youll add them when converting your variable names. i like the idea of a lottery where always one player wins, but makes the jackpot not dynamic. think ybout a way to increase the motivation of players to play lotto, like a percentual amount of the server economy added to the jackpot, or donations being added to it aswell...
if so, heres some thoughts about solving your little problem:
-each player choses a number, and its supposed to be chosen once only. since this is the case,
-an array holding each number - chosen by which players aswell later - is required:
pawn Code:
new NumberTaken[100];//if you /lotto 13, then NumberTaken[13]=1 so no player can bet on 13 anymore.
-the sizeof the numbers array is 100, a linear search through NumberTaken[] to collect all drawn numbers is a start..
-after all "only bet on" numbers are known, the new temoprary array AllNumbersTaken[] <= NumberTaken[100] after counting/collecting the players' bets.
-what when the 13 wins? the server knows THAT its the 13, and that there is 1 winner only indeed, due to the nature of "1 player per number" - so instead of looping through all players and checking for the /lotto number, the winner can be estimated the same way as the lotto number 13 itself. use an array, filled with pointers! an array like
pawn Code:
new NumberTakenByID[MAX_PLAYERS];
when you type /lotto 13, and the NumberTaken[13]==0, thhe following line will set the same cell (13) to your playerid, to let the script get pointed to your playerid by accessing the winner cell 13:
pawn Code:
NumberTaken[13]=1;//old one. your bet got accepted...
NumberTakenByID[13]=playerid (yours);//the 13 should be a sscanf-ed variable indeed...
pawn Code:
new AllNumbersTaken[100];
new Found;//0 numbers are known to be potential winners, yet.
for(new ANT=1;ANT<100;ANT++)//all numbers from 1 to 100
{
if(NumberTaken[ANT]==1)//gets checked if theyre taken by any playerid
{
AllNumbersTaken[Found]=ANT;//start at cell 0 of the temp array, and
Found++;//prepare to write into the next cell.
}
}
new NumberWins=random(sizeof(AllNumbersTaken));//pick a random lotto number from the "played only" table
pawn Code:
new JackpotID=NumberTakenByID[NumberWins];