//#####################################################################
//##### NPC By: Mclzeszen™ - Cronus Emulator ############
//##### Translation by: Yoh Asakura - Cronus Emulator ############
//##### All rights reserved® #################################
//### LOTTERY v2.5 #########
//#####################################################################
//
//--
//-- Structure for table `loteria_b`
//--
// DROP TABLE IF EXISTS `loteria_b`;
// CREATE TABLE IF NOT EXISTS `loteria_b` (
// `id_b` int(11) NOT NULL DEFAULT '1',
// `char_id` int(11) NOT NULL,
// `bilhete` int(11) NOT NULL,
// `aposta` int(11) NOT NULL
// ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
//
//--
//-- Structure for table `loteria_s`
//--
// DROP TABLE IF EXISTS `loteria_s`;
// CREATE TABLE IF NOT EXISTS `loteria_s` (
// `sort_id` int(11) NOT NULL,
// `sorteio` int(11) NOT NULL
// ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
//End tables mysql
//Variaveis
prontera,150,150,3 script Lottery 57,{
set @npc$,"^0006D3...:::LOTTERY:::...^000000"; //npc name
set @price,5000000; //ticket price
set @maxApostas,3; //max number of bets for each char
set @Servidor$,"YourRO"; //your server name
if(!$acumulado){ set $premio,10000000;} //if accumulated the value will not be only 10kk, otherwise it will be 10kk.
query_sql "SELECT `bilhete`,`id_b` FROM `loteria_b` WHERE `char_id` = '"+getcharid(0)+"'",.@blot,.@id; //count the bets
query_sql "SELECT `sorteio` FROM `loteria_s`",.@slot; //numbers from the last lottery draw
query_sql "SELECT COUNT(*) FROM `loteria_b`",.@total_bet;
//Fim variaveis
if($fechado){ //If in time of payment for the winers, bets closed from 17 to 23 hours.
show @npc$;
show "I'm sorry!";
show "We are reorganizing our system for the next lottery draw.";
show "Returns for bets at 23 Hours.";
show "We thank you for your preference.";
next;
show @npc$;
show "Would you like to consult something?";
next;
switch(select("- See my tickets","- See the result,","- Leave")){
case 1:
goto L_NUMEROS;
end;
case 2:
goto LRS;
end;
case 3:
goto L_FIM;
end;
}
close;
}
if(getarraysize(.@blot) >= @maxApostas) goto L_INI; //If the player has already done the max betting
callfunc("bilhete",.@bilhete); //Checks if there is already the numbers in the list of his tickets.
query_sql "SELECT `bilhete` FROM `loteria_b` WHERE `char_id` = '"+getcharid(0)+"' and `bilhete` = '"+.@bilhete+"'",.@valida;
if(.@valida){ //If yes, he will ask you to try again. I didin't put loop to avoid crashes.
show @npc$;
show "Sorry...";
show "Try again in a few seconds.";
close;
}
//explication part
L_INI:
show @npc$;
show "Welcome to the Lottery!";
show "I work at the "+@Servidor$+" Lottery.";
show "I'm part of the gambling commission,";
show "and you can become a millionaire in just one move.";
show "It's like this... You make a bet and I will give you random numbers";
show "on my iPad, every day at 5:00pm (Brasilia)";
show "the lottery draw occurs.";
show "If no one wins the prize is accumulated.";
show "The current prize is z$^ff0000"+$premio+"^000000,";
show "If no one wins the prize will be accumulated.";
show "The more accumulated is, greater the hefty winner's!";
next;
//End of explication
//Values
show @npc$;
show "Will you risk a bet?";
show "The value for a bet is z$"+@price;
show "You can bet ^ff0000"+@maxApostas+"^000000 times per character.";
show "Total Bets Till now "+ .@total_bet;
next;
//End of values
switch(select("- I will bet","- Numbers of the last lottery draw","- Leave for the next time","- My Tickets","- Last Result")){ //Menu principal
case 1:
if(getarraysize(.@blot) >= @maxApostas) goto L_CHEGA;
if(zeny < @price) goto L_NZ; //Check if the player has zeny
show @npc$;
show "Very well "+strcharinfo(0)+"!";
show "I'm processing your bet here on the iPad.";
next;
//Generate the ticket and concludes the bet sending the ticket to MySQL Table
set zeny,zeny-@price;
show @npc$;
show "Just one more second...Your ticket is being generated";
next;
show @npc$;
show "Done. Sorry for the delay.";
show "This is Your Number: ^C4258B"+.@bilhete+"^000000";
show "If you win... it will be announced and you will have till 11:00pm to get your prize.";
show "You can also consult your ticket here with me anytime you want.";
show "Bye, see you.";
query_sql "INSERT INTO `loteria_b` (`char_id`,`bilhete`,`aposta`) VALUES ('"+getcharid(0)+"','"+.@bilhete+"','"+@price+"')";
close;
//End of the Bet
//Consult the last lottery draw
case 2:
if (.@slot == 0) {
show @npc$;
show strcharinfo(0)+".";
show "There were no lottery draw yesterday!";
show "I'm sorry!";
close;
}else{
show @npc$;
show strcharinfo(0)+".";
show "The last Lottery Draw Numbers are: ^C47030"+.@slot+"^000000";
close;
}
//End lottery draw consult
//Leave for the next time
case 3:
show @npc$;
show "Ok! "+strcharinfo(0)+"!";
show "Come back anytime...";
show "Think well. You can become a millionaire...haha.";
close;
case 4:
goto L_NUMEROS;
close2;
case 5:
goto L_LAST;
close2;
}
L_NUMEROS:
//query to confirm the player's prize
query_sql "SELECT `bilhete` FROM `loteria_b` WHERE `bilhete` = '"+.@slot+"' and `char_id` = '"+getcharid(0)+"'",.@winner;
//query to get the name of the winners
if($nameW$ == ""){query_sql "SELECT `name` FROM `char` WHERE `char_id` IN (SELECT `char_id` FROM `loteria_b` WHERE `bilhete` = '"+.@slot+"')",$nameW$;}
if(.@winner){
set .@LotWon,getarraysize($nameW$);
set .@SeuPremio,$premio*getarraysize($nameW$);
///Importing your Prize directly to the Bank
set #bancoZ,#bancoZ+$premio;
//Data from the Lottery Draw Winners
show @npc$;
if(.@LotWon > 1){ set .@a1$,"You were one of the winners."; }else{ set .@a1$,"You were the only winner."; }
show .@a1$;
show "Your prize on the value of ^ff0000"+$premio+"^000000";
show "Was deposited on your bank account.";
show "Check your balance on your bank account,";
show "And your tickets were deleted from our system";
show "To avoid frauds";
next;
show @npc$;
show "^2EA686WINNERS LIST^000000";
show "^8A4D29|||^000000 = Name of the Winner";
show "^FF0000|||^000000 = Prize Value";
show "____________________________";
for(set @i,0; @i < .@LotWon; set @i,@i+1)
show "-^8A4D29"+ $nameW$[@i] +"^000000 :^ff0000 "+$premio+"^000000";
//
//show .@winner;
next;
show @npc$;
show "Number of Winners: "+.@LotWon;
show "Lottery Draw Number: "+.@slot;
show "Prize for each of the involved!";
show "z$:^ff0000"+ $premio+"^000000";
set $acumulado,0;
query_sql "DELETE FROM `loteria_b` WHERE `char_id` = '"+getcharid(0)+"'"; //Delete the tickets of those who already received the prize
close;
//End of the lottery draw data.
}
//If it's not winner and it's not time for prizes, the player checks his bets
show @npc$;
show "^C4258B|||^000000 = Ticket Number.";
show "^FF0000|||^000000 = Ticket Code.";
show "__________________________";
show "These are your Tickets.";
for(set .@n,0;.@n < getarraysize(.@blot); set .@n,.@n+1 ){
set @cod,.@n+1;
show "Ticket ^ff0000[ "+@cod+" ]^000000 : ^C4258B[ "+.@blot[.@n]+" ]^000000";
}
close;
L_NZ:
//No zeny
show @npc$;
show "You don't have enought zeny to bet.";
show "Come back when you get enough money!";
close;
LRS:
query_sql "SELECT `bilhete` FROM `loteria_b` WHERE `bilhete` = '"+.@slot+"' and `char_id` = '"+getcharid(0)+"'",.@winner;
if(.@winner){ goto L_NUMEROS; }
if($nameW$ == ""){query_sql "SELECT `name` FROM `char` WHERE `char_id` in (SELECT `char_id` FROM `loteria_b` WHERE `bilhete` = '"+.@slot+"')",$nameW$;}
query_sql "SELECT `char_id` FROM `loteria_b` WHERE `bilhete`",.@sorteado;
if($nameW$ == ""){
show @npc$;
show "^2EA686THERE WERE NO WINNERS^000000";
show "The Lottery Draw Number was: ^ff0000"+.@slot+"^000000";
show "The Prize has accumulated: z$^ff0000"+$premio+"^000000";
close;
}else{
show @npc$;
show "^2EA686LIST OF WINNERS^000000";
show "The Lottery Draw Number was: ^ff0000"+.@slot+"^000000";
show "^8A4D29|||^000000 = Name of the Winner";
show "^FF0000|||^000000 = Prize Value";
show "____________________________";
//show $nameW$;
for(set @i,0; @i < getarraysize($nameW$); set @i,@i+1)
show "-^8A4D29 "+$nameW$[@i]+"^000000 :^ff0000 "+$recebeu+"^000000";
close;
}
L_CHEGA:
show @npc$;
show "You've already done ^ff0000"+@maxApostas+"^000000 bets!!!";
show "Better stop here.";
close;
L_FIM:
show @npc$;
show "Come back always!";
close;
L_LAST:
if($nameW$ == ""){
show @npc$;
show "^2EA686THERE WERE NO WINNERS^000000";
show "The Lottery Draw Number was: ^ff0000"+.@sorteado+"^000000";
show "The Prize has accumlated: z$^ff0000"+$premio+"^000000";
close;
}else{
show @npc$;
show "^2EA686LIST OF WINNERS^000000";
show "^8A4D29|||^000000 = Name of the Winner";
show "^FF0000|||^000000 = Prize Value";
show "____________________________";
//show $nameW$;
for(set @i,0; @i < getarraysize($nameW$); set @i,@i+1)
show "-^8A4D29 "+$nameW$[@i]+"^000000 :^ff0000 "+$recebeu+"^000000";
close;
}
}
//Script responsible for the Lottery Draw
- script sorteio -1,{
OnClock1701:
set $recebeu,0;
set $nameW$,"";
set $fechado,1; //Turn the betting period closed
query_sql "DELETE FROM `loteria_s`"; //Delete the last lottery draw numbers
callfunc("bilhete",.@resultado); //Call the function to generate the lottery draw numbers.
query_sql "INSERT INTO `loteria_s` (`sorteio`) VALUES ('"+.@resultado+"')"; //Insert the lottery draw numbers at mysql
announce "Lottery: ATTENTION! Result from the Lottery Draw: "+.@resultado+"!",8; //Global message
end;
///##################################################################################################################
OnClock1702: //Announcement of winners or prize accumulated
query_sql "SELECT `bilhete` FROM `loteria_b` WHERE `bilhete` IN (SELECT `sorteio` FROM `loteria_s`)",.res; //Take the tickets that has not been deleted (winners)
if(.res <= 0){ //If there are no winners
set $premio,$premio*2+500000; //Accumulated prize(calculation of the prize)
announce "Lottery: There were no winners this time!!! Prize has been accumulated to "+$premio+"! ",8; //Global message
set $acumulado,1; //The prize will no longer be 10kk.
end;
}
if(getarraysize(.res) == 1){ //If there are a winner
set $recebeu,$premio;
announce "Lottery: Congratulations. We have [ 1 ] winner for the prize of z$: "+$premio,8; //Global message
end;
}else if(getarraysize(.res) > 1){ //If more than just one winner
set $premio,$premio/getarraysize(.res); //Share the prize for the winners
announce "Lottery: Congratulations. We have [ "+getarraysize(.res)+" ] winners! And each one will get z$: "+$premio,8;
set $recebeu,$premio;
}
////#################################################################################################################
OnClock2305: //At 11:00pm open the bets and the winners can no longer get the prize (Lost the prize!!!)
set $fechado,0;
query_sql "DELETE FROM `loteria_b`"; //to restart the bets
announce "Lottery: The Lottery is opened for new bets. Good Luck!",8;
end;
///##################################################################################################################
//Restricted Use for Administrators to give reload on the npc // Come back the prize to 10kk and open the bets if closed.
//Just use this if you know what you are doing.
OnWhisperGlobal:
if(@whispervar0$ == "reload"){
if(getgmlevel() <= 98){
//if(getgroupid() <= 98){ //For the new emulators version
end;
}else{
set $fechado,0;
set $acumulado,0;
query_sql "DELETE FROM `loteria_b`";
dispbottom "Lottery: Variables Reseted!!!";
}
}
if(@whispervar0$ == "fechar"){
if(getgmlevel() <= 98){
//if(getgroupid() <= 98){ //For the new emulators version
set $fechado,1;
dispbottom "Lottery: Lottery Closed!!!";
}
}
}
//##################################### FUNCTION TO GENERATE THE TICKET ############################################
///Ps.: The generated numbers here can not contain zero and can not have the same digit repeated. Makes it easier for gamblers
function script bilhete {
set .@lt1,rand(1,9);
L_1:
set .@lt2,rand(1,9);
if(.@lt2 == .@lt1) goto L_1;
L_2:
set .@lt3,rand(1,9);
if((.@lt3 == .@lt1) || (.@lt3 == .@lt2)) goto L_2;
L_3:
set .@lt4,rand(1,9);
if((.@lt4 == .@lt1) || (.@lt4 == .@lt2) || (.@lt4 == .@lt3)) goto L_3;
///################################################################################
///If you will activate numbers of 4 digits, you have to desactivate the number of 3 digits... (Ps.: 4 digits is very hard to win, (Good for big servers)
set getarg(0),.@lt1+""+.@lt2+""+.@lt3; //Generates Numbers of 3 digits for the tickets.
//set getarg(0),.@lt1+""+.@lt2+""+.@lt3+""+.@lt4; //Generates Numbers of 4 digits for the tickets.
return;
}