LucasRed

[VCMP] Sistema Top Killers VCMP

Mar 11th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. /*Top Killers System
  2.     Vice City Multiplayer 0.4
  3.         Squirrel
  4.             By (LBR)Lucas
  5. */
  6.  
  7. Accounts <- {}; /* Table where accounts will be */
  8.  
  9. /* FUNCTIONS */
  10. /* Let's say we are loading the accounts from the database */
  11. function loadAccounts() {
  12.     //9 "accounts"
  13.     Accounts.rawset(1, {Name = "Player1", Kills = rand() % 1000});
  14.     Accounts.rawset(2, {Name = "Player2", Kills = rand() % 1000});
  15.     Accounts.rawset(3, {Name = "Player3", Kills = rand() % 1000});
  16.     Accounts.rawset(4, {Name = "Player4", Kills = rand() % 1000});
  17.     Accounts.rawset(5, {Name = "Player5", Kills = rand() % 1000});
  18.     Accounts.rawset(6, {Name = "Player6", Kills = rand() % 1000});
  19.     Accounts.rawset(7, {Name = "Player7", Kills = rand() % 1000});
  20.     Accounts.rawset(8, {Name = "Player8", Kills = rand() % 1000});
  21.     Accounts.rawset(9, {Name = "Player9", Kills = rand() % 1000});
  22. /* NOTE: You will have to adapt this function to load all the accounts of your database. */
  23. }
  24.  
  25. function topKills() {
  26.     /*Here, we will temporarily clone the original table, because we will
  27.     have to delete some data (and we do not want this to happen in the main table)*/
  28.     local backup_Accounts = clone Accounts;
  29.  
  30.     local limit = 5, tmp = "";
  31.     while (limit) {
  32.         local topScore = 0, index = 0;
  33.         foreach (i, v in backup_Accounts)
  34.         {
  35.             if (backup_Accounts[i]["Kills"] > topScore) {
  36.                 topScore = backup_Accounts[i]["Kills"];
  37.                 index = i;
  38.             }
  39.         }
  40.         if (index) tmp = tmp + backup_Accounts[index]["Name"] + " - " + backup_Accounts[index]["Kills"] + ", ";
  41.         backup_Accounts.rawdelete(index);
  42.         limit --;
  43.     }
  44.     return tmp != "" ? tmp.slice(0, tmp.len() - 2) : "No top killers";
  45. }
  46.  
  47. function getAccountID(str) {
  48.     foreach (i, v in Accounts) {
  49.         if (Accounts[i]["Name"].tolower() == str.tolower()) {
  50.             return i;
  51.             break;
  52.         }
  53.     }
  54.     return 0;
  55. }
  56. /* SERVER EVENTS */
  57. function onScriptLoad() {
  58.     loadAccounts();
  59.     print(topKills());
  60. }
  61.  
  62. function onPlayerKill(killer, player, reason, bodypart) {
  63.     /* Do not forget to update the amount of kills when the player scores */
  64.     local i = getAccountID(killer.Name);
  65.     if (i) Accounts[i]["Kills"] ++;
  66. }
Add Comment
Please, Sign In to add comment