Approved Level Rank/Top Systems

Gameplay Addons
imSpartan
Member
Member
Malaysia
Posts: 22
Joined: 6 Months Ago
Has thanked: 6 times
Been thanked: 0
Contact:

Re: Level Rank/Top Systems

#31

Post by imSpartan » 6 Months Ago

Thank you, sir.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 550
Joined: 2 Years Ago
Has thanked: 20 times
Been thanked: 2 times
Contact:

#32

Post by czirimbolo » 7 Hours Ago

I noticed when I type /myrank (or/rank) I am always 1 of xxxx. Of course I am not TOP1. Every player have this problem. /lvlrank is working good. Cvars are ON. Where is the problem? I dont have any errors. Maybe new level system causing this? I use updated version! ---> viewtopic.php?f=15&t=72&start=120

my code:
  1. #include <zombie_escape>
  2. #include <nvault_util>
  3. #include <ze_levels>
  4.  
  5. // Constants
  6. new const g_szLevelsVault[] = "Levels"
  7. new const g_szRanksVault[]  = "Ranks"
  8.  
  9. // Variables
  10. new g_iLevelsVault, g_iRanksVault
  11.  
  12. // Cvars
  13. new g_pCvarEnableTop, g_pCvarLevelsToShow, g_pCvarEnableRank
  14.  
  15. public plugin_init()
  16. {
  17.     register_plugin("[ZE] Level Top/Rank", "1.1", "Raheem")
  18.    
  19.     // Commands
  20.     register_clcmd("say /top15", "Cmd_Top")
  21.     register_clcmd("say_team /top15", "Cmd_Top")
  22.     register_clcmd("say /rank", "Cmd_Rank")
  23.     register_clcmd("say_team /rank", "Cmd_Rank")
  24.    
  25.     // Cvars
  26.     g_pCvarEnableTop = register_cvar("ze_enable_top_system", "1")
  27.     g_pCvarLevelsToShow = register_cvar("ze_levels_top_number", "10")
  28.     g_pCvarEnableRank = register_cvar("ze_enable_rank_system", "1")
  29. }
  30.  
  31. public Cmd_Top(id)
  32. {
  33.     if (get_pcvar_num(g_pCvarEnableTop) == 0)
  34.         return
  35.    
  36.     // Open the two vaults using UTIL functions
  37.     new iLevelsVault = nvault_util_open(g_szLevelsVault)
  38.     new iRanksVault = nvault_util_open(g_szRanksVault)
  39.    
  40.     // Open Vaults
  41.     g_iLevelsVault = nvault_open(g_szLevelsVault)
  42.     g_iRanksVault = nvault_open(g_szRanksVault)
  43.    
  44.     // Max elements in Levels.vault and Rank.vault (They are same)
  45.     new iTotal = nvault_util_count(iLevelsVault)
  46.    
  47.     new szKeyLevelSteam[32],    // To hold SteamID from Levels.vault
  48.     szDataLevel[64],            // To hold Levels, XP, MaxXP from Levels.vault
  49.     szKeyRankSteam[32],         // To hold SteamID from Ranks.vault
  50.     szDataRank[64]              // To hold Names from Ranks.vault
  51.    
  52.     new Array:g_szMaxXP         // Dynamic Array to hold all MaxXP (szData) from Levels.vault
  53.    
  54.     // Useless Variables
  55.     new szVal[64], iTimeStamp
  56.    
  57.     // Create Our Arrays with proper lengths [As we don't know iTotal Length so we use Dynamic]
  58.     g_szMaxXP = ArrayCreate(70)
  59.    
  60.     // Tries
  61.     new Trie:g_Level_MaxXP,
  62.     Trie:g_XP_MaxXP,
  63.     Trie:g_SteamID_MaxXP,
  64.     Trie:g_Name_SteamID
  65.    
  66.     g_Level_MaxXP = TrieCreate()
  67.     g_XP_MaxXP = TrieCreate()
  68.     g_SteamID_MaxXP = TrieCreate()
  69.     g_Name_SteamID = TrieCreate()
  70.    
  71.     // Some integer counters to be used down
  72.     new i, iPos1 = 0, iPos2 = 0
  73.    
  74.     // Format motd Header
  75.     new szMotd[1501], iLen
  76.    
  77.     iLen = formatex(szMotd, charsmax(szMotd), "<body bgcolor=#000000><font color=#CBA50B><h3><pre>")
  78.     iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3s %-32s %-11s %s^n", "#", "Name", "# Level", "# XP")
  79.    
  80.     // Loop through all elements in our Levels.vault and Rank.vault
  81.     for(i = 0; i < iTotal; i++)
  82.     {
  83.         // Get SteamID from Levels.vault and save to szKey
  84.         iPos1 = nvault_util_read(iLevelsVault, iPos1, szKeyLevelSteam, charsmax(szKeyLevelSteam), szVal, charsmax(szVal), iTimeStamp)
  85.        
  86.         // Get Levels, XP for every SteamID from Levels.vault and save to szData
  87.         nvault_lookup(g_iLevelsVault, szKeyLevelSteam, szDataLevel, charsmax(szDataLevel), iTimeStamp)
  88.        
  89.         // Get SteamID from Ranks.vault and save to szKeyRank
  90.         iPos2 = nvault_util_read(iRanksVault, iPos2, szKeyRankSteam, charsmax(szKeyRankSteam), szVal, charsmax(szVal), iTimeStamp)
  91.        
  92.         // Get Name from Ranks.vault and save to szDataRank
  93.         nvault_lookup(g_iRanksVault, szKeyRankSteam, szDataRank, charsmax(szDataRank), iTimeStamp)
  94.        
  95.         // Spliting szData to Level and XP and Save them
  96.         new szLevel[32], szXP[32], szMaxXP[70]
  97.         parse(szDataLevel, szLevel, charsmax(szLevel), szXP, charsmax(szXP), szMaxXP, charsmax(szMaxXP))
  98.        
  99.         // Add XP+MAXXP+SteamID to be unique for every player
  100.         formatex(szMaxXP, charsmax(szMaxXP), "%i %s", str_to_num(szMaxXP) + str_to_num(szXP), szKeyRankSteam)
  101.        
  102.         // Save MAX-XP As Key, Level as Key Value
  103.         TrieSetCell(g_Level_MaxXP, szMaxXP, str_to_num(szLevel))
  104.        
  105.         // Save MAX-XP As Key, XP as Key Value
  106.         TrieSetCell(g_XP_MaxXP, szMaxXP, str_to_num(szXP))
  107.        
  108.         // Save MAX-XP As Key, SteamID as Value
  109.         TrieSetString(g_SteamID_MaxXP, szMaxXP, szKeyLevelSteam)
  110.        
  111.         // Save SteamID As Key, Name as Value
  112.         TrieSetString(g_Name_SteamID, szKeyRankSteam, szDataRank)
  113.        
  114.         // Save our MaxXP to Dynamic Array
  115.         ArrayPushString(g_szMaxXP, szMaxXP)
  116.     }
  117.    
  118.     // Rank Max-XP + SteamID
  119.     ArraySortEx(g_szMaxXP, "TopSorting")
  120.    
  121.     // Get Top Players Data
  122.     for (i = 0; i < get_pcvar_num(g_pCvarLevelsToShow); i++)
  123.     {
  124.         // MaxXP+SteamID As Key
  125.         new szMaxXP[70]
  126.        
  127.         ArrayGetString(g_szMaxXP, i, szMaxXP, charsmax(szMaxXP))
  128.        
  129.         // Get Level
  130.         new Level; TrieGetCell(g_Level_MaxXP, szMaxXP, Level)
  131.        
  132.         // Get XP
  133.         new XP; TrieGetCell(g_XP_MaxXP, szMaxXP, XP)
  134.        
  135.         // Get SteamID
  136.         new szSteamID[36]; TrieGetString(g_SteamID_MaxXP, szMaxXP, szSteamID, charsmax(szSteamID))
  137.        
  138.         // Get Name
  139.         new szName[32]; TrieGetString(g_Name_SteamID, szSteamID, szName, charsmax(szName))
  140.  
  141.         for (new j = 0; j < charsmax(szName); j++)
  142.         {
  143.             if (is_char_mb(szName[j]) > 0 || szName[j] == '<' || szName[j] == '>')
  144.             {
  145.                 szName[j] = ' '
  146.             }
  147.         }
  148.        
  149.         // Format Player
  150.         iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3d %-32s %-11d %d^n", i + 1, szName, Level, XP)
  151.     }
  152.    
  153.     // Format end of motd
  154.     iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</body></font></h3></pre>")
  155.    
  156.     // Finally Show motd to the player
  157.     show_motd(id, szMotd, "Levels Rank")
  158.    
  159.     // Free our memory
  160.     ArrayDestroy(g_szMaxXP)
  161.     TrieDestroy(g_Level_MaxXP)
  162.     TrieDestroy(g_XP_MaxXP)
  163.     TrieDestroy(g_SteamID_MaxXP)
  164.     TrieDestroy(g_Name_SteamID)
  165.    
  166.     // Closing UTIL Vaults
  167.     nvault_util_close(iLevelsVault)
  168.     nvault_util_close(iRanksVault)
  169.    
  170.     // Close Vaults
  171.     nvault_close(g_iLevelsVault)
  172.     nvault_close(g_iRanksVault)
  173. }
  174.  
  175. public Cmd_Rank(id)
  176. {
  177.     if (get_pcvar_num(g_pCvarEnableRank) == 0)
  178.         return
  179.    
  180.     // Open Levels vault via UTIL function
  181.     new iLevelsVault = nvault_util_open(g_szLevelsVault)
  182.    
  183.     // Open Vault
  184.     g_iLevelsVault = nvault_open(g_szLevelsVault)
  185.    
  186.     // Max elements in Levels.vault and Rank.vault (They are same)
  187.     new iTotal = nvault_util_count(iLevelsVault)
  188.    
  189.     new szKey[32]// To hold SteamID from Levels.vault
  190.     szData[64]      // To hold Levels, XP from Levels.vault
  191.    
  192.     new Array:iMaxXP    // Dynamic Array to hold all MaxXP (szData) from Levels.vault
  193.    
  194.     // Useless Variables
  195.     new szVal[64], iTimeStamp
  196.    
  197.     // Create Our Arrays with proper lengths [As we don't iTotal Length so we use Dynamic]
  198.     iMaxXP = ArrayCreate(1)
  199.    
  200.     // Some integer counters to be used down
  201.     new i, iPos = 0
  202.    
  203.     // Loop through all elements in our Levels.vault and Rank.vault
  204.     for(i = 0; i < iTotal; i++)
  205.     {
  206.         // Get SteamID from Levels.vault and save to szKey
  207.         iPos = nvault_util_read(iLevelsVault, iPos, szKey, charsmax(szKey), szVal, charsmax(szVal), iTimeStamp)
  208.        
  209.         // Get Levels, XP for every SteamID from Levels.vault and save to szData
  210.         nvault_lookup(g_iLevelsVault, szKey, szData, charsmax(szData), iTimeStamp)
  211.  
  212.         // Spliting szData to Level and XP and Save them
  213.         new szLevel[32], szXP[32], szMaxXP[32]
  214.         parse(szData, szLevel, 31, szXP, 31, szMaxXP, 31)
  215.  
  216.         // Save our MaxXP to Dynamic Array
  217.         ArrayPushCell(iMaxXP, str_to_num(szMaxXP) + str_to_num(szXP))
  218.     }
  219.    
  220.     // Rank Max-XP
  221.     ArraySortEx(iMaxXP, "RankSorting")
  222.    
  223.     // Get Player rank
  224.     new iIndex = 0;
  225.    
  226.     for (i = 0; i < ArraySize(iMaxXP); i++)
  227.     {
  228.         if (ArrayGetCell(iMaxXP, i) == (ze_get_user_max_xp(id) + ze_get_user_xp(id)))
  229.         {
  230.             iIndex = i
  231.             break;
  232.         }
  233.     }
  234.    
  235.     ze_colored_print(id, "!tYour rank is !g%i !tof !g%i!y.", iIndex + 1, iTotal - 1)
  236.    
  237.     // Free our memory
  238.     ArrayDestroy(iMaxXP)
  239.    
  240.     // Closing UTIL Vault
  241.     nvault_util_close(iLevelsVault)
  242.    
  243.     // Close Vaults
  244.     nvault_close(g_iLevelsVault)
  245. }
  246.  
  247. public TopSorting(Array:g_szMaxXP, szItem1[], szItem2[])
  248. {
  249.     // 2D arrays to hold max-xp and steam id for both item1 and item2
  250.     new szMaxXP[2][32], szSteamID[2][36]
  251.    
  252.     // Split item1 to Max-XP and SteamID, same for item 2
  253.     parse(szItem1, szMaxXP[0], 31, szSteamID[0], 36)
  254.     parse(szItem2, szMaxXP[1], 31, szSteamID[1], 36)
  255.    
  256.     // Start ranking
  257.     if (str_to_num(szMaxXP[0]) > str_to_num(szMaxXP[1]))
  258.     {
  259.         return -1
  260.     }
  261.     else if (str_to_num(szMaxXP[0]) < str_to_num(szMaxXP[1]))
  262.     {
  263.         return 1
  264.     }
  265.    
  266.     return 0
  267. }
  268.  
  269. public RankSorting(Array:iMaxXP, iItem1, iItem2)
  270. {
  271.     if (iItem1 > iItem2)
  272.     {
  273.         return -1
  274.     }
  275.     else if (iItem1 < iItem2)
  276.     {
  277.         return 1
  278.     }
  279.    
  280.     return 0
  281. }
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest