I've looked at his script and I don't really see anything wrong with it, and tested mine.
PHP Code:
function onCreated() {
for (temp.t = 0; temp.t < 5; temp.t++) {
test();
}
}
function test() {
temp.accts = {
"a", "b", "c", "d", "e"
};
clearAccounts();
for (temp.acct: temp.accts) {
for (temp.i = 0; temp.i < 3; temp.i++) {
addAccount(temp.acct);
}
}
echo("People entered " @ this.lottery.size() SPC "Winner " @ pickLotteryWinner());
}
// Adds account to the list of lottery entries
public function addAccount(acct) {
if (inLottery(acct)) {
// Already in lottery
return false;
} else {
// Add to lottery
this.lottery.add(acct);
this.trigger("update"); // Force-saves DB
return true;
}
}
// Checks if acct is entered in the lottery
public function inLottery(acct) {
return (acct in this.lottery);
}
// Clears accounts entered in the lottery
public function clearAccounts() {
this.lottery = "";
}
// Picks a random person entered in the lottery.
public function pickLotteryWinner() {
return this.lottery[int(random(0, this.lottery.size()))];
}
Echoed...
PHP Code:
The script of NPC Lottery has been updated by fowlplay4
People entered 5 Winner b
People entered 5 Winner c
People entered 5 Winner a
People entered 5 Winner d
People entered 5 Winner a
The first person winning was probably just a coincidence.