Thread: Lottery NPC
View Single Post
  #16  
Old 08-20-2011, 10:56 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
no, i havnt tried debugging it. i dont know how to do tasks that advanced.
here is the db npc script

PHP Code:
// 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()))];

here is whats in the npc that does it

PHP Code:
function onCreated(){
  
onUpdateText();
}
function 
onUpdateText(){
if(
server.jackpot == 0){
this.chat "The Current Jackpot Is 0 Gralats.";
return;
}
this.chat "The Current Jackpot Is "@server.jackpot@" Gralats.";
}
function 
onPlayerchats(){
if(
player.chat == "/Buy Ticket"){
if (
Lottery.inLottery(player.account)){
player.chat "I Have Already Purchased A Ticket!";
return;
}
if(
player.rupees 20){
player.chat "I Dont Have Enough Money!";
}
if(
player.rupees 19){
player.chat "I Brought A Lottery Ticket!";
Lottery.addAccount(player.account);
player.rupees -= 20;
server.jackpot += 20;
onUpdateText();
}
}
if(
player.chat == "/Draw Lottery"){
if(
clientr.isStaff){
onAwardWinner();
}
}
}
function 
onAwardWinner(){
server.winner Lottery.pickLotteryWinner();
echo(
"Lottery: "@server.winner@" Has Won The Lottery! They Won: "@server.jackpot@" Gralats!");
findplayer(server.winner).chat "I Just Won The Lottery! I Won "@server.jackpot@" Gralats!";
savelog2("Lottery.txt"server.winner@" Won The Lottery! They Won "@server.jackpot@" Gralats!");
server.jackpot 0;
Lottery.clearAccounts();
onUpdateText();

__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote