Page 1 of 2

Level Rank/Top Systems

Posted: 17 Nov 2017, 14:02
by Raheem
Level Rank/Top Systems

Description:
  • This plugin add Top system like top 15 it will display top x players in motd based on Level and XP. Also it adds Rank so anyone can know his rank based on level, XP also.
Cvars:
  • ze_enable_top_system 1 Enable Top system? 0 = Disable | 1 = Enable
  • ze_levels_top_number 10 How much Players to display in Top?
  • ze_enable_rank_system 1 Enable Rank system? 0 = Disable | 1 = Enable
Commands:
  • say /lvlrank OR say_team /lvlrank Show Rank Motd
  • say /myrank OR say_team /myrank Show player his rank in chat message.
Installation & Instructions:
  • Simply install it like any plugin nothing new but don't forget to copy the sound folder also.
  • It's recommended not to make players shown in Rank System more than 99 but you can do more your limit is how much players you have in Levels.txt
  • If you going to run this system, It's recommended to reset Levels.vault and Ranks.vault
  • If player name contain multi-byte characters like # it will be replaced with space. This because i can't make nice format for these multi-byte characters for now.

Changelog:
  • Spoiler!
    Version: 1.0
    • First Release.
    Version: 1.1 [Current Version]
    • Updated to work with new version of Level System.
    • Fixed wrong ranking and duplicate names in ranking.
    • Catched '<', '>' as stupid characters :lol:.
Screenshots:
  • ImageImage
Downloads:

Re: Level Rank/Top Systems

Posted: 30 Jul 2018, 14:28
by Raheem
Released new version: Image

Re: Level Rank/Top Systems

Posted: 06 Aug 2018, 20:25
by czirimbolo
here is my code:

Code: Select all

#include <zombie_escape>
#include <nvault_util>
#include <ze_levels>

// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[]  = "Ranks"

// Variables
new g_iLevelsVault, g_iRanksVault

// Cvars
new g_pCvarEnableTop, g_pCvarLevelsToShow, g_pCvarEnableRank

public plugin_init()
{
	register_plugin("[ZE] Level Top/Rank", "1.1", "Raheem")
	
	// Commands
	register_clcmd("say /lvlrank", "Cmd_Top")
	register_clcmd("say_team /lvlrank", "Cmd_Top")
	register_clcmd("say /myrank", "Cmd_Rank")
	register_clcmd("say_team /myrank", "Cmd_Rank")
	
	// Cvars
	g_pCvarEnableTop = register_cvar("ze_enable_top_system", "1")
	g_pCvarLevelsToShow = register_cvar("ze_levels_top_number", "10")
	g_pCvarEnableRank = register_cvar("ze_enable_rank_system", "1")
}

public Cmd_Top(id)
{
	if (get_pcvar_num(g_pCvarEnableTop) == 0)
		return
	
	// Open the two vaults using UTIL functions
	new iLevelsVault = nvault_util_open(g_szLevelsVault)
	new iRanksVault = nvault_util_open(g_szRanksVault)
	
	// Open Vaults
	g_iLevelsVault = nvault_open(g_szLevelsVault)
	g_iRanksVault = nvault_open(g_szRanksVault)
	
	// Max elements in Levels.vault and Rank.vault (They are same)
	new iTotal = nvault_util_count(iLevelsVault)
	
	new szKeyLevelSteam[32],	// To hold SteamID from Levels.vault
	szDataLevel[64],			// To hold Levels, XP, MaxXP from Levels.vault
	szKeyRankSteam[32],			// To hold SteamID from Ranks.vault
	szDataRank[64]				// To hold Names from Ranks.vault
	
	new Array:g_szMaxXP			// Dynamic Array to hold all MaxXP (szData) from Levels.vault
	
	// Useless Variables
	new szVal[64], iTimeStamp
	
	// Create Our Arrays with proper lengths [As we don't know iTotal Length so we use Dynamic]
	g_szMaxXP = ArrayCreate(70)
	
	// Tries
	new Trie:g_Level_MaxXP,
	Trie:g_XP_MaxXP, 
	Trie:g_SteamID_MaxXP,
	Trie:g_Name_SteamID
	
	g_Level_MaxXP = TrieCreate()
	g_XP_MaxXP = TrieCreate()
	g_SteamID_MaxXP = TrieCreate()
	g_Name_SteamID = TrieCreate()
	
	// Some integer counters to be used down
	new i, iPos1 = 0, iPos2 = 0
	
	// Format motd Header
	new szMotd[1501], iLen
	
	iLen = formatex(szMotd, charsmax(szMotd), "<body bgcolor=#000000><font color=#CBA50B><h3><pre>")
	iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3s %-32s %-11s %s^n", "#", "Name", "# Level", "# XP")
	
	// Loop through all elements in our Levels.vault and Rank.vault
	for(i = 0; i < iTotal; i++)
	{
		// Get SteamID from Levels.vault and save to szKey
		iPos1 = nvault_util_read(iLevelsVault, iPos1, szKeyLevelSteam, charsmax(szKeyLevelSteam), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Levels, XP for every SteamID from Levels.vault and save to szData
		nvault_lookup(g_iLevelsVault, szKeyLevelSteam, szDataLevel, charsmax(szDataLevel), iTimeStamp)
		
		// Get SteamID from Ranks.vault and save to szKeyRank
		iPos2 = nvault_util_read(iRanksVault, iPos2, szKeyRankSteam, charsmax(szKeyRankSteam), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Name from Ranks.vault and save to szDataRank
		nvault_lookup(g_iRanksVault, szKeyRankSteam, szDataRank, charsmax(szDataRank), iTimeStamp)
		
		// Spliting szData to Level and XP and Save them
		new szLevel[32], szXP[32], szMaxXP[70]
		parse(szDataLevel, szLevel, charsmax(szLevel), szXP, charsmax(szXP), szMaxXP, charsmax(szMaxXP))
		
		// Add XP+MAXXP+SteamID to be unique for every player
		formatex(szMaxXP, charsmax(szMaxXP), "%i %s", str_to_num(szMaxXP) + str_to_num(szXP), szKeyRankSteam)
		
		// Save MAX-XP As Key, Level as Key Value
		TrieSetCell(g_Level_MaxXP, szMaxXP, str_to_num(szLevel))
		
		// Save MAX-XP As Key, XP as Key Value
		TrieSetCell(g_XP_MaxXP, szMaxXP, str_to_num(szXP))
		
		// Save MAX-XP As Key, SteamID as Value
		TrieSetString(g_SteamID_MaxXP, szMaxXP, szKeyLevelSteam)
		
		// Save SteamID As Key, Name as Value
		TrieSetString(g_Name_SteamID, szKeyRankSteam, szDataRank)
		
		// Save our MaxXP to Dynamic Array
		ArrayPushString(g_szMaxXP, szMaxXP)
	}
	
	// Rank Max-XP + SteamID
	ArraySortEx(g_szMaxXP, "TopSorting")
	
	// Get Top Players Data
	for (i = 0; i < get_pcvar_num(g_pCvarLevelsToShow); i++)
	{
		// MaxXP+SteamID As Key
		new szMaxXP[70]
		
		ArrayGetString(g_szMaxXP, i, szMaxXP, charsmax(szMaxXP))
		
		// Get Level
		new Level; TrieGetCell(g_Level_MaxXP, szMaxXP, Level)
		
		// Get XP
		new XP; TrieGetCell(g_XP_MaxXP, szMaxXP, XP)
		
		// Get SteamID
		new szSteamID[36]; TrieGetString(g_SteamID_MaxXP, szMaxXP, szSteamID, charsmax(szSteamID))
		
		// Get Name
		new szName[32]; TrieGetString(g_Name_SteamID, szSteamID, szName, charsmax(szName))

		for (new j = 0; j < charsmax(szName); j++)
		{
			if (is_char_mb(szName[j]) > 0 || szName[j] == '<' || szName[j] == '>')
			{
				szName[j] = ' '
			}
		}
		
		// Format Player
		iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3d %-32s %-11d %d^n", i + 1, szName, Level, XP)
	}
	
	// Format end of motd
	iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</body></font></h3></pre>")
	
	// Finally Show motd to the player
	show_motd(id, szMotd, "Levels Rank")
	
	// Free our memory
	ArrayDestroy(g_szMaxXP)
	TrieDestroy(g_Level_MaxXP)
	TrieDestroy(g_XP_MaxXP)
	TrieDestroy(g_SteamID_MaxXP)
	TrieDestroy(g_Name_SteamID)
	
	// Closing UTIL Vaults
	nvault_util_close(iLevelsVault)
	nvault_util_close(iRanksVault)
	
	// Close Vaults
	nvault_close(g_iLevelsVault)
	nvault_close(g_iRanksVault)
}

public Cmd_Rank(id)
{
	if (get_pcvar_num(g_pCvarEnableRank) == 0)
		return
	
	// Open Levels vault via UTIL function
	new iLevelsVault = nvault_util_open(g_szLevelsVault)
	
	// Open Vault
	g_iLevelsVault = nvault_open(g_szLevelsVault)
	
	// Max elements in Levels.vault and Rank.vault (They are same)
	new iTotal = nvault_util_count(iLevelsVault)
	
	new szKey[32],	// To hold SteamID from Levels.vault
	szData[64]		// To hold Levels, XP from Levels.vault
	
	new Array:iMaxXP	// Dynamic Array to hold all MaxXP (szData) from Levels.vault
	
	// Useless Variables
	new szVal[64], iTimeStamp
	
	// Create Our Arrays with proper lengths [As we don't iTotal Length so we use Dynamic]
	iMaxXP = ArrayCreate(1)
	
	// Some integer counters to be used down
	new i, iPos = 0
	
	// Loop through all elements in our Levels.vault and Rank.vault
	for(i = 0; i < iTotal; i++)
	{
		// Get SteamID from Levels.vault and save to szKey
		iPos = nvault_util_read(iLevelsVault, iPos, szKey, charsmax(szKey), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Levels, XP for every SteamID from Levels.vault and save to szData
		nvault_lookup(g_iLevelsVault, szKey, szData, charsmax(szData), iTimeStamp)

		// Spliting szData to Level and XP and Save them
		new szLevel[32], szXP[32], szMaxXP[32]
		parse(szData, szLevel, 31, szXP, 31, szMaxXP, 31)

		// Save our MaxXP to Dynamic Array
		ArrayPushCell(iMaxXP, str_to_num(szMaxXP) + str_to_num(szXP))
	}
	
	// Rank Max-XP
	ArraySortEx(iMaxXP, "RankSorting")
	
	// Get Player rank
	new iIndex = 0;
	
	for (i = 0; i < ArraySize(iMaxXP); i++)
	{
		if (ArrayGetCell(iMaxXP, i) == (ze_get_user_max_xp(id) + ze_get_user_xp(id)))
		{
			iIndex = i
			break;
		}
	}
	
	ze_colored_print(id, "!tYour rank is !g%i !tof !g%i!y.", iIndex + 1, iTotal - 1)
	
	// Free our memory
	ArrayDestroy(iMaxXP)
	
	// Closing UTIL Vault
	nvault_util_close(iLevelsVault)
	
	// Close Vaults
	nvault_close(g_iLevelsVault)
}

public TopSorting(Array:g_szMaxXP, szItem1[], szItem2[])
{
	// 2D arrays to hold max-xp and steam id for both item1 and item2
	new szMaxXP[2][32], szSteamID[2][36]
	
	// Split item1 to Max-XP and SteamID, same for item 2
	parse(szItem1, szMaxXP[0], 31, szSteamID[0], 36)
	parse(szItem2, szMaxXP[1], 31, szSteamID[1], 36)
	
	// Start ranking
	if (str_to_num(szMaxXP[0]) > str_to_num(szMaxXP[1]))
	{
		return -1
	}
	else if (str_to_num(szMaxXP[0]) < str_to_num(szMaxXP[1]))
	{
		return 1
	}
	
	return 0
}

public RankSorting(Array:iMaxXP, iItem1, iItem2)
{
	if (iItem1 > iItem2)
	{
		return -1
	}
	else if (iItem1 < iItem2)
	{
		return 1
	}
	
	return 0
}
I cant compile:

//// ze_levels_rank_top.sma
//
// C:\Users\macie\Desktop\Compiler v1.8.3\scripting\ze_levels_rank_top.sma(228) : error 017: undefined symbol "ze_get_user_max_xp"
//
// 1 Error.
// Could not locate output file compiled\ze_levels_rank_top.amx (compile failed).
//
// Compilation Time: 0,91 sec
// ----------------------------------------

Re: Level Rank/Top Systems

Posted: 06 Aug 2018, 23:16
by Raheem
Compile without problems for me,
please make sure to use latest compiler and use latest ze_levels.inc from level plugin.

Re: Level Rank/Top Systems

Posted: 07 Aug 2018, 09:04
by czirimbolo
‏‏‎
Ok problem solved. I used ze_levels.inc from this plugin: viewtopic.php?f=17&t=3209&start=10 and that was a problem

Re: Level Rank/Top Systems

Posted: 13 Aug 2018, 20:36
by czirimbolo
Hello, I had this error today:

L 08/13/2018 - 19:44:44: [ZE] Invalid Player id (1)
L 08/13/2018 - 19:44:44: [AMXX] Displaying debug trace (plugin "ze_levels_rank_top.amxx", version "1.1")
L 08/13/2018 - 19:44:44: [AMXX] Run time error 10: native error (native "ze_get_user_max_xp")
L 08/13/2018 - 19:44:44: [AMXX] [0] ze_levels_rank_top.sma::Cmd_Rank (line 228)

Re: Level Rank/Top Systems

Posted: 13 Aug 2018, 21:10
by Prekrasnoe Daleko
czirimbolo wrote: 5 years ago Hello, I had this error today:

L 08/13/2018 - 19:44:44: [ZE] Invalid Player id (1)
L 08/13/2018 - 19:44:44: [AMXX] Displaying debug trace (plugin "ze_levels_rank_top.amxx", version "1.1")
L 08/13/2018 - 19:44:44: [AMXX] Run time error 10: native error (native "ze_get_user_max_xp")
L 08/13/2018 - 19:44:44: [AMXX] [0] ze_levels_rank_top.sma::Cmd_Rank (line 228)
i'am have this problem

Re: Level Rank/Top Systems

Posted: 14 Aug 2018, 16:17
by Raheem
Will happens if there is lower than ze_levels_top_number entered your server. In the nVault it sould be more that the required numbers. Make sure your server got more that required number then it will work without issues.

When get time i'll add check for this to show log message or chat message to player so this error not happen again.

Re: Level Rank/Top Systems

Posted: 14 Aug 2018, 19:53
by Prekrasnoe Daleko
help,
Load fails: Plugin uses an unknown function (name "ze_get_user_max_xp") - check your modules.ini.'
mysql
;sqlite
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Put third party modules below here. ;;
;; You can just list their names, without the _amxx ;;
;; or file extension. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These modules will be auto-detected and loaded ;;
;; as needed. You do not need to enable them here ;;
;; unless you have problems. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;fun
engine
;fakemeta
;geoip
;sockets
;regex
nvault
;cstrike
;csx
;hamsandwichreapi

Re: Level Rank/Top Systems

Posted: 14 Aug 2018, 19:59
by Raheem
Make sure that level system plugin installed and latest version: viewtopic.php?f=15&t=72

Re: Level Rank/Top Systems

Posted: 14 Aug 2018, 20:09
by Prekrasnoe Daleko
Raheem wrote: 5 years ago Make sure that level system plugin installed and latest version: viewtopic.php?f=15&t=72
thanks Raheem all work i'am forget update

Re: Level Rank/Top Systems

Posted: 01 Sep 2018, 18:30
by Mark
When i do /lvlrank nothing happens but im the only player ever in server does this matter?

When i do /myrank i get a chat message <seems this works>
[Zombie Escape] Your rank is 1 of 1.

Re: Level Rank/Top Systems

Posted: 01 Sep 2018, 18:35
by czirimbolo
Raheem wrote: 5 years ago Will happens if there is lower than ze_levels_top_number entered your server. In the nVault it sould be more that the required numbers. Make sure your server got more that required number then it will work without issues.
So how to say, at least 10 or 15 players (depends of the cvar) should join your server to make it working

Re: Level Rank/Top Systems

Posted: 13 Jul 2019, 05:38
by imSpartan
compile with 1.4, i get this error.

Code: Select all

//// ze_frost_m4a1.sma
//
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : error 017: undefined symbol "get_user_msgid"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(13) : error 017: undefined symbol "get_member_game"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(14) : error 017: undefined symbol "numargs"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(19) : error 017: undefined symbol "is_user_connected"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(29) : error 017: undefined symbol "getarg"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(34) : error 017: undefined symbol "getarg"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(35) : error 017: undefined symbol "GetLangTransKey"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(37) : error 017: undefined symbol "setarg"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(45) : error 017: undefined symbol "vformat"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(46) : error 017: undefined symbol "format"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(48) : error 017: undefined symbol "replace_all"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(49) : error 017: undefined symbol "replace_all"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(50) : error 017: undefined symbol "replace_all"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(53) : error 017: undefined symbol "message_begin"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(53) : warning 215: expression has no effect
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(53) : error 029: invalid expression, assumed zero
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(53) : error 029: invalid expression, assumed zero
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(53) : fatal error 107: too many error messages on one line
//
// Compilation aborted.
// 17 Errors.
// Could not locate output file C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\compiled\ze_frost_m4a1.amx (compile failed).
//
// Compilation Time: 0.11 sec
// ----------------------------------------

Re: Level Rank/Top Systems

Posted: 14 Jul 2019, 00:01
by Raheem
Can u post the source code u try to compile?

Re: Level Rank/Top Systems

Posted: 14 Jul 2019, 06:32
by imSpartan
error

Code: Select all

//AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// ze_levels_rank_top.sma
//
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : error 017: undefined symbol "get_user_msgid"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : warning 215: expression has no effect
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : error 001: expected token: ";", but found ")"
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : error 029: invalid expression, assumed zero
// C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\include\zombie_escape.inc(7) : fatal error 107: too many error messages on one line
//
// Compilation aborted.
// 4 Errors.
// Could not locate output file C:\Users\Dell\Desktop\amxx 1.8.3 5169\amxmodx-1.8.3-dev-git5169-base-windows\addons\amxmodx\scripting\compiled\ze_levels_rank_top.amx (compile failed).
//
// Compilation Time: 0.23 sec
// ----------------------------------------

Press enter to exit ...
source code

Code: Select all

#include <zombie_escape>
#include <nvault_util>
#include <ze_levels>

// Constants
new const g_szLevelsVault[] = "Levels"
new const g_szRanksVault[]  = "Ranks"

// Variables
new g_iLevelsVault, g_iRanksVault

// Cvars
new g_pCvarEnableTop, g_pCvarLevelsToShow, g_pCvarEnableRank

public plugin_init()
{
	register_plugin("[ZE] Level Top/Rank", "1.1", "Raheem")
	
	// Commands
	register_clcmd("say /lvlrank", "Cmd_Top")
	register_clcmd("say_team /lvlrank", "Cmd_Top")
	register_clcmd("say /myrank", "Cmd_Rank")
	register_clcmd("say_team /myrank", "Cmd_Rank")
	
	// Cvars
	g_pCvarEnableTop = register_cvar("ze_enable_top_system", "1")
	g_pCvarLevelsToShow = register_cvar("ze_levels_top_number", "10")
	g_pCvarEnableRank = register_cvar("ze_enable_rank_system", "1")
}

public Cmd_Top(id)
{
	if (get_pcvar_num(g_pCvarEnableTop) == 0)
		return
	
	// Open the two vaults using UTIL functions
	new iLevelsVault = nvault_util_open(g_szLevelsVault)
	new iRanksVault = nvault_util_open(g_szRanksVault)
	
	// Open Vaults
	g_iLevelsVault = nvault_open(g_szLevelsVault)
	g_iRanksVault = nvault_open(g_szRanksVault)
	
	// Max elements in Levels.vault and Rank.vault (They are same)
	new iTotal = nvault_util_count(iLevelsVault)
	
	new szKeyLevelSteam[32],	// To hold SteamID from Levels.vault
	szDataLevel[64],			// To hold Levels, XP, MaxXP from Levels.vault
	szKeyRankSteam[32],			// To hold SteamID from Ranks.vault
	szDataRank[64]				// To hold Names from Ranks.vault
	
	new Array:g_szMaxXP			// Dynamic Array to hold all MaxXP (szData) from Levels.vault
	
	// Useless Variables
	new szVal[64], iTimeStamp
	
	// Create Our Arrays with proper lengths [As we don't know iTotal Length so we use Dynamic]
	g_szMaxXP = ArrayCreate(70)
	
	// Tries
	new Trie:g_Level_MaxXP,
	Trie:g_XP_MaxXP, 
	Trie:g_SteamID_MaxXP,
	Trie:g_Name_SteamID
	
	g_Level_MaxXP = TrieCreate()
	g_XP_MaxXP = TrieCreate()
	g_SteamID_MaxXP = TrieCreate()
	g_Name_SteamID = TrieCreate()
	
	// Some integer counters to be used down
	new i, iPos1 = 0, iPos2 = 0
	
	// Format motd Header
	new szMotd[1501], iLen
	
	iLen = formatex(szMotd, charsmax(szMotd), "<body bgcolor=#000000><font color=#CBA50B><h3><pre>")
	iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3s %-32s %-11s %s^n", "#", "Name", "# Level", "# XP")
	
	// Loop through all elements in our Levels.vault and Rank.vault
	for(i = 0; i < iTotal; i++)
	{
		// Get SteamID from Levels.vault and save to szKey
		iPos1 = nvault_util_read(iLevelsVault, iPos1, szKeyLevelSteam, charsmax(szKeyLevelSteam), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Levels, XP for every SteamID from Levels.vault and save to szData
		nvault_lookup(g_iLevelsVault, szKeyLevelSteam, szDataLevel, charsmax(szDataLevel), iTimeStamp)
		
		// Get SteamID from Ranks.vault and save to szKeyRank
		iPos2 = nvault_util_read(iRanksVault, iPos2, szKeyRankSteam, charsmax(szKeyRankSteam), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Name from Ranks.vault and save to szDataRank
		nvault_lookup(g_iRanksVault, szKeyRankSteam, szDataRank, charsmax(szDataRank), iTimeStamp)
		
		// Spliting szData to Level and XP and Save them
		new szLevel[32], szXP[32], szMaxXP[70]
		parse(szDataLevel, szLevel, charsmax(szLevel), szXP, charsmax(szXP), szMaxXP, charsmax(szMaxXP))
		
		// Add XP+MAXXP+SteamID to be unique for every player
		formatex(szMaxXP, charsmax(szMaxXP), "%i %s", str_to_num(szMaxXP) + str_to_num(szXP), szKeyRankSteam)
		
		// Save MAX-XP As Key, Level as Key Value
		TrieSetCell(g_Level_MaxXP, szMaxXP, str_to_num(szLevel))
		
		// Save MAX-XP As Key, XP as Key Value
		TrieSetCell(g_XP_MaxXP, szMaxXP, str_to_num(szXP))
		
		// Save MAX-XP As Key, SteamID as Value
		TrieSetString(g_SteamID_MaxXP, szMaxXP, szKeyLevelSteam)
		
		// Save SteamID As Key, Name as Value
		TrieSetString(g_Name_SteamID, szKeyRankSteam, szDataRank)
		
		// Save our MaxXP to Dynamic Array
		ArrayPushString(g_szMaxXP, szMaxXP)
	}
	
	// Rank Max-XP + SteamID
	ArraySortEx(g_szMaxXP, "TopSorting")
	
	// Get Top Players Data
	for (i = 0; i < get_pcvar_num(g_pCvarLevelsToShow); i++)
	{
		// MaxXP+SteamID As Key
		new szMaxXP[70]
		
		ArrayGetString(g_szMaxXP, i, szMaxXP, charsmax(szMaxXP))
		
		// Get Level
		new Level; TrieGetCell(g_Level_MaxXP, szMaxXP, Level)
		
		// Get XP
		new XP; TrieGetCell(g_XP_MaxXP, szMaxXP, XP)
		
		// Get SteamID
		new szSteamID[36]; TrieGetString(g_SteamID_MaxXP, szMaxXP, szSteamID, charsmax(szSteamID))
		
		// Get Name
		new szName[32]; TrieGetString(g_Name_SteamID, szSteamID, szName, charsmax(szName))

		for (new j = 0; j < charsmax(szName); j++)
		{
			if (is_char_mb(szName[j]) > 0 || szName[j] == '<' || szName[j] == '>')
			{
				szName[j] = ' '
			}
		}
		
		// Format Player
		iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "%-3d %-32s %-11d %d^n", i + 1, szName, Level, XP)
	}
	
	// Format end of motd
	iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</body></font></h3></pre>")
	
	// Finally Show motd to the player
	show_motd(id, szMotd, "Levels Rank")
	
	// Free our memory
	ArrayDestroy(g_szMaxXP)
	TrieDestroy(g_Level_MaxXP)
	TrieDestroy(g_XP_MaxXP)
	TrieDestroy(g_SteamID_MaxXP)
	TrieDestroy(g_Name_SteamID)
	
	// Closing UTIL Vaults
	nvault_util_close(iLevelsVault)
	nvault_util_close(iRanksVault)
	
	// Close Vaults
	nvault_close(g_iLevelsVault)
	nvault_close(g_iRanksVault)
}

public Cmd_Rank(id)
{
	if (get_pcvar_num(g_pCvarEnableRank) == 0)
		return
	
	// Open Levels vault via UTIL function
	new iLevelsVault = nvault_util_open(g_szLevelsVault)
	
	// Open Vault
	g_iLevelsVault = nvault_open(g_szLevelsVault)
	
	// Max elements in Levels.vault and Rank.vault (They are same)
	new iTotal = nvault_util_count(iLevelsVault)
	
	new szKey[32],	// To hold SteamID from Levels.vault
	szData[64]		// To hold Levels, XP from Levels.vault
	
	new Array:iMaxXP	// Dynamic Array to hold all MaxXP (szData) from Levels.vault
	
	// Useless Variables
	new szVal[64], iTimeStamp
	
	// Create Our Arrays with proper lengths [As we don't iTotal Length so we use Dynamic]
	iMaxXP = ArrayCreate(1)
	
	// Some integer counters to be used down
	new i, iPos = 0
	
	// Loop through all elements in our Levels.vault and Rank.vault
	for(i = 0; i < iTotal; i++)
	{
		// Get SteamID from Levels.vault and save to szKey
		iPos = nvault_util_read(iLevelsVault, iPos, szKey, charsmax(szKey), szVal, charsmax(szVal), iTimeStamp)
		
		// Get Levels, XP for every SteamID from Levels.vault and save to szData
		nvault_lookup(g_iLevelsVault, szKey, szData, charsmax(szData), iTimeStamp)

		// Spliting szData to Level and XP and Save them
		new szLevel[32], szXP[32], szMaxXP[32]
		parse(szData, szLevel, 31, szXP, 31, szMaxXP, 31)

		// Save our MaxXP to Dynamic Array
		ArrayPushCell(iMaxXP, str_to_num(szMaxXP) + str_to_num(szXP))
	}
	
	// Rank Max-XP
	ArraySortEx(iMaxXP, "RankSorting")
	
	// Get Player rank
	new iIndex = 0;
	
	for (i = 0; i < ArraySize(iMaxXP); i++)
	{
		if (ArrayGetCell(iMaxXP, i) == (ze_get_user_max_xp(id) + ze_get_user_xp(id)))
		{
			iIndex = i
			break;
		}
	}
	
	ze_colored_print(id, "!tYour rank is !g%i !tof !g%i!y.", iIndex + 1, iTotal - 1)
	
	// Free our memory
	ArrayDestroy(iMaxXP)
	
	// Closing UTIL Vault
	nvault_util_close(iLevelsVault)
	
	// Close Vaults
	nvault_close(g_iLevelsVault)
}

public TopSorting(Array:g_szMaxXP, szItem1[], szItem2[])
{
	// 2D arrays to hold max-xp and steam id for both item1 and item2
	new szMaxXP[2][32], szSteamID[2][36]
	
	// Split item1 to Max-XP and SteamID, same for item 2
	parse(szItem1, szMaxXP[0], 31, szSteamID[0], 36)
	parse(szItem2, szMaxXP[1], 31, szSteamID[1], 36)
	
	// Start ranking
	if (str_to_num(szMaxXP[0]) > str_to_num(szMaxXP[1]))
	{
		return -1
	}
	else if (str_to_num(szMaxXP[0]) < str_to_num(szMaxXP[1]))
	{
		return 1
	}
	
	return 0
}

public RankSorting(Array:iMaxXP, iItem1, iItem2)
{
	if (iItem1 > iItem2)
	{
		return -1
	}
	else if (iItem1 < iItem2)
	{
		return 1
	}
	
	return 0
}

Re: Level Rank/Top Systems

Posted: 14 Jul 2019, 07:44
by Raheem
Compile with me without any erros, make sure to use this compiler: viewtopic.php?f=6&t=221

Also post your zombie_escape.inc file.

Re: Level Rank/Top Systems

Posted: 20 Jul 2019, 11:25
by imSpartan
Raheem is there a PHP version to put on the website to show in-game ranking?

Re: Level Rank/Top Systems

Posted: 20 Jul 2019, 12:30
by Muhammet20
imSpartan wrote: 4 years ago Raheem is there a PHP version to put on the website to show in-game ranking?
you mean like this? :
viewtopic.php?f=21&t=3562

Re: Level Rank/Top Systems

Posted: 20 Jul 2019, 15:58
by imSpartan
Muhammet20 wrote: 4 years ago
imSpartan wrote: 4 years ago Raheem is there a PHP version to put on the website to show in-game ranking?
you mean like this? :
viewtopic.php?f=21&t=3562
Why is it on trash?