Thread: Lottery
View Single Post
  #1  
Old 09-24-2006, 08:19 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Lottery

HTML Code:
function onCreated()
{ 
  showcharacter();
  DisplayAmount();

  setTimer(50);
}
function onTimeout()
{
  if (this.drawtime == NULL)
  {
    sendtorc("Drawing the winner of the lottery!");
    findwinner();
    this.drawtime = 10080;
  }
  this.drawtime--;
  setTimer(50);
}  
function onActionGrab()
{
  say2("Hi there! We draw the winning" NL
  "ticket randomly once a week. If" NL
  "you're interested in purchasing a" NL
  "ticket just say 'buy ticket'." NL
  "Tickets cost $20." NL
  "Good luck!");
}

function onPlayerChats()
{
  if (player.chat != "buy ticket")
  {
    return;
  }
  if (player.account in this.PTickets)
  {
    player.chat = "I have already purchased a ticket!";
    return;
  }
  if(player.rupees >= 20)
  {
    PurchaseTicket();
  }
    else
  {
    player.chat = "I don't have enough money to purchase a ticket!";
  }
}
function findwinner()
{
  temp.tokens = this.tickets.tokenize(); 
  temp.winnernumber = temp.tokens.size();
  temp.winnerpicked = int(random(0, temp.winnernumber));

  this.LWinner = temp.tokens[temp.winnerpicked];
       
  //Add the pay in here, if the player isn't online, add it to their bank account or something.
  //Removed it for public use!

  sendtonc(format(_("Lottery Winner: %s. Amount: %s."), this.LWinner, this.LAmount));
  resetDatabase();
}
function resetDatabase()
{
  this.PTickets = NULL;
  this.LAmount = NULL;

  DisplayAmount();
}
function PurchaseTicket()
{
  if(playertrial)
  {
    player.chat = "(Trials can't participate!)";
    return;
  }
  this.PTickets.add(player.account);
  
  player.rupees -= 20;
  this.LAmount += 20;
  DisplayAmount();
  
  player.chat = "I have purchased a ticket!";
  savelog2("lottery.txt", format(_("%s purchased a ticket!"), player.account));
}
function DisplayAmount()
{
  message(format(_("Jackpot is $%i! Last weeks winner was %s"), this.LAmount, this.LWinner));
}
A lottery system, draws a winning ticket each week.
__________________
Reply With Quote