PDA

View Full Version : Lottery


xAndrewx
09-24-2006, 09:19 PM
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.

KuJi
09-28-2006, 03:33 AM
[HTML]
A lottery system, draws a winning ticket each week.

if (playertrial) <-- works still? o.O

Darkyoshi12345
09-28-2006, 05:21 AM
Is there a GS2 command for playertrial?

xAndrewx
09-28-2006, 09:40 AM
player.trial maybe, didn't try it.

xXziroXx
09-28-2006, 03:30 PM
I would assume that its still: if (playertrial)