viewing paste rA/115288-l lotti_girl+rank+shop | Athena

Posted on the | Last edited on
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
// https://rathena.org/board/topic/115288-lotti-girl-ranker-wreward/
 
/*
create table lotti_rank (
char_id int(11),
name varchar(24),
lotti_point int(11),
primary key (char_id),
key (lotti_point)
) engine = innodb;
*/
 
prontera,155,181,5  script  Lotti Girl  1_F_MARIA,{
    goto L_talk;
OnInit:
    setarray .cost, 7227,300;
 
//  setarray .p1, 70, 607,25;
//  setarray .p2, 70, 13710,1;
//  setarray .p3, 40, 5471,1;
//  setarray .p4, 40, 5210,1;
//  setarray .p5, 40, 5224,1;
//  setarray .p6, 50, 2357,1, 2524,1, 2421,1, 2115,1;
//  setarray .p7, 25, 2701,1;
//  setarray .p8, 5, 2394,1;
//  setarray .p9, 30+30+60+60+60+50+75+95, 12214,1; 
 
    setarray .p1, 10, 501, 1;
    setarray .p2, 8, 502, 1;
    setarray .p3, 5, 503, 1;
    setarray .p4, 3, 504, 1;
    setarray .p5, 1, 505, 1;
    setarray .p6, 90+92+95+97+99, 512, 10;
 
    setarray .itemid,1101,1201,1301,1501,1601;
    setarray .itemcost,10,20,30,40,50;
 
    for ( .@i = 1; getd(".p"+ .@i ); .@i++ ) {
        .itemtotalchance += getd(".p"+ .@i );
        .itemsize[.@i] = ( getarraysize( getd(".p"+ .@i ) ) -1 ) /2;
    }
 
    //  .points[ <random number on item chance> ] = <get this points>; // otherwise only get 1 point
    .points[10] = 10;
    .points[9] = 20;
    .points[8] = 30;
    .points[7] = 40;
    .points[6] = 50;
    .points[5] = 60;
    .points[4] = 70;
    .points[3] = 80;
    .points[2] = 90;
    .points[1] = 100;
 
    .shop_size = getarraysize(.itemid);
    npcshopdelitem "Lotti#hidden", 512;
    for ( .@i = 0; .@i < .shop_size; .@i++ )
        npcshopadditem "Lotti#hidden", .itemid[.@i], .itemcost[.@i];
    npcshopattach "Lotti#hidden";
    end;
L_talk:
    mes "[Lotti Girl]";
    mes "Welcome to the blah blah where I can blah blah and shop shop"; // lazy dialog
    next;
    switch ( select ( "Play", "Lotti Ranking", "Lotti Shop" ) ) {
    mes "[Lotti Girl]";
    case 1:
        mes "It costs "+ .cost[1] +"x "+ getitemname( .cost[0] ) +" to play.";
        if ( countitem( .cost[0] ) < .cost[1] ) close;
        next;
        if ( select( "Deal me in!", "No way..." ) == 2 ) close;
        mes "[Lotti Girl]";
        while ( true ) {
            mes "Here we go...";
            .@rand = rand(.itemtotalchance);
            .@r = 0;
            while ( ( .@rand = .@rand - getd( ".p"+ .@r +"[0]" ) ) >= 0 ) .@r++;
            deletearray .@itemid;
            deletearray .@itemamount;
            for ( .@i = 0; .@i < .itemsize[.@r]; .@i++ ) {
                .@itemid[.@i] = getd( ".p"+ .@r +"["+( .@i *2 +1 )+"]" );
                .@itemamount[.@i] = getd( ".p"+ .@r +"["+( .@i *2 +2 )+"]" );
            }
            if ( checkweight2( .@itemid, .@itemamount ) == false ) {
                mes "\rit appears you have overweight";
                break;
            }
            delitem .cost[0], .cost[1];
            for ( .@i = 0; .@i < .itemsize[.@r]; ++.@i )
                getitem .@itemid[.@i], .@itemamount[.@i];
            if ( .points[ getd( ".p"+ .@r +"[0]" ) ] > 0 )
                .@points = .points[ getd( ".p"+ .@r +"[0]" ) ];
            else
                .@points = 1;
            Lotti_Points = Lotti_Points + .@points;
            query_sql "insert into lotti_rank values ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', "+ .@points +" ) on duplicate key update lotti_point = lotti_point + "+ .@points;
            dispbottom "Lotti_Points -> "+ Lotti_Points +" ++"+ .@points;
            mes "\rwanna try again ?";
            next;
            if ( select( "Yes", "No" ) == 2 ) break;
            mes "[Lotti Girl]";
            if ( countitem( .cost[0] ) < .cost[1] ) {
                mes "\rit seems you have ran out of "+ getitemname( .cost[0] );
                break;
            }
        }
        mes "\rThank you for using Lotti service~";
        close;
    case 2:
        .@query$  = "SELECT `name`, IF(@d=t.`lotti_point`, @r, @r:=@i), @d:=t.`lotti_point`, @i:=@i+1 ";
        .@query$ += "FROM `lotti_rank` t, (SELECT @d:=0, @r:=0, @i:=1)q ";
        .@query$ += "ORDER BY `lotti_point` DESC LIMIT 5";
        .@nb = query_sql(.@query$, .@name$, .@rank, .@points, .@dummy);
        if ( !.@nb ) {
            mes "There's no ranking yet ~";
            close;
        }
        for ( .@i = 0; .@i < .@nb; .@i++ )
            mes .@rank[.@i] +"> "+ .@name$[.@i] +" > "+ .@points[.@i] +" Points.";
        if ( !query_sql( "SELECT `lotti_point`, 1+(SELECT COUNT(1) FROM `lotti_rank` t1 WHERE t1.lotti_point > t2.lotti_point) FROM `lotti_rank` t2 WHERE `char_id` = "+ getcharid(0), .@kills, .@rank ) ) {
            mes "\rYou are not in the rank.";
            close;
        }
        mes "\rYour current Point > "+ .@points;
        mes "Your current Rank > "+ .@rank;
        close;
    case 3:
        mes "You currently have "+ Lotti_Points +" Lotti Points.";
        dispbottom "You currently have "+ Lotti_Points +" Lotti Points.";
        close2;
        callshop "Lotti#hidden", 1;
        end;
    }
    close;
OnBuyItem:
    mes "[Lotti Girl]";
    if ( !@bought_quantity ) end;
    if ( checkweight2( @bought_nameid, @bought_quantity ) == false ) {
        mes "It appears you can't carry them all";
        close;
    }
    .@size = getarraysize( @bought_nameid );
    for ( .@i = 0; .@i < .@size; .@i++ ) {
        for ( .@j = 0; .@j < .shop_size; .@j++ )
            if ( @bought_nameid[.@i] == .itemid[.@j] )
                break;
        .@itemcost = .@itemcost + .itemcost[.@j] * @bought_quantity[.@i];
    }
    if ( .@itemcost > Lotti_Points ) {
        mes "You don't have enough Lotti Points";
        close;
    }
    Lotti_Points = Lotti_Points - .@itemcost;
    for ( .@i = 0; .@i < .@size; .@i++ )
        getitem @bought_nameid[.@i], @bought_quantity[.@i];
    deletearray @bought_nameid;
    deletearray @bought_quantity;
    mes "Thanks for buying ~";
    close;
}
-   shop    Lotti#hidden    -1,512:1000
Viewed 1224 times, submitted by AnnieRuru.