Thread: Lottery NPC
View Single Post
  #19  
Old 08-21-2011, 06:46 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.0temp.5temp.t++) {
    
test();
  }
}

function 
test() {
  
temp.accts = {
    
"a""b""c""d""e"
  
};
  
clearAccounts();
  for (
temp.accttemp.accts) {
    for (
temp.0temp.3temp.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(0this.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.
__________________
Quote:
Reply With Quote