viewing paste topic/10967- mvp_rank ... | 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
prontera,158,176,3      script  MVP Ladder      1_F_MARIA,{
    mes "[MVP Ladder]";
    mes "Hello!";
    mes "What are you doing here?";
    next;
    switch(select("Check rankings.:My stats.:Previous Month ranking")) {
    case 1:
        mes "[MVP Ladder]";
        mes "Rankings :->";
        .@nb = query_sql( "select name, mvp_rank from `char` where mvp_rank > 0 order by mvp_rank desc limit 5", .@name$, .@count );
        if ( !.@nb ) {
            mes "no entry";
            close;
        }
        for ( .@i = 0; .@i < .@nb; .@i++ )
            mes ( .@i +1 )+". "+ .@name$[.@i] +" -> "+ .@count[.@i] +" points";
        close;
    case 2:
        query_sql "select mvp_rank from `char` where char_id = "+ getcharid(0), .@killed;
        mes "[MVP Ladder]";
        mes "You have killed "+ .@killed +" MVPs";
        close;
    case 3:
        mes "[MVP Ladder]";
        mes "Last month ranking";
        if ( gettime(MONTH) > 10 )
            .@store_date$ = gettime(YEAR) +"-"+( gettime(MONTH) -1 )+"-00 00:00:00";
        else if ( gettime(MONTH) > 1 )
            .@store_date$ = gettime(YEAR) +"-0"+( gettime(MONTH) -1 )+"-00 00:00:00";
        else
            .@store_date$ = ( gettime(YEAR) -1 ) +"-12-00 00:00:00";
        .@nb = query_sql( "select name, points from mvp_rank_archive where `date` = '"+ .@store_date$ +"' order by pos", .@name$, .@count );
        if ( !.@nb ) {
            mes "no entry";
            close;
        }
        for ( .@i = 0; .@i < .@nb; .@i++ )
            mes ( .@i +1 )+". "+ .@name$[.@i] +" -> "+ .@count[.@i] +" points";
        close;
    }
    close;
OnInit:
    if ( $mvp_ladder_last_given == atoi( gettime(YEAR) +""+ gettime(MONTH) ) ) end;
    goto L_give;
OnClock0000:
    if ( gettime(DAYOFMONTH) != 1 ) end;
L_give:
    .@nb = query_sql( "select char_id, name, mvp_rank from `char` where mvp_rank > 0 order by mvp_rank desc limit 5", .@cid, .@name$, .@killed );
    if ( !.@nb ) end;
    setarray .@reward, 30316, 7227, 7227, 7227, 7227; // <1st place>, <2nd place>, <3rd place> ...
    setarray .@amount, 1, 50, 25, 10, 5;
    for ( .@i = 0; .@i < .@nb; .@i++ )
        query_sql "insert into mail ( send_name, dest_id, title, message, nameid, amount, identify, zeny, time ) values ( '"+ escape_sql( .@name$[.@i] ) +"', "+ .@cid[.@i] +", '[MVP RANK]', 'Congratulations for earning No. "+( .@i +1 )+" position in killing Custom MVPs. Here is your reward.', "+ .@reward[.@i] +", "+ .@amount[.@i] +", 1, 0, unix_timestamp( now() ) )";
    query_sql "update `char` set mvp_rank = 0"; // reset the ladder
    $mvp_ladder_last_given = atoi( gettime(YEAR) +""+ gettime(MONTH) );
    end;
OnNPCKillEvent:
    if ( killedrid == PORING) // 1002 <-- debugging
        query_sql "update `char` set mvp_rank = mvp_rank +1 where char_id = "+ getcharid(0);
    end;
}
Viewed 924 times, submitted by AnnieRuru.