Advertisement
johnlol

mvp_ranker

May 22nd, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //===== rAthena Script =======================================
  2. //= MvP Ranker with Shop
  3. //===== By ===================================================
  4. //= llchrisll
  5. //===== Version ==============================================
  6. //= 1.0 - Initial Version
  7. //= 1.1 - Fixed Ranking Display
  8. //      - Exchanged .mvp_ with $@mvp_ variables
  9. //      - Modified OnMvPCardUnlock to be a function
  10. //      - Added freeloop(); to prevent infinite loop <<----- DON'T NEED ANY freeloop
  11. //= 1.2 - Improved by AnnieRuru <3
  12. //===== Tested With ==========================================
  13. //= rAthena 03/26/2018 Revision
  14. //= GIT Hash: 333f0dddc8353663eacba0423751988c9bc38e34
  15. //===== Description ==========================================
  16. //= MvP Ranking with MvP Card Shop as soon as the Goal Points of
  17. //  respective MvP has been reached.
  18. //= Automatic detection of MvPs hunting state and addition of MvP Card
  19. //  into the Shop.
  20. //= Top 10 Ranking
  21. //= List of MvP Goals
  22. //= Price per MvP Card = Goal Points/4
  23. //===== Request ==============================================
  24. //= by Radian (https://rathena.org/board/profile/27689-radian/)
  25. //= Topic: https://rathena.org/board/topic/115216-mvp-ranker-w-rewards/
  26. //===== SQL Tables ===========================================
  27. /* SQL Tables:
  28. CREATE TABLE `mvp_rank` (
  29.  `char_id` int(11) unsigned NOT NULL,
  30.  `char_name` varchar(30) NOT NULL default 'Unknown',
  31.  `mvp_points` int(11) default '0',
  32. PRIMARY KEY ( `char_id` ),
  33. KEY (`mvp_points`)
  34.  ) ENGINE=MyISAM;
  35.  
  36. CREATE TABLE `mvp_goal` (
  37.  `mvp_id` smallint(5) unsigned NOT NULL,
  38.  `goal_points` int(11) default '4',
  39.  `goal_needed` int(11) default '4',
  40.  `mvp_card` smallint(5) unsigned NOT NULL,
  41. PRIMARY KEY ( `mvp_id` )
  42.  ) ENGINE=InnoDB;
  43. */
  44. //============================================================
  45. poring_w01,100,100,4    script  MvP Ranker  102,{
  46.  
  47.     mes .n$;
  48.     mes "How can I help you?";
  49.     next;
  50.     switch(select("- Server Ranking","- MVP Goals","- Open MVP Shop:- Nevermind")) {
  51.  
  52.     case 1:
  53.         mes .n$;
  54.         mes "I will now list the Top 10 MvP Hunters:";
  55.         next;
  56.         mes "[ Top 10 MvP Hunters ]";
  57.         if ( !( .@nb = query_sql( "SELECT `char_name` , `mvp_points` FROM `mvp_rank` ORDER BY `mvp_points` DESC LIMIT 10;", .@c_name$, .@mvp_pts ) ) ) {
  58.             mes "There is currently no player ranked.";
  59.             mes "Come back later.";
  60.             close;
  61.         }
  62.         for ( .@i = 0; .@i < .@nb; ++.@i )
  63.             mes ( .@i +1 )+". "+ .@c_name$[.@i] +" - "+ .@mvp_pts[.@i] +" Points";
  64.         close;
  65.    
  66.     case 2:
  67.         mes .n$;
  68.         mes "Here is the list of the MvP's with their needed Goal Points:";
  69.         mes " ";
  70.         mes "> MvP / Required / Current";
  71.         .@nb = query_sql( "SELECT `mvp_id` , `goal_points`, `goal_needed` FROM `mvp_goal`", .@mvp_id, .@goal_pts, .@need_goal );
  72.         for ( .@i = 0; .@i < .@nb; ++.@i )
  73.             mes "> "+ getmonsterinfo(.@mvp_id[.@i], MOB_NAME) +" / "+ .@need_goal[.@i] +" / "+( .@goal_pts[.@i] ? .@goal_pts[.@i] : "UNLOCKED" );
  74.         close;
  75.    
  76.     case 3:
  77.         mes .n$;
  78.         if(!MVPPOINTS) {
  79.             mes "I'm sorry, but you have to kill at least 1 MvP to gain access to the MvP Shop";
  80.             close;
  81.         }
  82.         mes "Your current MvP Points: "+MVPPOINTS;
  83.         if(!.shop_card_total) { // Prevent opening an empty shop
  84.             mes "I'm sorry, but there is no card yet available.";
  85.             mes "Kill one of the MvP's first until their goal has been reached!";
  86.             close;
  87.         }
  88.         mes "I will now open the Shop.";
  89.         close2;
  90.         callshop "MvPRankShop",1;
  91.         npcshopattach "MvPRankShop";
  92.         end;   
  93.    
  94.     case 4:
  95.         close;
  96.     }
  97.     end;
  98.  
  99. OnInit:
  100.     set .n$,"["+strnpcinfo(1)+"]";
  101.     // MvP ID's to Hunt:
  102.     // Put every MvP ID here, which should be hunted
  103.         setarray .mvp_id[0],
  104.             1511,   // Amonra
  105.             1785,   // Atroce
  106.             1630,   // Bacsojin
  107.             1039,   // Baphomet
  108.             1272,   // Dark Lord
  109.             1719,   // Detale
  110.             1046,   // Doppelganger
  111.             1389,   //
  112.             1112,
  113.             1115,
  114.             1418,
  115.             1871,
  116.             1252,
  117.             1768,
  118.             1086,
  119.             1832,
  120.             1492,
  121.             1734,
  122.             1251,
  123.             1779,
  124.             1688,
  125.             1373,
  126.             1147,
  127.             1059,
  128.             1087,
  129.             1190,
  130.             1038,
  131.             1157,
  132.             1159,
  133.             1623,
  134.             1583,
  135.             1708,
  136.             1312,
  137.             1751,
  138.             1685,
  139.             1658;
  140.    
  141.     // MvP Card ID's
  142.     // magically built with SQL commands ~
  143.  
  144.     set .mvp_id_size, getarraysize( .mvp_id );
  145.  
  146.     // Goal Points required
  147.     //  setarray .mvp_goal[0],4,4,4,4,4;
  148.     cleararray .mvp_goal, 4, .mvp_id_size; // change back to setarray
  149.  
  150.  
  151.     // Automatic check for existing database entries
  152.     for ( .@i = 0; .@i < .mvp_id_size; ++.@i )
  153.         .@values$[.@i] = "SELECT "+ .mvp_id[.@i] +" AS MVPID, "+ .mvp_goal[.@i] +", "+ .mvp_goal[.@i] +", ( SELECT `DropCardid` FROM `"+( checkre(0)? "mob_db_re" : "mob_db" )+"` where ID = MVPID )";
  154.     if ( .mvp_id_size )
  155.         query_sql "INSERT IGNORE INTO `mvp_goal` ( `mvp_id`, `goal_points`, `goal_needed`, `mvp_card` ) "+ implode( .@values$, " UNION " );
  156.  
  157.     // Automatic check if MvP will not be hunted anymore:
  158.     // It checks if the MvP is in the .mvp_id array, if not remove it from the database
  159.     // Note: Be aware that the acquired goal points will not be saved anywhere for later usage!
  160.     for ( .@i = 0; .@i < .mvp_id_size; ++.@i )
  161.         .@where_clause$[.@i] = "`mvp_id` != "+ .mvp_id[.@i];
  162.     if ( .mvp_id_size )
  163.         query_sql "DELETE FROM `mvp_goal` WHERE "+ implode( .@where_clause$, " AND " );
  164.     else
  165.         query_sql "TRUNCATE TABLE `mvp_goal`";
  166.  
  167.     npcshopdelitem "MvPRankShop", 501;
  168.     if ( ( .shop_card_total = query_sql( "SELECT `mvp_card`, `goal_needed` FROM `mvp_goal` WHERE `goal_points` = 0", .@mvpcard, .@need_goal ) ) ) {
  169.         for ( .@i = 0; .@i < .shop_card_total; ++.@i ) {
  170.             npcshopadditem "MvPRankShop", .@mvpcard[.@i], .@need_goal[.@i] /4;
  171.             .shop_card_id[.@i] = .@mvpcard[.@i];
  172.             .shop_goal[.@i] = .@need_goal[.@i] /4;
  173.         }
  174.     }
  175.     end;
  176.  
  177. OnNPCKillEvent:
  178.     if ( !getmonsterinfo( killedrid, MOB_MVPEXP ) ) end;
  179.  
  180.     if ( !query_sql( "SELECT `goal_points`, `goal_needed`, `mvp_card` FROM `mvp_goal` WHERE `mvp_id` = "+ killedrid, .@goal, .@need_goal, .@mvpcard ) )
  181.         end; // if the killedrid is MVP but not a mvp_goal ...
  182.  
  183.     if ( .@goal )
  184.         query_sql "UPDATE `mvp_goal` SET `goal_points` = `goal_points` - 1 WHERE `mvp_id` = "+ killedrid;
  185.     if ( .@goal -1 == 0 ) {
  186.         announce "[ MVP Ranker ]: "+ strcharinfo(0) +" has fullfilled the last kill of ["+ getmonsterinfo( killedrid, MOB_NAME ) +"], the Monster Card can now be purchased in the Shop!", bc_all;
  187.         npcshopadditem "MvPRankShop", .@mvpcard, .@need_goal /4;
  188.         .shop_card_id[.shop_card_total] = .@mvpcard[.@i];
  189.         .shop_goal[.shop_card_total] = .@need_goal[.@i] /4;
  190.         ++.shop_card_total;
  191.     }
  192.  
  193.     if ( !getcharid(1) ) {
  194.         ++MVPPOINTS;
  195.         query_sql "INSERT INTO `mvp_rank` ( `char_id`, `char_name`, `mvp_points` ) VALUES ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', 1 ) ON DUPLICATE KEY UPDATE `mvp_points` = `mvp_points` +1;";
  196.     }
  197.     else {
  198.         // *addrid is evil XD
  199.         .@map$ = strcharinfo(3);
  200.         getpartymember getcharid(1), 1;
  201.         getpartymember getcharid(1), 2;
  202.         for ( .@i = 0; .@i < $@partymembercount; ++.@i ) {
  203.             if ( isloggedin( $@partymemberaid[.@i], $@partymembercid[.@i] ) ) {
  204.                 attachrid $@partymemberaid[.@i];
  205.                 if ( strcharinfo(3) == .@map$ ) { // only those in the same map
  206.                     ++MVPPOINTS;
  207.                     message strcharinfo(0), .n$ +": You have recieved 1 MvP Point for slaying "+ getmonsterinfo( killedrid, MOB_NAME ) +"!";
  208.                     .@cid[.@count] = $@partymembercid[.@i];
  209.                     .@name$[.@count] = strcharinfo(0);
  210.                     ++.@count;
  211.                 }
  212.             }
  213.         }
  214.         for ( .@i = 0; .@i < .@count; ++.@i )
  215.             .@values$[.@i] = "( "+ .@cid[.@i] +", '"+ escape_sql( .@name$[.@i] ) +"', 1 )";
  216.         query_sql "INSERT INTO `mvp_rank` ( `char_id`, `char_name`, `mvp_points` ) VALUES "+ implode( .@values$, ", " ) +" ON DUPLICATE KEY UPDATE `mvp_points` = `mvp_points` +1;";
  217.     }
  218.     end;
  219.  
  220. OnBuyItem:
  221.     if ( checkweight2( @bought_nameid, @bought_quantity ) == false ) {
  222.         dispbottom .n$+": I'm sorry, but you don't have enough space in inventory to take these items.";
  223.         end;
  224.     }
  225.  
  226.     .@item_bought = getarraysize( @bought_nameid );
  227.     for ( .@i = 0; .@i < .@item_bought; ++.@i )
  228.         for ( .@j = 0; .@j < .shop_card_total; ++.@j )
  229.             if ( @bought_nameid[.@i] == .shop_card_id[.@j] )
  230.                 .@total += .shop_goal[.@j] * @bought_quantity[.@i];
  231.  
  232.     if ( .@total > MVPPOINTS ) {
  233.         dispbottom .n$+": I'm sorry, but you don't enough MvP Points to purchase these cards.";
  234.         end;
  235.     }
  236.     MVPPOINTS -= .@total;
  237.     for ( .@i = 0; .@i < .@item_bought; ++.@i )
  238.         getitem @bought_nameid[.@i], @bought_quantity[.@i];
  239.     end;
  240. }
  241.  
  242. -   shop    MvPRankShop -1,501:-1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement