viewing paste Lottery[Yoh] | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
//#####################################################################
//##### 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.";
show @npc$;
show "Would you like to consult something?";
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;
 
}
}
 
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.";
 
}
 
 
 
//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!";
//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;
//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.";
 
L_FIM:
show @npc$;
show "Come back always!";
 
 
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;
 
}
Viewed 800 times, submitted by Dastgir.