nVault; Грешно извеждане на Data_Rank 0/x

Всички ненужни и извън правилата теми.
Заключена
Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Грешно извеждане на Data_Rank 0/x

Мнение от LayerFort DJBosma » 12 фев 2019, 15:03

Това с което се спречквам е ранк който показва 0/х навсякъде.
Прочетете мненията по-надоло за да получите по-добра представа.

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault_util>
#include <fakemeta>
#include <engine>
#include <zombieplague>

new const szRanks[][] = 
{
    "Guardsman",
    "Healer",
    "Protector",
    "Warrior",
    "High Warrior",
    "Alpha Warrior",
    "Archwarrior",
    "High Archwarrior",
    "Alpha Archwarrior",
    "Destroyer",
    "High Destroyer",
    "Alpha Destroyer",
    "Commander",
    "High Commander",
    "Alpha Commander",
    "Baron",
    "High Baron",
    "Alpha Baron",
    "King",
    "Alpha King",
    "Overlord",
    "Hacker"
}

new const iEXP[] = 
{
    0,
    50,
    100,
    200,
    250,
    300,
    350,
    400,
    450,
    500,
    600,
    700,
    700,
    800,
    900,
    1100,
    1250,
    1500,
    2000,
    2500,
    3000,
    999999999
}

enum _:Player_Data
{
	Data_Steamid[35],
	//Data_Ip[16],
	Data_Name[32],
	Data_Exp,
	Data_Kills,
	Data_Deaths,
	Data_HeadShot,
	Data_Knife,
	Data_Nade,
	Data_NemKills,
	Data_SurKills,
	Data_PlayTime,
	Data_Level,
	Data_Country[46],
	Data_Rank,
	Data_Connected,
	MAX_PLAYER_DATA
}

enum _:Forward_Data
{
	Forward_Levelup,
	Forward_Exp_Add,
	Forward_Exp_Set,
	Forward_Result,
	MAX_FORWARD_DATA
}

new iVaultHandle, gData[33][MAX_PLAYER_DATA], iHudStats, Float:fLastHud[33], szMotd[1536], gForward[MAX_FORWARD_DATA], Float:fLastCmd, iTotalEntries, iMsgSayText
const iExpKill = 1
const iExpHeadShot = 3
const iExpKnife = 4
const iExpGrenade = 4
const iExpNemKill = 5
const iExpSurKill = 5
const Float:HUD_STATS_X = 0.77//-1.0
const Float:HUD_STATS_Y = 0.6//0.8
new const szVaultName[] = "fter-zpuservault"

#define is_user_valid(%0) (0<%0<33)
new cvar_ammopacks
//new g_maxplayers

new Ammopacks[22] = {
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    21,
    0
}

//Uncomment this to update motd.txt on map loaded to show global top-10 players.
#define UPDATE_MOTD

//Uncomment this to enable nvault prune.
#define PRUNE_DATABASE


#if defined UPDATE_MOTD
new const szFileMotd[] = "motd.txt"
#endif

#if defined PRUNE_DATABASE
const iExpiredDays = 30
#endif

public plugin_natives()
{
	register_native("xp_get_user_exp","_get_user_exp",1)
	register_native("xp_set_user_exp","_set_user_exp",1)
	
	register_native("xp_get_user_playtime","_get_user_playtime",1)
	register_native("xp_set_user_playtime","_set_user_playtime",1)
	
	register_native("xp_get_user_level","_get_user_level",1)
	register_native("xp_set_user_level","_set_user_level",1)
	
	register_native("xp_get_user_deaths","_get_user_deaths",1)
	register_native("xp_set_user_deaths","_set_user_deaths",1)
	
	register_native("xp_get_user_frags","_get_user_frags",1)
	register_native("xp_set_user_frags","_set_user_frags",1)
	
	register_native("xp_get_user_headshot","_get_user_headshot",1)
	register_native("xp_set_user_headshot","_set_user_headshot",1)
	
	register_native("xp_get_user_knife","_get_user_knife",1)
	register_native("xp_set_user_knife","_set_user_knife",1)
	
	register_native("xp_get_user_nade","_get_user_nade",1)
	register_native("xp_set_user_nade","_set_user_nade",1)
	
	register_native("xp_get_user_nemesis","_get_user_nemesis",1)
	register_native("xp_set_user_nemesis","_set_user_nemesis",1)
	
	register_native("xp_get_user_survivor","_get_user_survivor",1)
	register_native("xp_set_user_survivor","_set_user_survivor",1)
	
	register_native("xp_reset_user_data","_reset_user_data",1)
	register_native("xp_get_user_rank","_get_user_rank",1)
	register_native("xp_check_user_level","CheckPlayerLevel",1)
}

public plugin_init()
{
	new const PLUGIN_VERSION[] = "1.0"//0.0.5
	new const CVAR_EXP_VERSION[] = "n4d_zpstats"
	register_plugin("[ZP] UserVault", PLUGIN_VERSION, "wbyokomo, huehue, djbosma")
	
	iHudStats = CreateHudSyncObj()
	iMsgSayText = get_user_msgid("SayText")
	
	//register_event("HLTV", "event_newround", "a", "1=0", "2=0")
	register_event("DeathMsg", "OnDeathMsg", "a") //use deathmsg easy to trace weapon and hitplace
	register_event_ex("30", "Event_Intermission", RegisterEvent_Global)
	
	RegisterHam(Ham_Player_PreThink, "player", "OnPlayerPreThink")
	
	register_clcmd("say /stats" , "CmdStats")
	register_clcmd("say /rank", "CmdShowRank")
	register_clcmd("say /top15", "CmdTopExpGlobal")
	register_clcmd("say /top10", "CmdTopExpGlobal")
	register_clcmd("say /toponline", "CmdTopExpOnline")
	
	register_clcmd("say_team /stats" , "CmdStats")
	register_clcmd("say_team /rank", "CmdShowRank")
	register_clcmd("say_team /top15", "CmdTopExpGlobal")
	register_clcmd("say_team /top10", "CmdTopExpGlobal")
	register_clcmd("say_team /toponline", "CmdTopExpOnline")
	
	cvar_ammopacks = register_cvar("xp_ammopacks_reward", "1")
	//g_maxplayers = get_maxplayers()
	

	gForward[Forward_Levelup] = CreateMultiForward("xp_user_levelup", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL) //xp_user_levelup(player, level, exp)
	gForward[Forward_Exp_Add] = CreateMultiForward("xp_user_expadd", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expadd(player, expadd)
	gForward[Forward_Exp_Set] = CreateMultiForward("xp_user_expset", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expset(player, exptotal)
	
	register_cvar(CVAR_EXP_VERSION, PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	set_cvar_string(CVAR_EXP_VERSION, PLUGIN_VERSION)
}

/*
public event_newround()
{
	new id;
	for(id = 1; id<= g_maxplayers; id++)
		if(is_user_valid(id) && is_user_alive(id) && is_user_connected(id) && !zp_get_user_zombie(id)
		&& !zp_get_user_nemesis(id) && !zp_get_user_survivor(id))
			reward_user(id, 1)
}
*/

public Event_Intermission()
{
	set_task_ex(0.1, "Delayed_Intermission")
}
public Delayed_Intermission()
{
	new iPlayers[MAX_PLAYERS], iNum, id
	get_players_ex(iPlayers, iNum, GetPlayers_ExcludeHLTV|GetPlayers_ExcludeBots)

	for (--iNum; iNum >= 0; iNum--)
	{
		id = iPlayers[iNum]

		if (!is_user_connected(id))
			return

		reward_with_ammopacks(id)
	}
}
public fw_spawn_post(id)
{
	if(zp_get_user_zombie(id) || zp_get_user_survivor(id) || zp_get_user_nemesis(id)
	|| !is_user_alive(id) || !is_user_connected(id) || !is_user_valid(id)) {return;}
	else
		reward_user(id, 0)
}

public zp_user_humanized_post(id)
	fw_spawn_post(id)

reward_user(id, roundstart)
{
	if(get_pcvar_num(cvar_ammopacks) == 1 && roundstart == 1){ reward_with_ammopacks(id);}
}

reward_with_ammopacks(id)
{
	new ap = Ammopacks[gData[id][Data_Level]]
	zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ap)
	//client_print(id, print_chat, "You received %d ammmopacks from the server", ap)
	UTIL_ColorChat(id, "^x04[User Vault]^x01 You received:^x04 %d^x01 ammmopacks from the server", ap)
}

public plugin_cfg()
{
	iVaultHandle = nvault_open(szVaultName)
	
	if(iVaultHandle == INVALID_HANDLE)
	{
		new szText[128]; formatex(szText, 127, "[UserVault] Error opening nVault file [%s]", szVaultName);
		set_fail_state(szText)
	}
	else
	{
		server_print("[UserVault] Database [%s] successfully loaded...", szVaultName)
		
		#if defined PRUNE_DATABASE
		nvault_prune(iVaultHandle, 0, get_systime() - (86400 * iExpiredDays))
		#endif
		
		FormatGlobalTopTen()
		
		#if defined UPDATE_MOTD
		if(file_exists(szFileMotd))
		{
			if(delete_file(szFileMotd))
			{
				if(write_file(szFileMotd, szMotd, -1)) server_print("[UserVault] File [%s] has been updated...", szFileMotd);
			}
		}
		#endif
	}
}

public plugin_end()
{
	nvault_close(iVaultHandle)
}

public client_putinserver(id)
{

	if (is_user_hltv(id))
		return;

	arrayset(gData[id], 0, sizeof(gData[]))
	
	get_user_name(id, gData[id][Data_Name], charsmax(gData[][Data_Name]))
	get_user_authid(id, gData[id][Data_Steamid], charsmax(gData[][Data_Steamid]))
	//get_user_ip(id, gData[id][Data_Ip], charsmax(gData[][Data_Ip]))
	set_task(0.1, "Load_Data", id, gData[id][Data_Name], sizeof(gData[][Data_Name]))
}

public client_disconnected(id)
{
	if (gData[id][Data_Connected])
	{
		gData[id][Data_PlayTime] += get_user_time(id)
		Save_Data(id, gData[id][Data_Name])
		gData[id][Data_Connected] = false
	}
}

public client_infochanged(id)
{
	if (!is_user_connected(id))
		return PLUGIN_HANDLED
	
	static szNames[2][32]
	get_user_name(id, szNames[0], charsmax(szNames[]))
	get_user_info(id, "name", szNames[1], charsmax(szNames[]))

	if (!equali(szNames[1], szNames[0]))
	{
		Save_Data(id, szNames[0])
		set_task(0.1, "Load_Data", id, szNames[1], sizeof(szNames[]))
		gData[id][Data_Name] = szNames[1]
		return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public CmdStats(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	new menu = menu_create("\yPlayer Stats:", "PlayerStatsMenuHandler")
	new szUserId[32], iPlayers[32], iNum, j, id2, szName[32]
	get_players(iPlayers, iNum, "h")
	for(j=0;j<iNum;j++)
	{
		id2 = iPlayers[j]
		get_user_name(id2, szName, 31)
		formatex(szUserId, 31, "%d", get_user_userid(id2))
		menu_additem(menu, szName, szUserId, 0)
	}
	
	menu_display(id, menu, 0)
	
	return PLUGIN_HANDLED;
}

public PlayerStatsMenuHandler(id, menu, item)
{
	if(!is_user_connected(id))
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	new szData[6], szName[64]
	new _access, item_callback
	menu_item_getinfo(menu, item, _access, szData, 5, szName, 63, item_callback)
	
	new userid = str_to_num(szData)
	new player = find_player("k", userid)
	
	if(player && is_user_connected(player))
	{
		GetPlayerStats(player, id)
	}
	
	menu_destroy(menu)
	return PLUGIN_HANDLED;
}

public CmdShowRank(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	new iRank = SortPlayerRank(id)
	if(iRank == -1) UTIL_ColorChat(id, "^x04[UserVault]^x01 Your rank is not been saved yet, please rejoin the server.") //client_print(id, print_chat, "Your rank is not been saved yet, please rejoin the server.");
	else UTIL_ColorChat(id, "^x04%s^x01 rank is^x04 %d^x01/^x04%d^x01 -- Kills:^x04 %d^x01 Deaths:^x04 %d^x01 Stage:^x04 %d^x01 Points:^x04 %d^x01/^x04%d", gData[id][Data_Name], iRank, iTotalEntries, gData[id][Data_Kills], gData[id][Data_Deaths], szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1])
	
	return PLUGIN_HANDLED;
}

public CmdTopExpGlobal(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	show_motd(id, szMotd, "TOP-10 Players (GLOBAL)")
	
	return PLUGIN_HANDLED;
}

public CmdTopExpOnline(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	static Sort[33][2]
	new players[32], num, count, index
	get_players(players, num)
	
	for(new i = 0; i < num; i++)
	{
		index = players[i]
		Sort[count][0] = index
		Sort[count][1] = gData[index][Data_Exp]
		count++
	}
	
	SortCustom2D(Sort, count, "CompareEXP")
	
	new y = clamp(count, 0, 10)
	new kindex, szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd2)
	
	for(new x = 0; x < y; x++)
	{
		kindex = Sort[x][0]
		new iSec, szTimeFormat[32], szName[32]
		iSec = get_user_time(kindex)+gData[kindex][Data_PlayTime]
		GetTimeFormat(iSec, szTimeFormat, 31)
		get_user_name(kindex, szName, 31)
		replace_all(szName, 31, "#", " ")
		replace_all(szName, 31, "<", "&lt")
		replace_all(szName, 31, ">", "&gt")
		
		len += formatex(szMotd2[len], charsmax(szMotd2)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%s</td>", (x+1), szName, gData[kindex][Data_Exp], gData[kindex][Data_Kills], gData[kindex][Data_Deaths], szTimeFormat)
	}
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(id, szMotd2, "TOP Players (Now Online)")
	
	return PLUGIN_HANDLED;
}

public CompareEXP(elem1[], elem2[])
{
	if(elem1[1] > elem2[1]) return -1;
	else if(elem1[1] < elem2[1]) return 1;
	
	return 0;
}

public OnDeathMsg()
{
	new atk, vic, hs, szWpn[4]
	atk = read_data(1)
	vic = read_data(2)
	hs = read_data(3)
	read_data(4, szWpn, 3)
	
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		
		if(hs)
		{
			gData[atk][Data_HeadShot]++
			gData[atk][Data_Exp] += iExpHeadShot
		}
		if(zp_get_user_nemesis(vic))
		{
			gData[atk][Data_NemKills]++
			gData[atk][Data_Exp] += iExpNemKill
		}
		else if(zp_get_user_survivor(vic))
		{
			gData[atk][Data_SurKills]++
			gData[atk][Data_Exp] += iExpSurKill
		}
		
		if(szWpn[0]=='k' && szWpn[1]=='n')
		{
			gData[atk][Data_Knife]++
			gData[atk][Data_Exp] += iExpKnife
			CheckPlayerLevel(atk)
			return;
		}
		
		if(szWpn[0]=='g' && szWpn[1]=='r')
		{
			gData[atk][Data_Nade]++
			gData[atk][Data_Exp] += iExpGrenade
			CheckPlayerLevel(atk)
			return;
		}
		
		CheckPlayerLevel(atk)
	}
}

public zp_user_infected_post(vic, atk)
{
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		CheckPlayerLevel(atk)
	}
}

public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "        SPECTATING^n%s ^n[ Country: %s ]^n[ HP: %.0f | Ammo: %d ]^n[ %s: %d/%d ]", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), zp_get_user_ammo_packs(iSpec),szRanks[gData[iSpec][Data_Level]], gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1]) //entity_get_float(iSpec, EV_FL_armorvalue)
		return;
	}
	new iRank
	iRank = SortPlayerRank(id)
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "[ %s: %d/%d ]^n[ Rank: %d of %d ]^n              Alive ^n[ Humans:%d|%d:Zombies ]",szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], iRank, iTotalEntries, zp_get_human_count(), zp_get_zombie_count() )
}
/*
public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "SPECTATING: %s | COUNTRY: %s^nHP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), entity_get_float(iSpec, EV_FL_armorvalue), zp_get_user_ammo_packs(iSpec), gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1], szRanks[gData[iSpec][Data_Level]])
		return;
	}
	
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "HP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s^nCOUNTRY: %s", entity_get_float(id, EV_FL_health), entity_get_float(id, EV_FL_armorvalue), zp_get_user_ammo_packs(id), gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], szRanks[gData[id][Data_Level]], gData[id][Data_Country])
}*/

public _get_user_exp(id)
{
	return gData[id][Data_Exp];
}

public _set_user_exp(id, amount)
{
	gData[id][Data_Exp] = amount
}

public _get_user_playtime(id)
{
	return gData[id][Data_PlayTime];
}

public _set_user_playtime(id, amount)
{
	gData[id][Data_PlayTime] = amount
}

public _get_user_level(id)
{
	return gData[id][Data_Level];
}

public _set_user_level(id, amount)
{
	gData[id][Data_Level] = amount
}

public _get_user_deaths(id)
{
	return gData[id][Data_Deaths];
}

public _set_user_deaths(id, amount)
{
	gData[id][Data_Deaths] = amount
}

public _get_user_frags(id)
{
	return gData[id][Data_Kills];
}

public _set_user_frags(id, amount)
{
	gData[id][Data_Kills] = amount
}

public _get_user_headshot(id)
{
	return gData[id][Data_HeadShot];
}

public _set_user_headshot(id, amount)
{
	gData[id][Data_HeadShot] = amount
}

public _get_user_knife(id)
{
	return gData[id][Data_Knife];
}

public _set_user_knife(id, amount)
{
	gData[id][Data_Knife] = amount
}

public _get_user_nade(id)
{
	return gData[id][Data_Nade];
}

public _set_user_nade(id, amount)
{
	gData[id][Data_Nade] = amount
}

public _get_user_nemesis(id)
{
	return gData[id][Data_NemKills];
}

public _set_user_nemesis(id, amount)
{
	gData[id][Data_NemKills] = amount
}

public _get_user_survivor(id)
{
	return gData[id][Data_SurKills];
}

public _set_user_survivor(id, amount)
{
	gData[id][Data_SurKills] = amount
}

public _reset_user_data(id)
{
	gData[id][Data_Exp] = 0
	gData[id][Data_Kills] = 0
	gData[id][Data_Deaths] = 0
	gData[id][Data_HeadShot] = 0
	gData[id][Data_Knife] = 0
	gData[id][Data_Nade] = 0
	gData[id][Data_NemKills] = 0
	gData[id][Data_SurKills] = 0
	gData[id][Data_PlayTime] = 0
	gData[id][Data_Level] = 0
}

public _get_user_rank(id)
{
	return SortPlayerRank(id);
}

GetTimeFormat(seconds, szTime[], len)
{
	new days, hours, minutes
	days = seconds / 86400;
	hours = ( seconds / 3600 ) % 24;
	minutes = ( seconds / 60 ) % 60;
	seconds = seconds % 60;
	
	if(days)
	{
		formatex(szTime, len, "%dD %dH %dM %dS", days, hours, minutes, seconds)
		return;
	}
	
	if(hours)
	{
		formatex(szTime, len, "%dH %dM %dS", hours, minutes, seconds)
		return;
	}
	
	if(minutes)
	{
		formatex(szTime, len, "%dM %dS", minutes, seconds)
		return;
	}
	
	if(seconds)
	{
		formatex(szTime, len, "%dS", seconds)
	}
}

GetPlayerStats(id, caller)
{
	new szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background: url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left;  }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#e6e6e6;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=30%>Statistics</td>\
	<td id=h>Ammount</td></tr>")
	
	len = strlen(szMotd2)

	new iSec, szTimeFormat[32], iRank, iPacks, szName[32]
	iSec = get_user_time(id)+gData[id][Data_PlayTime]
	GetTimeFormat(iSec, szTimeFormat, 31)
	iRank = SortPlayerRank(id)
	iPacks = zp_get_user_ammo_packs(id)
	get_user_name(id, szName, 31)
	replace_all(szName, 31, "#", " ")
	replace_all(szName, 31, "<", "&lt")
	replace_all(szName, 31, ">", "&gt")
	
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nickname</td><td>%s</td>", szName)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>SteamID</td><td>%s</td>", gData[id][Data_Steamid])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Country</td><td>%s</td>", gData[id][Data_Country])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Rank</td><td>%d of %d</td>", iRank, iTotalEntries)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Ammo</td><td>%d</td>", iPacks)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Points</td><td>%d</td>", gData[id][Data_Exp])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Stage</td><td>%s</td>", szRanks[gData[id][Data_Level]])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Kills</td><td>%d</td>", gData[id][Data_Kills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Deaths</td><td>%d</td>", gData[id][Data_Deaths])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Headshot kills</td><td>%d</td>", gData[id][Data_HeadShot])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Knife kills</td><td>%d</td>", gData[id][Data_Knife])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Grenade kills</td><td>%d</td>", gData[id][Data_Nade])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nemesis kills</td><td>%d</td>", gData[id][Data_NemKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Survivor kills</td><td>%d</td>", gData[id][Data_SurKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Online time</td><td>%s</td>", szTimeFormat)
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(caller, szMotd2, "Player Statistics")
}

public CheckPlayerLevel(id)
{
	while((gData[id][Data_Exp] >= iEXP[gData[id][Data_Level]+1]))
	{
		gData[id][Data_Level]++
		UTIL_ColorChat(id, "^x04%s^x01 has been promoted to the Stage of^x04 %s^x01 with^x04 %d^x01 Points.", gData[id][Data_Name], szRanks[gData[id][Data_Level]], gData[id][Data_Exp])
		ExecuteForward(gForward[Forward_Levelup], gForward[Forward_Result], id, gData[id][Data_Level], gData[id][Data_Exp])
	}
}


public Load_Data(szName[], id)
{
	if(!is_user_connected(id))
		return

	new szName[32], szKey[50], szData[164]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", szName)
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Ip])	

	if (nvault_get(iVaultHandle, szName, szData, charsmax(szData)))
	{
		replace_all(szData, charsmax(szData), "#", " ")
	
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8]
		parse(szData, szExp, charsmax(szExp), szKills, charsmax(szKills), szDeaths, charsmax(szDeaths), szHeadShot, charsmax(szHeadShot), szKnife, charsmax(szKnife),
			szNade, charsmax(szNade), szNemKill, charsmax(szNemKill), szSurKill, charsmax(szSurKill), szPlayTime, charsmax(szPlayTime), szLevel, charsmax(szLevel))

		gData[id][Data_Exp] = str_to_num(szExp)
		gData[id][Data_Kills] = str_to_num(szKills)
		gData[id][Data_Deaths] = str_to_num(szDeaths)
		gData[id][Data_HeadShot] = str_to_num(szHeadShot)
		gData[id][Data_Knife] = str_to_num(szKnife)
		gData[id][Data_Nade] = str_to_num(szNade)
		gData[id][Data_NemKills] = str_to_num(szNemKill)
		gData[id][Data_SurKills] = str_to_num(szSurKill)
		gData[id][Data_PlayTime] = str_to_num(szPlayTime)
		gData[id][Data_Level] = str_to_num(szLevel)
	}
	else
	{
		_reset_user_data(id)
	}
	gData[id][Data_Connected] = true
}

public Save_Data(id, szName[])
{
	new szKey[50], szData[MAX_FMT_LENGTH]
	replace_all(gData[id][Data_Name], 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	formatex(szData, charsmax(szData), "%d %d %d %d %d %d %d %d %d %d %s", gData[id][Data_Exp], gData[id][Data_Kills], gData[id][Data_Deaths], gData[id][Data_HeadShot], gData[id][Data_Knife], gData[id][Data_Nade], gData[id][Data_NemKills], gData[id][Data_SurKills], gData[id][Data_PlayTime], gData[id][Data_Level], gData[id][Data_Name])
	nvault_set(iVaultHandle, szName, szData)
}

FormatGlobalTopTen()
{
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	const MAX_ENTRIES = 10
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < MAX_ENTRIES)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < MAX_ENTRIES)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)

	new len
	szMotd[0] = 0
	
	add(szMotd, charsmax(szMotd),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd, charsmax(szMotd),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd)
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		//data[VD_Key][20] = 0
		
		new szDataNew[164]
		nvault_get(iVaultHandle, data[VD_Key], szDataNew, charsmax(szDataNew))
		
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8], szName3[32]
		parse(szDataNew, szExp, 7, szKills, 7, szDeaths, 7, szHeadShot, 7, szKnife, 7, szNade, 7, szNemKill, 7, szSurKill, 7, szPlayTime, 7, szLevel, 7, szName3, 31)
		
		new iSec, szOnline[32]
		iSec = str_to_num(szPlayTime)
		GetTimeFormat(iSec, szOnline, 31)
		replace_all(szName3, 31, "#", " ")
		replace_all(szName3, 31, "<", "&lt")
		replace_all(szName3, 31, ">", "&gt")
		
		len += formatex(szMotd[len], charsmax(szMotd)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>", (i+1), szName3, szExp, szKills, szDeaths, szOnline)
	}
	
	add(szMotd, charsmax(szMotd), "</table></body></html>")
	ArrayDestroy(entries)
}

SortPlayerRank(id)
{
	new szName[32], szKey[50]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", szName)
	
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < numEntries)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < numEntries)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)
	iTotalEntries = sizeEntries
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		if(equal(data[VD_Key],szKey))
		{
			gData[id][Data_Rank] = i+1
			break;
		}
	}
	
	ArrayDestroy(entries)
	return gData[id][Data_Rank];
}

UTIL_ColorChat(id, const szText[], any:...)
{
	new szBuffer[512]
	
	if(!id)
	{
		new iPlayers[32], iNum, y, id2
		get_players(iPlayers, iNum, "ch")
		for(y=0;y<iNum;y++)
		{
			id2 = iPlayers[y]
			if(!is_user_connected(id2)) continue;
			
			vformat(szBuffer, charsmax(szBuffer), szText, 3)
			message_begin(MSG_ONE_UNRELIABLE, iMsgSayText, _, id2)
			write_byte(id2)
			write_string(szBuffer)
			message_end()
		}
	}
	else
	{
		vformat(szBuffer, charsmax(szBuffer), szText, 3)
		message_begin(MSG_ONE, iMsgSayText, _, id)
		write_byte(id)
		write_string(szBuffer)
		message_end()
	}
}

stock client_cmd_ex(id, const command[], any:...)
{
	#pragma unused command
	
	if (id == 0 || is_user_connected(id))
	{
		new szMessage[256]
		
		format_args(szMessage, charsmax(szMessage), 1)
		
		message_begin(id == 0 ? MSG_ALL : MSG_ONE, 51, _, id)
		write_byte(strlen(szMessage) + 2)
		write_byte(10)
		write_string(szMessage)
		message_end()
	}
}
Последна промяна от LayerFort DJBosma на 24 фев 2019, 14:54, променено общо 1 път.
Пиша от избата, защото горе имаме течове..

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Премахване на проверка за парола

Мнение от LayerFort DJBosma » 15 фев 2019, 23:10

Здравейте, оправих се с повечето неща.

Само където сега като напишеш /rank показва 0 от 2, (0/2) вместо (1/2) но в топ15 го показва правилно.

Другото което е OnPlayerPreThink, не показва.

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault_util>
#include <fakemeta>
#include <engine>
#include <geoip>
#include <zombieplague>

new const szRanks[][] = 
{
    "Guardsman",
    "Healer",
    "Protector",
    "Warrior",
    "High Warrior",
    "Alpha Warrior",
    "Archwarrior",
    "High Archwarrior",
    "Alpha Archwarrior",
    "Destroyer",
    "High Destroyer",
    "Alpha Destroyer",
    "Commander",
    "High Commander",
    "Alpha Commander",
    "Baron",
    "High Baron",
    "Alpha Baron",
    "King",
    "Alpha King",
    "Overlord",
    "Hacker"
}

new const iEXP[] = 
{
    0,
    50,
    100,
    200,
    250,
    300,
    350,
    400,
    450,
    500,
    600,
    700,
    700,
    800,
    900,
    1100,
    1250,
    1500,
    2000,
    2500,
    3000,
    999999999
}

enum _:Player_Data
{
	Data_Steamid[35],
	//Data_Ip[16],
	Data_Name[32],
	Data_Exp,
	Data_Kills,
	Data_Deaths,
	Data_HeadShot,
	Data_Knife,
	Data_Nade,
	Data_NemKills,
	Data_SurKills,
	Data_PlayTime,
	Data_Level,
	Data_Country[46],
	Data_Rank,
	Data_Connected,
	MAX_PLAYER_DATA
}

enum _:Forward_Data
{
	Forward_Levelup,
	Forward_Exp_Add,
	Forward_Exp_Set,
	Forward_Result,
	MAX_FORWARD_DATA
}

new iVaultHandle, gData[33][MAX_PLAYER_DATA], iHudStats, Float:fLastHud[33], szMotd[1536], gForward[MAX_FORWARD_DATA], Float:fLastCmd, iTotalEntries, iMsgSayText
const iExpKill = 1
const iExpHeadShot = 3
const iExpKnife = 4
const iExpGrenade = 4
const iExpNemKill = 5
const iExpSurKill = 5
const Float:HUD_STATS_X = 0.77//-1.0
const Float:HUD_STATS_Y = 0.6//0.8
new const szVaultName[] = "vault201915feb-5"

#define is_user_valid(%0) (0<%0<33)
new cvar_ammopacks
//new g_maxplayers

new Ammopacks[22] = {
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    21,
    0
}

//Uncomment this to update motd.txt on map loaded to show global top-10 players.
#define UPDATE_MOTD

//Uncomment this to enable nvault prune.
#define PRUNE_DATABASE


#if defined UPDATE_MOTD
new const szFileMotd[] = "motd.txt"
#endif

#if defined PRUNE_DATABASE
const iExpiredDays = 30
#endif

public plugin_natives()
{
	register_native("xp_get_user_exp","_get_user_exp",1)
	register_native("xp_set_user_exp","_set_user_exp",1)
	
	register_native("xp_get_user_playtime","_get_user_playtime",1)
	register_native("xp_set_user_playtime","_set_user_playtime",1)
	
	register_native("xp_get_user_level","_get_user_level",1)
	register_native("xp_set_user_level","_set_user_level",1)
	
	register_native("xp_get_user_deaths","_get_user_deaths",1)
	register_native("xp_set_user_deaths","_set_user_deaths",1)
	
	register_native("xp_get_user_frags","_get_user_frags",1)
	register_native("xp_set_user_frags","_set_user_frags",1)
	
	register_native("xp_get_user_headshot","_get_user_headshot",1)
	register_native("xp_set_user_headshot","_set_user_headshot",1)
	
	register_native("xp_get_user_knife","_get_user_knife",1)
	register_native("xp_set_user_knife","_set_user_knife",1)
	
	register_native("xp_get_user_nade","_get_user_nade",1)
	register_native("xp_set_user_nade","_set_user_nade",1)
	
	register_native("xp_get_user_nemesis","_get_user_nemesis",1)
	register_native("xp_set_user_nemesis","_set_user_nemesis",1)
	
	register_native("xp_get_user_survivor","_get_user_survivor",1)
	register_native("xp_set_user_survivor","_set_user_survivor",1)
	
	register_native("xp_reset_user_data","_reset_user_data",1)
	register_native("xp_get_user_rank","_get_user_rank",1)
	register_native("xp_check_user_level","CheckPlayerLevel",1)
}

public plugin_init()
{
	new const PLUGIN_VERSION[] = "1.0"//0.0.5
	new const CVAR_EXP_VERSION[] = "n4d_zpstats"
	register_plugin("[ZP] UserVault", PLUGIN_VERSION, "wbyokomo, huehue, djbosma")
	
	iHudStats = CreateHudSyncObj()
	iMsgSayText = get_user_msgid("SayText")
	
	//register_event("HLTV", "event_newround", "a", "1=0", "2=0")
	register_event("DeathMsg", "OnDeathMsg", "a") //use deathmsg easy to trace weapon and hitplace
	register_event_ex("30", "Event_Intermission", RegisterEvent_Global)
	
	register_clcmd("say /stats" , "CmdStats")
	register_clcmd("say /rank", "CmdShowRank")
	register_clcmd("say /top15", "CmdTopExpGlobal")
	register_clcmd("say /top10", "CmdTopExpGlobal")
	register_clcmd("say /toponline", "CmdTopExpOnline")
	
	register_clcmd("say_team /stats" , "CmdStats")
	register_clcmd("say_team /rank", "CmdShowRank")
	register_clcmd("say_team /top15", "CmdTopExpGlobal")
	register_clcmd("say_team /top10", "CmdTopExpGlobal")
	register_clcmd("say_team /toponline", "CmdTopExpOnline")
	
	cvar_ammopacks = register_cvar("xp_ammopacks_reward", "1")
	//g_maxplayers = get_maxplayers()
	

	gForward[Forward_Levelup] = CreateMultiForward("xp_user_levelup", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL) //xp_user_levelup(player, level, exp)
	gForward[Forward_Exp_Add] = CreateMultiForward("xp_user_expadd", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expadd(player, expadd)
	gForward[Forward_Exp_Set] = CreateMultiForward("xp_user_expset", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expset(player, exptotal)
	
	register_cvar(CVAR_EXP_VERSION, PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	set_cvar_string(CVAR_EXP_VERSION, PLUGIN_VERSION)
}

/*
public event_newround()
{
	new id;
	for(id = 1; id<= g_maxplayers; id++)
		if(is_user_valid(id) && is_user_alive(id) && is_user_connected(id) && !zp_get_user_zombie(id)
		&& !zp_get_user_nemesis(id) && !zp_get_user_survivor(id))
			reward_user(id, 1)
}
*/

public Event_Intermission()
{
	set_task_ex(0.1, "Delayed_Intermission")
}
public Delayed_Intermission()
{
	new iPlayers[MAX_PLAYERS], iNum, id
	get_players_ex(iPlayers, iNum, GetPlayers_ExcludeHLTV|GetPlayers_ExcludeBots)

	for (--iNum; iNum >= 0; iNum--)
	{
		id = iPlayers[iNum]

		if (!is_user_connected(id))
			return

		reward_with_ammopacks(id)
	}
}
public fw_spawn_post(id)
{
	if(zp_get_user_zombie(id) || zp_get_user_survivor(id) || zp_get_user_nemesis(id)
	|| !is_user_alive(id) || !is_user_connected(id) || !is_user_valid(id)) {return;}
	else
		reward_user(id, 0)
}

public zp_user_humanized_post(id)
	fw_spawn_post(id)

reward_user(id, roundstart)
{
	if(get_pcvar_num(cvar_ammopacks) == 1 && roundstart == 1){ reward_with_ammopacks(id);}
}

reward_with_ammopacks(id)
{
	new ap = Ammopacks[gData[id][Data_Level]]
	zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ap)
	//client_print(id, print_chat, "You received %d ammmopacks from the server", ap)
	UTIL_ColorChat(id, "^x04[User Vault]^x01 You received:^x04 %d^x01 ammmopacks from the server", ap)
}

public plugin_cfg()
{
	iVaultHandle = nvault_open(szVaultName)
	
	if(iVaultHandle == INVALID_HANDLE)
	{
		new szText[128]; formatex(szText, 127, "[UserVault] Error opening nVault file [%s]", szVaultName);
		set_fail_state(szText)
	}
	else
	{
		server_print("[UserVault] Database [%s] successfully loaded...", szVaultName)
		
		#if defined PRUNE_DATABASE
		nvault_prune(iVaultHandle, 0, get_systime() - (86400 * iExpiredDays))
		#endif
		
		FormatGlobalTopTen()
		
		#if defined UPDATE_MOTD
		if(file_exists(szFileMotd))
		{
			if(delete_file(szFileMotd))
			{
				if(write_file(szFileMotd, szMotd, -1)) server_print("[UserVault] File [%s] has been updated...", szFileMotd);
			}
		}
		#endif
	}
}

public plugin_end()
{
	nvault_close(iVaultHandle)
}

public client_putinserver(id)
{

	if (is_user_hltv(id))
		return;

	arrayset(gData[id], 0, sizeof(gData[]))
	
	get_user_name(id, gData[id][Data_Name], charsmax(gData[][Data_Name]))
	get_user_authid(id, gData[id][Data_Steamid], charsmax(gData[][Data_Steamid]))
	//get_user_ip(id, gData[id][Data_Ip], charsmax(gData[][Data_Ip]))
	set_task(0.1, "Load_Data", id, gData[id][Data_Name], sizeof(gData[][Data_Name]))
}

public client_disconnected(id)
{
	if (gData[id][Data_Connected])
	{
		gData[id][Data_PlayTime] += get_user_time(id)
		Save_Data(id, gData[id][Data_Name])
		gData[id][Data_Connected] = false
	}
}

public client_infochanged(id)
{
	if (!is_user_connected(id))
		return PLUGIN_HANDLED
	
	static szNames[2][32]
	get_user_name(id, szNames[0], charsmax(szNames[]))
	get_user_info(id, "name", szNames[1], charsmax(szNames[]))

	if (!equali(szNames[1], szNames[0]))
	{
		Save_Data(id, szNames[0])
		set_task(0.1, "Load_Data", id, szNames[1], sizeof(szNames[]))
		gData[id][Data_Name] = szNames[1]
		return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public CmdStats(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	new menu = menu_create("\yPlayer Stats:", "PlayerStatsMenuHandler")
	new szUserId[32], iPlayers[32], iNum, j, id2, szName[32]
	get_players(iPlayers, iNum, "h")
	for(j=0;j<iNum;j++)
	{
		id2 = iPlayers[j]
		get_user_name(id2, szName, 31)
		formatex(szUserId, 31, "%d", get_user_userid(id2))
		menu_additem(menu, szName, szUserId, 0)
	}
	
	menu_display(id, menu, 0)
	
	return PLUGIN_HANDLED;
}

public PlayerStatsMenuHandler(id, menu, item)
{
	if(!is_user_connected(id))
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	new szData[6], szName[64]
	new _access, item_callback
	menu_item_getinfo(menu, item, _access, szData, 5, szName, 63, item_callback)
	
	new userid = str_to_num(szData)
	new player = find_player("k", userid)
	
	if(player && is_user_connected(player))
	{
		GetPlayerStats(player, id)
	}
	
	menu_destroy(menu)
	return PLUGIN_HANDLED;
}

public CmdShowRank(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	new iRank = SortPlayerRank(id)
	if(iRank == -1) UTIL_ColorChat(id, "^x04[UserVault]^x01 Your rank is not been saved yet, please rejoin the server.") //client_print(id, print_chat, "Your rank is not been saved yet, please rejoin the server.");
	else UTIL_ColorChat(id, "^x04%s^x01 rank is^x04 %d^x01/^x04%d^x01 -- Kills:^x04 %d^x01 Deaths:^x04 %d^x01 Stage:^x04 %d^x01 Points:^x04 %d^x01/^x04%d", gData[id][Data_Name], iRank, iTotalEntries, gData[id][Data_Kills], gData[id][Data_Deaths], szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1])
	
	return PLUGIN_HANDLED;
}

public CmdTopExpGlobal(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	show_motd(id, szMotd, "TOP-10 Players (GLOBAL)")
	
	return PLUGIN_HANDLED;
}

public CmdTopExpOnline(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	static Sort[33][2]
	new players[32], num, count, index
	get_players(players, num)
	
	for(new i = 0; i < num; i++)
	{
		index = players[i]
		Sort[count][0] = index
		Sort[count][1] = gData[index][Data_Exp]
		count++
	}
	
	SortCustom2D(Sort, count, "CompareEXP")
	
	new y = clamp(count, 0, 10)
	new kindex, szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd2)
	
	for(new x = 0; x < y; x++)
	{
		kindex = Sort[x][0]
		new iSec, szTimeFormat[32], szName[32]
		iSec = get_user_time(kindex)+gData[kindex][Data_PlayTime]
		GetTimeFormat(iSec, szTimeFormat, 31)
		get_user_name(kindex, szName, 31)
		replace_all(szName, 31, "#", " ")
		replace_all(szName, 31, "<", "&lt")
		replace_all(szName, 31, ">", "&gt")
		
		len += formatex(szMotd2[len], charsmax(szMotd2)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%s</td>", (x+1), szName, gData[kindex][Data_Exp], gData[kindex][Data_Kills], gData[kindex][Data_Deaths], szTimeFormat)
	}
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(id, szMotd2, "TOP Players (Now Online)")
	
	return PLUGIN_HANDLED;
}

public CompareEXP(elem1[], elem2[])
{
	if(elem1[1] > elem2[1]) return -1;
	else if(elem1[1] < elem2[1]) return 1;
	
	return 0;
}

public OnDeathMsg()
{
	new atk, vic, hs, szWpn[4]
	atk = read_data(1)
	vic = read_data(2)
	hs = read_data(3)
	read_data(4, szWpn, 3)
	
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		
		if(hs)
		{
			gData[atk][Data_HeadShot]++
			gData[atk][Data_Exp] += iExpHeadShot
		}
		if(zp_get_user_nemesis(vic))
		{
			gData[atk][Data_NemKills]++
			gData[atk][Data_Exp] += iExpNemKill
		}
		else if(zp_get_user_survivor(vic))
		{
			gData[atk][Data_SurKills]++
			gData[atk][Data_Exp] += iExpSurKill
		}
		
		if(szWpn[0]=='k' && szWpn[1]=='n')
		{
			gData[atk][Data_Knife]++
			gData[atk][Data_Exp] += iExpKnife
			CheckPlayerLevel(atk)
			return;
		}
		
		if(szWpn[0]=='g' && szWpn[1]=='r')
		{
			gData[atk][Data_Nade]++
			gData[atk][Data_Exp] += iExpGrenade
			CheckPlayerLevel(atk)
			return;
		}
		
		CheckPlayerLevel(atk)
	}
}

public zp_user_infected_post(vic, atk)
{
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		CheckPlayerLevel(atk)
	}
}

/*public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "        SPECTATING^n%s ^n[ Country: %s ]^n[ HP: %.0f | Ammo: %d ]^n[ %s: %d/%d ]", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), zp_get_user_ammo_packs(iSpec),szRanks[gData[iSpec][Data_Level]], gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1]) //entity_get_float(iSpec, EV_FL_armorvalue)
		return;
	}
	new iRank
	iRank = SortPlayerRank(id)
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "[ %s: %d/%d ]^n[ Rank: %d of %d ]^n              Alive ^n[ Humans:%d|%d:Zombies ]",szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], iRank, iTotalEntries, zp_get_human_count(), zp_get_zombie_count() )
}
*/

public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "SPECTATING: %s | COUNTRY: %s^nHP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), entity_get_float(iSpec, EV_FL_armorvalue), zp_get_user_ammo_packs(iSpec), gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1], szRanks[gData[iSpec][Data_Level]])
		return;
	}
	
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "HP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s^nCOUNTRY: %s", entity_get_float(id, EV_FL_health), entity_get_float(id, EV_FL_armorvalue), zp_get_user_ammo_packs(id), gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], szRanks[gData[id][Data_Level]], gData[id][Data_Country])
}

public _get_user_exp(id)
{
	return gData[id][Data_Exp];
}

public _set_user_exp(id, amount)
{
	gData[id][Data_Exp] = amount
}

public _get_user_playtime(id)
{
	return gData[id][Data_PlayTime];
}

public _set_user_playtime(id, amount)
{
	gData[id][Data_PlayTime] = amount
}

public _get_user_level(id)
{
	return gData[id][Data_Level];
}

public _set_user_level(id, amount)
{
	gData[id][Data_Level] = amount
}

public _get_user_deaths(id)
{
	return gData[id][Data_Deaths];
}

public _set_user_deaths(id, amount)
{
	gData[id][Data_Deaths] = amount
}

public _get_user_frags(id)
{
	return gData[id][Data_Kills];
}

public _set_user_frags(id, amount)
{
	gData[id][Data_Kills] = amount
}

public _get_user_headshot(id)
{
	return gData[id][Data_HeadShot];
}

public _set_user_headshot(id, amount)
{
	gData[id][Data_HeadShot] = amount
}

public _get_user_knife(id)
{
	return gData[id][Data_Knife];
}

public _set_user_knife(id, amount)
{
	gData[id][Data_Knife] = amount
}

public _get_user_nade(id)
{
	return gData[id][Data_Nade];
}

public _set_user_nade(id, amount)
{
	gData[id][Data_Nade] = amount
}

public _get_user_nemesis(id)
{
	return gData[id][Data_NemKills];
}

public _set_user_nemesis(id, amount)
{
	gData[id][Data_NemKills] = amount
}

public _get_user_survivor(id)
{
	return gData[id][Data_SurKills];
}

public _set_user_survivor(id, amount)
{
	gData[id][Data_SurKills] = amount
}

public _reset_user_data(id)
{
	gData[id][Data_Exp] = 0
	gData[id][Data_Kills] = 0
	gData[id][Data_Deaths] = 0
	gData[id][Data_HeadShot] = 0
	gData[id][Data_Knife] = 0
	gData[id][Data_Nade] = 0
	gData[id][Data_NemKills] = 0
	gData[id][Data_SurKills] = 0
	gData[id][Data_PlayTime] = 0
	gData[id][Data_Level] = 0
}

public _get_user_rank(id)
{
	return SortPlayerRank(id);
}

GetTimeFormat(seconds, szTime[], len)
{
	new days, hours, minutes
	days = seconds / 86400;
	hours = ( seconds / 3600 ) % 24;
	minutes = ( seconds / 60 ) % 60;
	seconds = seconds % 60;
	
	if(days)
	{
		formatex(szTime, len, "%dD %dH %dM %dS", days, hours, minutes, seconds)
		return;
	}
	
	if(hours)
	{
		formatex(szTime, len, "%dH %dM %dS", hours, minutes, seconds)
		return;
	}
	
	if(minutes)
	{
		formatex(szTime, len, "%dM %dS", minutes, seconds)
		return;
	}
	
	if(seconds)
	{
		formatex(szTime, len, "%dS", seconds)
	}
}

GetPlayerStats(id, caller)
{
	new szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background: url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left;  }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#e6e6e6;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=30%>Statistics</td>\
	<td id=h>Ammount</td></tr>")
	
	len = strlen(szMotd2)

	new iSec, szTimeFormat[32], iRank, iPacks, szName[32]
	iSec = get_user_time(id)+gData[id][Data_PlayTime]
	GetTimeFormat(iSec, szTimeFormat, 31)
	iRank = SortPlayerRank(id)
	iPacks = zp_get_user_ammo_packs(id)
	get_user_name(id, szName, 31)
	replace_all(szName, 31, "#", " ")
	replace_all(szName, 31, "<", "&lt")
	replace_all(szName, 31, ">", "&gt")
	
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nickname</td><td>%s</td>", szName)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>SteamID</td><td>%s</td>", gData[id][Data_Steamid])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Country</td><td>%s</td>", gData[id][Data_Country])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Rank</td><td>%d of %d</td>", iRank, iTotalEntries)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Ammo</td><td>%d</td>", iPacks)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Points</td><td>%d</td>", gData[id][Data_Exp])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Stage</td><td>%s</td>", szRanks[gData[id][Data_Level]])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Kills</td><td>%d</td>", gData[id][Data_Kills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Deaths</td><td>%d</td>", gData[id][Data_Deaths])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Headshot kills</td><td>%d</td>", gData[id][Data_HeadShot])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Knife kills</td><td>%d</td>", gData[id][Data_Knife])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Grenade kills</td><td>%d</td>", gData[id][Data_Nade])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nemesis kills</td><td>%d</td>", gData[id][Data_NemKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Survivor kills</td><td>%d</td>", gData[id][Data_SurKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Online time</td><td>%s</td>", szTimeFormat)
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(caller, szMotd2, "Player Statistics")
}

public CheckPlayerLevel(id)
{
	while((gData[id][Data_Exp] >= iEXP[gData[id][Data_Level]+1]))
	{
		gData[id][Data_Level]++
		UTIL_ColorChat(id, "^x04%s^x01 has been promoted to the Stage of^x04 %s^x01 with^x04 %d^x01 Points.", gData[id][Data_Name], szRanks[gData[id][Data_Level]], gData[id][Data_Exp])
		ExecuteForward(gForward[Forward_Levelup], gForward[Forward_Result], id, gData[id][Data_Level], gData[id][Data_Exp])
	}
}


public Load_Data(szName[], id)
{
	if(!is_user_connected(id))
		return
	
	new szName[32], szKey[50], szData[164]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, " ", "#")
	formatex(szKey, 49, "%s#EXP", szName)
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Ip])
	

	if (nvault_get(iVaultHandle, szName, szData, charsmax(szData)))
	{
		//replace_all(szData, charsmax(szData), "#", " ")
	
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8]
		parse(szData, szExp, charsmax(szExp), szKills, charsmax(szKills), szDeaths, charsmax(szDeaths), szHeadShot, charsmax(szHeadShot), szKnife, charsmax(szKnife),
			szNade, charsmax(szNade), szNemKill, charsmax(szNemKill), szSurKill, charsmax(szSurKill), szPlayTime, charsmax(szPlayTime), szLevel, charsmax(szLevel))

		gData[id][Data_Exp] = str_to_num(szExp)
		gData[id][Data_Kills] = str_to_num(szKills)
		gData[id][Data_Deaths] = str_to_num(szDeaths)
		gData[id][Data_HeadShot] = str_to_num(szHeadShot)
		gData[id][Data_Knife] = str_to_num(szKnife)
		gData[id][Data_Nade] = str_to_num(szNade)
		gData[id][Data_NemKills] = str_to_num(szNemKill)
		gData[id][Data_SurKills] = str_to_num(szSurKill)
		gData[id][Data_PlayTime] = str_to_num(szPlayTime)
		gData[id][Data_Level] = str_to_num(szLevel)
	}
	else
	{
		_reset_user_data(id)
	}
	gData[id][Data_Connected] = true
}

public Save_Data(id, szName[])
{
	new szData[MAX_FMT_LENGTH]
	formatex(szData, charsmax(szData), "%d %d %d %d %d %d %d %d %d %d %s", gData[id][Data_Exp], gData[id][Data_Kills], gData[id][Data_Deaths], gData[id][Data_HeadShot], gData[id][Data_Knife], gData[id][Data_Nade], gData[id][Data_NemKills], gData[id][Data_SurKills], gData[id][Data_PlayTime], gData[id][Data_Level], gData[id][Data_Name])
	nvault_set(iVaultHandle, szName, szData)
}

FormatGlobalTopTen()
{
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	const MAX_ENTRIES = 10
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < MAX_ENTRIES)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < MAX_ENTRIES)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)

	new len
	szMotd[0] = 0
	
	add(szMotd, charsmax(szMotd),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd, charsmax(szMotd),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd)
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		//data[VD_Key][20] = 0
		
		new szDataNew[164]
		nvault_get(iVaultHandle, data[VD_Key], szDataNew, charsmax(szDataNew))
		
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8], szName3[32]
		parse(szDataNew, szExp, 7, szKills, 7, szDeaths, 7, szHeadShot, 7, szKnife, 7, szNade, 7, szNemKill, 7, szSurKill, 7, szPlayTime, 7, szLevel, 7, szName3, 31)
		
		new iSec, szOnline[32]
		iSec = str_to_num(szPlayTime)
		GetTimeFormat(iSec, szOnline, 31)
		replace_all(szName3, 31, "#", " ")
		//replace_all(szName3, 31, " ", "#")
		replace_all(szName3, 31, "<", "&lt")
		replace_all(szName3, 31, ">", "&gt")
		
		len += formatex(szMotd[len], charsmax(szMotd)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>", (i+1), szName3, szExp, szKills, szDeaths, szOnline)
	}
	
	add(szMotd, charsmax(szMotd), "</table></body></html>")
	ArrayDestroy(entries)
}

SortPlayerRank(id)
{
	new szName[32], szKey[50]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", szName)
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Ip])
	
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < numEntries)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < numEntries)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)
	iTotalEntries = sizeEntries
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		if(equal(data[VD_Key],szKey))
		{
			gData[id][Data_Rank] = i+1
			break;
		}
	}
	
	ArrayDestroy(entries)
	return gData[id][Data_Rank];
}

UTIL_ColorChat(id, const szText[], any:...)
{
	new szBuffer[512]
	
	if(!id)
	{
		new iPlayers[32], iNum, y, id2
		get_players(iPlayers, iNum, "ch")
		for(y=0;y<iNum;y++)
		{
			id2 = iPlayers[y]
			if(!is_user_connected(id2)) continue;
			
			vformat(szBuffer, charsmax(szBuffer), szText, 3)
			message_begin(MSG_ONE_UNRELIABLE, iMsgSayText, _, id2)
			write_byte(id2)
			write_string(szBuffer)
			message_end()
		}
	}
	else
	{
		vformat(szBuffer, charsmax(szBuffer), szText, 3)
		message_begin(MSG_ONE, iMsgSayText, _, id)
		write_byte(id)
		write_string(szBuffer)
		message_end()
	}
}

stock client_cmd_ex(id, const command[], any:...)
{
	#pragma unused command
	
	if (id == 0 || is_user_connected(id))
	{
		new szMessage[256]
		
		format_args(szMessage, charsmax(szMessage), 1)
		
		message_begin(id == 0 ? MSG_ALL : MSG_ONE, 51, _, id)
		write_byte(strlen(szMessage) + 2)
		write_byte(10)
		write_string(szMessage)
		message_end()
	}
}
Пиша от избата, защото горе имаме течове..

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5097
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 58 пъти
Получена благодарност: 490 пъти
Години: 21
Контакти:

nVault; Премахване на проверка за парола

Мнение от OciXCrom TM » 16 фев 2019, 14:52

И в двата случая се ползва същата функция за да се вземе ранкът - SortPlayerRank(id). Не виждам логика да показва различна стойност на две места. В краен случай направи го в командата да бъде new iRank = SortPlayerRank(id) + 1 за да не започва от 0. Сигурен ли си, че си компилирал кода след последните промени, понеже такова нещо не ми звучи нормално?

Относно OnPlayerPreThink:

Код: Избери всички

static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
Според написаното, fLastHud[id] винаги е по-голямо от ctime, съответно условието fLastHud[id] > ctime винаги ще се изпълнява и ще връща return. Трябва да направиш fLastHud[id] = ctime, без + 1.0.

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Премахване на проверка за парола

Мнение от LayerFort DJBosma » 16 фев 2019, 16:17

Код: Избери всички

RegisterHam(Ham_Player_PreThink, "player", "OnPlayerPreThink")
Бях забравил

С добавените от теб предложени промени сега всеки в топа има ранк 1/X. Последно това съм променял, но без успех, навсякъде ранка е 0/X

Код: Избери всички

public client_putinserver(id)
{

	if (is_user_hltv(id))
		return;

	arrayset(gData[id], 0, sizeof(gData[]))
	
	get_user_name(id, gData[id][Data_Name], charsmax(gData[][Data_Name]))
	get_user_authid(id, gData[id][Data_Steamid], charsmax(gData[][Data_Steamid]))
	//get_user_ip(id, gData[id][Data_Ip], charsmax(gData[][Data_Ip]))
	set_task(0.1, "Load_Data", id, gData[id][Data_Name], sizeof(gData[][Data_Name]))
}

Код: Избери всички

public client_infochanged(id)
{
	if (!is_user_connected(id))
		return PLUGIN_HANDLED
	
	static szNames[2][32]
	get_user_name(id, szNames[0], charsmax(szNames[]))
	get_user_info(id, "name", szNames[1], charsmax(szNames[]))

	if (!equali(szNames[1], szNames[0]))
	{
		Save_Data(id, szNames[0])
		set_task(0.1, "Load_Data", id, szNames[1], sizeof(szNames[]))
		gData[id][Data_Name] = szNames[1]
		return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

Код: Избери всички

public Load_Data(szName[], id)
{
	if(!is_user_connected(id))
		return
	
	new szName[32], szKey[50], szData[164]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, " ", "#")
	formatex(szKey, 49, "%s#EXP", szName)
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Ip])	

	if (nvault_get(iVaultHandle, szName, szData, charsmax(szData)))
	{
		//replace_all(szData, charsmax(szData), "#", " ")
	
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8]
		parse(szData, szExp, charsmax(szExp), szKills, charsmax(szKills), szDeaths, charsmax(szDeaths), szHeadShot, charsmax(szHeadShot), szKnife, charsmax(szKnife),
			szNade, charsmax(szNade), szNemKill, charsmax(szNemKill), szSurKill, charsmax(szSurKill), szPlayTime, charsmax(szPlayTime), szLevel, charsmax(szLevel))

		gData[id][Data_Exp] = str_to_num(szExp)
		gData[id][Data_Kills] = str_to_num(szKills)
		gData[id][Data_Deaths] = str_to_num(szDeaths)
		gData[id][Data_HeadShot] = str_to_num(szHeadShot)
		gData[id][Data_Knife] = str_to_num(szKnife)
		gData[id][Data_Nade] = str_to_num(szNade)
		gData[id][Data_NemKills] = str_to_num(szNemKill)
		gData[id][Data_SurKills] = str_to_num(szSurKill)
		gData[id][Data_PlayTime] = str_to_num(szPlayTime)
		gData[id][Data_Level] = str_to_num(szLevel)
	}
	else
	{
		_reset_user_data(id)
	}
	gData[id][Data_Connected] = true
}

Код: Избери всички

public Save_Data(id, szName[])
{
	new szKey[50], szData[MAX_FMT_LENGTH]
	replace_all(gData[id][Data_Name], 31, " ", "#")
	formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	formatex(szData, charsmax(szData), "%d %d %d %d %d %d %d %d %d %d %s", gData[id][Data_Exp], gData[id][Data_Kills], gData[id][Data_Deaths], gData[id][Data_HeadShot], gData[id][Data_Knife], gData[id][Data_Nade], gData[id][Data_NemKills], gData[id][Data_SurKills], gData[id][Data_PlayTime], gData[id][Data_Level], gData[id][Data_Name])
	nvault_set(iVaultHandle, szName, szData)
}
Пиша от избата, защото горе имаме течове..

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Премахване на проверка за парола

Мнение от LayerFort DJBosma » 18 фев 2019, 17:48

*бут*

Пробвах

replace_all(szName, 31, " ", "#")
С
replace_all(szName, 31, "#", " ")

Безуспешно.

В топа ранка се показва правилно но все пак..
Пиша от избата, защото горе имаме течове..

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Премахване на проверка за парола

Мнение от LayerFort DJBosma » 20 фев 2019, 12:56

Ето и отново целия плъгин.

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault_util>
#include <fakemeta>
#include <engine>
#include <zombieplague>

new const szRanks[][] = 
{
    "Guardsman",
    "Healer",
    "Protector",
    "Warrior",
    "High Warrior",
    "Alpha Warrior",
    "Archwarrior",
    "High Archwarrior",
    "Alpha Archwarrior",
    "Destroyer",
    "High Destroyer",
    "Alpha Destroyer",
    "Commander",
    "High Commander",
    "Alpha Commander",
    "Baron",
    "High Baron",
    "Alpha Baron",
    "King",
    "Alpha King",
    "Overlord",
    "Hacker"
}

new const iEXP[] = 
{
    0,
    50,
    100,
    200,
    250,
    300,
    350,
    400,
    450,
    500,
    600,
    700,
    700,
    800,
    900,
    1100,
    1250,
    1500,
    2000,
    2500,
    3000,
    999999999
}

enum _:Player_Data
{
	Data_Steamid[35],
	//Data_Ip[16],
	Data_Name[32],
	Data_Exp,
	Data_Kills,
	Data_Deaths,
	Data_HeadShot,
	Data_Knife,
	Data_Nade,
	Data_NemKills,
	Data_SurKills,
	Data_PlayTime,
	Data_Level,
	Data_Country[46],
	Data_Rank,
	Data_Connected,
	MAX_PLAYER_DATA
}

enum _:Forward_Data
{
	Forward_Levelup,
	Forward_Exp_Add,
	Forward_Exp_Set,
	Forward_Result,
	MAX_FORWARD_DATA
}

new iVaultHandle, gData[33][MAX_PLAYER_DATA], iHudStats, Float:fLastHud[33], szMotd[1536], gForward[MAX_FORWARD_DATA], Float:fLastCmd, iTotalEntries, iMsgSayText
const iExpKill = 1
const iExpHeadShot = 3
const iExpKnife = 4
const iExpGrenade = 4
const iExpNemKill = 5
const iExpSurKill = 5
const Float:HUD_STATS_X = 0.77//-1.0
const Float:HUD_STATS_Y = 0.6//0.8
new const szVaultName[] = "fter-zpuservault"

#define is_user_valid(%0) (0<%0<33)
new cvar_ammopacks
//new g_maxplayers

new Ammopacks[22] = {
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    12,
    13,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    21,
    0
}

//Uncomment this to update motd.txt on map loaded to show global top-10 players.
#define UPDATE_MOTD

//Uncomment this to enable nvault prune.
#define PRUNE_DATABASE


#if defined UPDATE_MOTD
new const szFileMotd[] = "motd.txt"
#endif

#if defined PRUNE_DATABASE
const iExpiredDays = 30
#endif

public plugin_natives()
{
	register_native("xp_get_user_exp","_get_user_exp",1)
	register_native("xp_set_user_exp","_set_user_exp",1)
	
	register_native("xp_get_user_playtime","_get_user_playtime",1)
	register_native("xp_set_user_playtime","_set_user_playtime",1)
	
	register_native("xp_get_user_level","_get_user_level",1)
	register_native("xp_set_user_level","_set_user_level",1)
	
	register_native("xp_get_user_deaths","_get_user_deaths",1)
	register_native("xp_set_user_deaths","_set_user_deaths",1)
	
	register_native("xp_get_user_frags","_get_user_frags",1)
	register_native("xp_set_user_frags","_set_user_frags",1)
	
	register_native("xp_get_user_headshot","_get_user_headshot",1)
	register_native("xp_set_user_headshot","_set_user_headshot",1)
	
	register_native("xp_get_user_knife","_get_user_knife",1)
	register_native("xp_set_user_knife","_set_user_knife",1)
	
	register_native("xp_get_user_nade","_get_user_nade",1)
	register_native("xp_set_user_nade","_set_user_nade",1)
	
	register_native("xp_get_user_nemesis","_get_user_nemesis",1)
	register_native("xp_set_user_nemesis","_set_user_nemesis",1)
	
	register_native("xp_get_user_survivor","_get_user_survivor",1)
	register_native("xp_set_user_survivor","_set_user_survivor",1)
	
	register_native("xp_reset_user_data","_reset_user_data",1)
	register_native("xp_get_user_rank","_get_user_rank",1)
	register_native("xp_check_user_level","CheckPlayerLevel",1)
}

public plugin_init()
{
	new const PLUGIN_VERSION[] = "1.0"//0.0.5
	new const CVAR_EXP_VERSION[] = "n4d_zpstats"
	register_plugin("[ZP] UserVault", PLUGIN_VERSION, "wbyokomo, huehue, djbosma")
	
	iHudStats = CreateHudSyncObj()
	iMsgSayText = get_user_msgid("SayText")
	
	//register_event("HLTV", "event_newround", "a", "1=0", "2=0")
	register_event("DeathMsg", "OnDeathMsg", "a") //use deathmsg easy to trace weapon and hitplace
	register_event_ex("30", "Event_Intermission", RegisterEvent_Global)
	
	RegisterHam(Ham_Player_PreThink, "player", "OnPlayerPreThink")
	
	register_clcmd("say /stats" , "CmdStats")
	register_clcmd("say /rank", "CmdShowRank")
	register_clcmd("say /top15", "CmdTopExpGlobal")
	register_clcmd("say /top10", "CmdTopExpGlobal")
	register_clcmd("say /toponline", "CmdTopExpOnline")
	
	register_clcmd("say_team /stats" , "CmdStats")
	register_clcmd("say_team /rank", "CmdShowRank")
	register_clcmd("say_team /top15", "CmdTopExpGlobal")
	register_clcmd("say_team /top10", "CmdTopExpGlobal")
	register_clcmd("say_team /toponline", "CmdTopExpOnline")
	
	cvar_ammopacks = register_cvar("xp_ammopacks_reward", "1")
	//g_maxplayers = get_maxplayers()
	

	gForward[Forward_Levelup] = CreateMultiForward("xp_user_levelup", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL) //xp_user_levelup(player, level, exp)
	gForward[Forward_Exp_Add] = CreateMultiForward("xp_user_expadd", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expadd(player, expadd)
	gForward[Forward_Exp_Set] = CreateMultiForward("xp_user_expset", ET_CONTINUE, FP_CELL, FP_CELL) //xp_user_expset(player, exptotal)
	
	register_cvar(CVAR_EXP_VERSION, PLUGIN_VERSION, FCVAR_SERVER|FCVAR_SPONLY)
	set_cvar_string(CVAR_EXP_VERSION, PLUGIN_VERSION)
}

/*
public event_newround()
{
	new id;
	for(id = 1; id<= g_maxplayers; id++)
		if(is_user_valid(id) && is_user_alive(id) && is_user_connected(id) && !zp_get_user_zombie(id)
		&& !zp_get_user_nemesis(id) && !zp_get_user_survivor(id))
			reward_user(id, 1)
}
*/

public Event_Intermission()
{
	set_task_ex(0.1, "Delayed_Intermission")
}
public Delayed_Intermission()
{
	new iPlayers[MAX_PLAYERS], iNum, id
	get_players_ex(iPlayers, iNum, GetPlayers_ExcludeHLTV|GetPlayers_ExcludeBots)

	for (--iNum; iNum >= 0; iNum--)
	{
		id = iPlayers[iNum]

		if (!is_user_connected(id))
			return

		reward_with_ammopacks(id)
	}
}
public fw_spawn_post(id)
{
	if(zp_get_user_zombie(id) || zp_get_user_survivor(id) || zp_get_user_nemesis(id)
	|| !is_user_alive(id) || !is_user_connected(id) || !is_user_valid(id)) {return;}
	else
		reward_user(id, 0)
}

public zp_user_humanized_post(id)
	fw_spawn_post(id)

reward_user(id, roundstart)
{
	if(get_pcvar_num(cvar_ammopacks) == 1 && roundstart == 1){ reward_with_ammopacks(id);}
}

reward_with_ammopacks(id)
{
	new ap = Ammopacks[gData[id][Data_Level]]
	zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + ap)
	//client_print(id, print_chat, "You received %d ammmopacks from the server", ap)
	UTIL_ColorChat(id, "^x04[User Vault]^x01 You received:^x04 %d^x01 ammmopacks from the server", ap)
}

public plugin_cfg()
{
	iVaultHandle = nvault_open(szVaultName)
	
	if(iVaultHandle == INVALID_HANDLE)
	{
		new szText[128]; formatex(szText, 127, "[UserVault] Error opening nVault file [%s]", szVaultName);
		set_fail_state(szText)
	}
	else
	{
		server_print("[UserVault] Database [%s] successfully loaded...", szVaultName)
		
		#if defined PRUNE_DATABASE
		nvault_prune(iVaultHandle, 0, get_systime() - (86400 * iExpiredDays))
		#endif
		
		FormatGlobalTopTen()
		
		#if defined UPDATE_MOTD
		if(file_exists(szFileMotd))
		{
			if(delete_file(szFileMotd))
			{
				if(write_file(szFileMotd, szMotd, -1)) server_print("[UserVault] File [%s] has been updated...", szFileMotd);
			}
		}
		#endif
	}
}

public plugin_end()
{
	nvault_close(iVaultHandle)
}

public client_putinserver(id)
{

	if (is_user_hltv(id))
		return;

	arrayset(gData[id], 0, sizeof(gData[]))
	
	get_user_name(id, gData[id][Data_Name], charsmax(gData[][Data_Name]))
	get_user_authid(id, gData[id][Data_Steamid], charsmax(gData[][Data_Steamid]))
	//get_user_ip(id, gData[id][Data_Ip], charsmax(gData[][Data_Ip]))
	set_task(0.1, "Load_Data", id, gData[id][Data_Name], sizeof(gData[][Data_Name]))
}

public client_disconnected(id)
{
	if (gData[id][Data_Connected])
	{
		gData[id][Data_PlayTime] += get_user_time(id)
		Save_Data(id, gData[id][Data_Name])
		gData[id][Data_Connected] = false
	}
}

public client_infochanged(id)
{
	if (!is_user_connected(id))
		return PLUGIN_HANDLED
	
	static szNames[2][32]
	get_user_name(id, szNames[0], charsmax(szNames[]))
	get_user_info(id, "name", szNames[1], charsmax(szNames[]))

	if (!equali(szNames[1], szNames[0]))
	{
		Save_Data(id, szNames[0])
		set_task(0.1, "Load_Data", id, szNames[1], sizeof(szNames[]))
		gData[id][Data_Name] = szNames[1]
		return PLUGIN_HANDLED
	}
	return PLUGIN_HANDLED
}

public CmdStats(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	new menu = menu_create("\yPlayer Stats:", "PlayerStatsMenuHandler")
	new szUserId[32], iPlayers[32], iNum, j, id2, szName[32]
	get_players(iPlayers, iNum, "h")
	for(j=0;j<iNum;j++)
	{
		id2 = iPlayers[j]
		get_user_name(id2, szName, 31)
		formatex(szUserId, 31, "%d", get_user_userid(id2))
		menu_additem(menu, szName, szUserId, 0)
	}
	
	menu_display(id, menu, 0)
	
	return PLUGIN_HANDLED;
}

public PlayerStatsMenuHandler(id, menu, item)
{
	if(!is_user_connected(id))
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	if(item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED;
	}
	
	new szData[6], szName[64]
	new _access, item_callback
	menu_item_getinfo(menu, item, _access, szData, 5, szName, 63, item_callback)
	
	new userid = str_to_num(szData)
	new player = find_player("k", userid)
	
	if(player && is_user_connected(player))
	{
		GetPlayerStats(player, id)
	}
	
	menu_destroy(menu)
	return PLUGIN_HANDLED;
}

public CmdShowRank(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	new iRank = SortPlayerRank(id)
	if(iRank == -1) UTIL_ColorChat(id, "^x04[UserVault]^x01 Your rank is not been saved yet, please rejoin the server.") //client_print(id, print_chat, "Your rank is not been saved yet, please rejoin the server.");
	else UTIL_ColorChat(id, "^x04%s^x01 rank is^x04 %d^x01/^x04%d^x01 -- Kills:^x04 %d^x01 Deaths:^x04 %d^x01 Stage:^x04 %d^x01 Points:^x04 %d^x01/^x04%d", gData[id][Data_Name], iRank, iTotalEntries, gData[id][Data_Kills], gData[id][Data_Deaths], szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1])
	
	return PLUGIN_HANDLED;
}

public CmdTopExpGlobal(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		//client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		UTIL_ColorChat(id, "^x04[UserVault]^x01 System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	show_motd(id, szMotd, "TOP-10 Players (GLOBAL)")
	
	return PLUGIN_HANDLED;
}

public CmdTopExpOnline(id)
{
	if(!is_user_connected(id)) return PLUGIN_HANDLED;
	
	static Float:ctime; ctime = get_gametime();
	if(fLastCmd > ctime)
	{
		client_print(id, print_chat, "System is busy please wait for %.1f second(s).", fLastCmd-ctime)
		return PLUGIN_HANDLED;
	}
	
	fLastCmd = ctime+2.0
	static Sort[33][2]
	new players[32], num, count, index
	get_players(players, num)
	
	for(new i = 0; i < num; i++)
	{
		index = players[i]
		Sort[count][0] = index
		Sort[count][1] = gData[index][Data_Exp]
		count++
	}
	
	SortCustom2D(Sort, count, "CompareEXP")
	
	new y = clamp(count, 0, 10)
	new kindex, szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd2)
	
	for(new x = 0; x < y; x++)
	{
		kindex = Sort[x][0]
		new iSec, szTimeFormat[32], szName[32]
		iSec = get_user_time(kindex)+gData[kindex][Data_PlayTime]
		GetTimeFormat(iSec, szTimeFormat, 31)
		get_user_name(kindex, szName, 31)
		replace_all(szName, 31, "#", " ")
		replace_all(szName, 31, "<", "&lt")
		replace_all(szName, 31, ">", "&gt")
		
		len += formatex(szMotd2[len], charsmax(szMotd2)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%d</td>\
		<td>%s</td>", (x+1), szName, gData[kindex][Data_Exp], gData[kindex][Data_Kills], gData[kindex][Data_Deaths], szTimeFormat)
	}
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(id, szMotd2, "TOP Players (Now Online)")
	
	return PLUGIN_HANDLED;
}

public CompareEXP(elem1[], elem2[])
{
	if(elem1[1] > elem2[1]) return -1;
	else if(elem1[1] < elem2[1]) return 1;
	
	return 0;
}

public OnDeathMsg()
{
	new atk, vic, hs, szWpn[4]
	atk = read_data(1)
	vic = read_data(2)
	hs = read_data(3)
	read_data(4, szWpn, 3)
	
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		
		if(hs)
		{
			gData[atk][Data_HeadShot]++
			gData[atk][Data_Exp] += iExpHeadShot
		}
		if(zp_get_user_nemesis(vic))
		{
			gData[atk][Data_NemKills]++
			gData[atk][Data_Exp] += iExpNemKill
		}
		else if(zp_get_user_survivor(vic))
		{
			gData[atk][Data_SurKills]++
			gData[atk][Data_Exp] += iExpSurKill
		}
		
		if(szWpn[0]=='k' && szWpn[1]=='n')
		{
			gData[atk][Data_Knife]++
			gData[atk][Data_Exp] += iExpKnife
			CheckPlayerLevel(atk)
			return;
		}
		
		if(szWpn[0]=='g' && szWpn[1]=='r')
		{
			gData[atk][Data_Nade]++
			gData[atk][Data_Exp] += iExpGrenade
			CheckPlayerLevel(atk)
			return;
		}
		
		CheckPlayerLevel(atk)
	}
}

public zp_user_infected_post(vic, atk)
{
	if(is_user_connected(vic))
	{
		gData[vic][Data_Deaths]++
	}
	
	if((atk != vic) && is_user_connected(atk))
	{
		gData[atk][Data_Kills]++
		gData[atk][Data_Exp] += iExpKill
		CheckPlayerLevel(atk)
	}
}

public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "        SPECTATING^n%s ^n[ Country: %s ]^n[ HP: %.0f | Ammo: %d ]^n[ %s: %d/%d ]", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), zp_get_user_ammo_packs(iSpec),szRanks[gData[iSpec][Data_Level]], gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1]) //entity_get_float(iSpec, EV_FL_armorvalue)
		return;
	}
	new iRank
	iRank = SortPlayerRank(id)
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "[ %s: %d/%d ]^n[ Rank: %d of %d ]^n              Alive ^n[ Humans:%d|%d:Zombies ]",szRanks[gData[id][Data_Level]], gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], iRank, iTotalEntries, zp_get_human_count(), zp_get_zombie_count() )
}
/*
public OnPlayerPreThink(id)
{
	static Float:ctime; ctime = get_gametime();
	if(fLastHud[id] > ctime) return;
	
	fLastHud[id] = ctime+1.0
	
	if(!is_user_alive(id))
	{
		static iSpec; iSpec = entity_get_int(id, EV_INT_iuser2);
		if(!is_user_alive(iSpec)) return;
		
		set_hudmessage(128, 128, 128, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
		ShowSyncHudMsg(id, iHudStats, "SPECTATING: %s | COUNTRY: %s^nHP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s", gData[iSpec][Data_Name], gData[iSpec][Data_Country], entity_get_float(iSpec, EV_FL_health), entity_get_float(iSpec, EV_FL_armorvalue), zp_get_user_ammo_packs(iSpec), gData[iSpec][Data_Exp], iEXP[gData[iSpec][Data_Level]+1], szRanks[gData[iSpec][Data_Level]])
		return;
	}
	
	set_hudmessage(4, 128, 4, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.6, 0.5, -1)
	ShowSyncHudMsg(id, iHudStats, "HP: %.0f | ARMOR: %.0f | PACKS: %d^nEXP: %d/%d | LEVEL: %s^nCOUNTRY: %s", entity_get_float(id, EV_FL_health), entity_get_float(id, EV_FL_armorvalue), zp_get_user_ammo_packs(id), gData[id][Data_Exp], iEXP[gData[id][Data_Level]+1], szRanks[gData[id][Data_Level]], gData[id][Data_Country])
}*/

public _get_user_exp(id)
{
	return gData[id][Data_Exp];
}

public _set_user_exp(id, amount)
{
	gData[id][Data_Exp] = amount
}

public _get_user_playtime(id)
{
	return gData[id][Data_PlayTime];
}

public _set_user_playtime(id, amount)
{
	gData[id][Data_PlayTime] = amount
}

public _get_user_level(id)
{
	return gData[id][Data_Level];
}

public _set_user_level(id, amount)
{
	gData[id][Data_Level] = amount
}

public _get_user_deaths(id)
{
	return gData[id][Data_Deaths];
}

public _set_user_deaths(id, amount)
{
	gData[id][Data_Deaths] = amount
}

public _get_user_frags(id)
{
	return gData[id][Data_Kills];
}

public _set_user_frags(id, amount)
{
	gData[id][Data_Kills] = amount
}

public _get_user_headshot(id)
{
	return gData[id][Data_HeadShot];
}

public _set_user_headshot(id, amount)
{
	gData[id][Data_HeadShot] = amount
}

public _get_user_knife(id)
{
	return gData[id][Data_Knife];
}

public _set_user_knife(id, amount)
{
	gData[id][Data_Knife] = amount
}

public _get_user_nade(id)
{
	return gData[id][Data_Nade];
}

public _set_user_nade(id, amount)
{
	gData[id][Data_Nade] = amount
}

public _get_user_nemesis(id)
{
	return gData[id][Data_NemKills];
}

public _set_user_nemesis(id, amount)
{
	gData[id][Data_NemKills] = amount
}

public _get_user_survivor(id)
{
	return gData[id][Data_SurKills];
}

public _set_user_survivor(id, amount)
{
	gData[id][Data_SurKills] = amount
}

public _reset_user_data(id)
{
	gData[id][Data_Exp] = 0
	gData[id][Data_Kills] = 0
	gData[id][Data_Deaths] = 0
	gData[id][Data_HeadShot] = 0
	gData[id][Data_Knife] = 0
	gData[id][Data_Nade] = 0
	gData[id][Data_NemKills] = 0
	gData[id][Data_SurKills] = 0
	gData[id][Data_PlayTime] = 0
	gData[id][Data_Level] = 0
}

public _get_user_rank(id)
{
	return SortPlayerRank(id);
}

GetTimeFormat(seconds, szTime[], len)
{
	new days, hours, minutes
	days = seconds / 86400;
	hours = ( seconds / 3600 ) % 24;
	minutes = ( seconds / 60 ) % 60;
	seconds = seconds % 60;
	
	if(days)
	{
		formatex(szTime, len, "%dD %dH %dM %dS", days, hours, minutes, seconds)
		return;
	}
	
	if(hours)
	{
		formatex(szTime, len, "%dH %dM %dS", hours, minutes, seconds)
		return;
	}
	
	if(minutes)
	{
		formatex(szTime, len, "%dM %dS", minutes, seconds)
		return;
	}
	
	if(seconds)
	{
		formatex(szTime, len, "%dS", seconds)
	}
}

GetPlayerStats(id, caller)
{
	new szMotd2[1536], len
	szMotd2[0] = 0
	
	add(szMotd2, charsmax(szMotd2),
	"<html><style>\
	body{background: url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left;  }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#e6e6e6;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd2, charsmax(szMotd2),
	"<tr><td id=h width=30%>Statistics</td>\
	<td id=h>Ammount</td></tr>")
	
	len = strlen(szMotd2)

	new iSec, szTimeFormat[32], iRank, iPacks, szName[32]
	iSec = get_user_time(id)+gData[id][Data_PlayTime]
	GetTimeFormat(iSec, szTimeFormat, 31)
	iRank = SortPlayerRank(id)
	iPacks = zp_get_user_ammo_packs(id)
	get_user_name(id, szName, 31)
	replace_all(szName, 31, "#", " ")
	replace_all(szName, 31, "<", "&lt")
	replace_all(szName, 31, ">", "&gt")
	
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nickname</td><td>%s</td>", szName)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>SteamID</td><td>%s</td>", gData[id][Data_Steamid])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Country</td><td>%s</td>", gData[id][Data_Country])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Rank</td><td>%d of %d</td>", iRank, iTotalEntries)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Ammo</td><td>%d</td>", iPacks)
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Points</td><td>%d</td>", gData[id][Data_Exp])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Stage</td><td>%s</td>", szRanks[gData[id][Data_Level]])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Kills</td><td>%d</td>", gData[id][Data_Kills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Deaths</td><td>%d</td>", gData[id][Data_Deaths])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Headshot kills</td><td>%d</td>", gData[id][Data_HeadShot])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Knife kills</td><td>%d</td>", gData[id][Data_Knife])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Grenade kills</td><td>%d</td>", gData[id][Data_Nade])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Nemesis kills</td><td>%d</td>", gData[id][Data_NemKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Survivor kills</td><td>%d</td>", gData[id][Data_SurKills])
	len += formatex(szMotd2[len], charsmax(szMotd2)-len, "<tr><td id=p>Online time</td><td>%s</td>", szTimeFormat)
	
	add(szMotd2, charsmax(szMotd2), "</table></body></html>")
	show_motd(caller, szMotd2, "Player Statistics")
}

public CheckPlayerLevel(id)
{
	while((gData[id][Data_Exp] >= iEXP[gData[id][Data_Level]+1]))
	{
		gData[id][Data_Level]++
		UTIL_ColorChat(id, "^x04%s^x01 has been promoted to the Stage of^x04 %s^x01 with^x04 %d^x01 Points.", gData[id][Data_Name], szRanks[gData[id][Data_Level]], gData[id][Data_Exp])
		ExecuteForward(gForward[Forward_Levelup], gForward[Forward_Result], id, gData[id][Data_Level], gData[id][Data_Exp])
	}
}


public Load_Data(szName[], id)
{
	if(!is_user_connected(id))
		return

	new szName[32], szKey[50], szData[164]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", szName)
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	//formatex(szKey, 49, "%s#EXP", gData[id][Data_Ip])	

	if (nvault_get(iVaultHandle, szName, szData, charsmax(szData)))
	{
		replace_all(szData, charsmax(szData), "#", " ")
	
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8]
		parse(szData, szExp, charsmax(szExp), szKills, charsmax(szKills), szDeaths, charsmax(szDeaths), szHeadShot, charsmax(szHeadShot), szKnife, charsmax(szKnife),
			szNade, charsmax(szNade), szNemKill, charsmax(szNemKill), szSurKill, charsmax(szSurKill), szPlayTime, charsmax(szPlayTime), szLevel, charsmax(szLevel))

		gData[id][Data_Exp] = str_to_num(szExp)
		gData[id][Data_Kills] = str_to_num(szKills)
		gData[id][Data_Deaths] = str_to_num(szDeaths)
		gData[id][Data_HeadShot] = str_to_num(szHeadShot)
		gData[id][Data_Knife] = str_to_num(szKnife)
		gData[id][Data_Nade] = str_to_num(szNade)
		gData[id][Data_NemKills] = str_to_num(szNemKill)
		gData[id][Data_SurKills] = str_to_num(szSurKill)
		gData[id][Data_PlayTime] = str_to_num(szPlayTime)
		gData[id][Data_Level] = str_to_num(szLevel)
	}
	else
	{
		_reset_user_data(id)
	}
	gData[id][Data_Connected] = true
}

public Save_Data(id, szName[])
{
	new szKey[50], szData[MAX_FMT_LENGTH]
	replace_all(gData[id][Data_Name], 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", gData[id][Data_Name])
	formatex(szData, charsmax(szData), "%d %d %d %d %d %d %d %d %d %d %s", gData[id][Data_Exp], gData[id][Data_Kills], gData[id][Data_Deaths], gData[id][Data_HeadShot], gData[id][Data_Knife], gData[id][Data_Nade], gData[id][Data_NemKills], gData[id][Data_SurKills], gData[id][Data_PlayTime], gData[id][Data_Level], gData[id][Data_Name])
	nvault_set(iVaultHandle, szName, szData)
}

FormatGlobalTopTen()
{
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	const MAX_ENTRIES = 10
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < MAX_ENTRIES)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < MAX_ENTRIES)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)

	new len
	szMotd[0] = 0
	
	add(szMotd, charsmax(szMotd),
	"<html><style>\
	body{background:url('https://static.brusheezy.com/system/resources/previews/000/013/939/non_2x/grunge-texture-by-krist-photoshop-textures.jpg') repeat;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
	.t{color:#afafaf;text-align:left; }\
	#h{background: #333;border-style: solid;border-width: 1px;border-color: #999;color:#E0E0E0;font-weight:bold;}\
	#p{color:#D41313;}\
	#n{color:#fff;}\
	</style><body>\
	<table cellspacing=0 width=100% class=t>")
	
	add(szMotd, charsmax(szMotd),
	"<tr><td id=h width=7%>#</td>\
	<td id=h>Name</td>\
	<td id=h>Points</td>\
	<td id=h>Kills</td>\
	<td id=h>Deaths</td>\
	<td id=h>Online</td></tr>")
	
	len = strlen(szMotd)
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		//data[VD_Key][20] = 0
		
		new szDataNew[164]
		nvault_get(iVaultHandle, data[VD_Key], szDataNew, charsmax(szDataNew))
		
		new szExp[8], szKills[8], szDeaths[8], szHeadShot[8], szKnife[8], szNade[8], szNemKill[8], szSurKill[8], szPlayTime[8], szLevel[8], szName3[32]
		parse(szDataNew, szExp, 7, szKills, 7, szDeaths, 7, szHeadShot, 7, szKnife, 7, szNade, 7, szNemKill, 7, szSurKill, 7, szPlayTime, 7, szLevel, 7, szName3, 31)
		
		new iSec, szOnline[32]
		iSec = str_to_num(szPlayTime)
		GetTimeFormat(iSec, szOnline, 31)
		replace_all(szName3, 31, "#", " ")
		replace_all(szName3, 31, "<", "&lt")
		replace_all(szName3, 31, ">", "&gt")
		
		len += formatex(szMotd[len], charsmax(szMotd)-len,
		"<tr><td id=p>%d</td>\
		<td id=n>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>\
		<td>%s</td>", (i+1), szName3, szExp, szKills, szDeaths, szOnline)
	}
	
	add(szMotd, charsmax(szMotd), "</table></body></html>")
	ArrayDestroy(entries)
}

SortPlayerRank(id)
{
	new szName[32], szKey[50]
	copy(szName, 31, gData[id][Data_Name])
	replace_all(szName, 31, "#", " ")
	formatex(szKey, 49, "%s#EXP", szName)
	
	enum _:VaultData
	{
		VD_Key[64],
		VD_Value
	}
	
	new vault = nvault_util_open(szVaultName)
	new Array:entries = ArrayCreate(VaultData)
	new sizeEntries
	new numEntries = nvault_util_count(vault)
	new data[VaultData], value[128], data2[VaultData]
	
	for(new i = 0, pos, timestamp; i < numEntries; i++)
	{
		pos = nvault_util_read(vault, pos, data[VD_Key], charsmax(data[VD_Key]), value, charsmax(value), timestamp)
		data[VD_Value] = str_to_num(value)
		
		if(sizeEntries == 0)
		{
			ArrayPushArray(entries, data)
			sizeEntries++;
		}
		else
		{
			for(timestamp = 0; timestamp <= sizeEntries; timestamp++)
			{
				if(timestamp == sizeEntries)
				{
					if(sizeEntries < numEntries)
					{
						ArrayPushArray(entries, data)
						sizeEntries++;
					}
					
					break;
				}
				
				ArrayGetArray(entries, timestamp, data2)
				
				if(data[VD_Value] >= data2[VD_Value])
				{
					ArrayInsertArrayBefore(entries, timestamp, data)
					
					if(sizeEntries < numEntries)
					{
						sizeEntries++;
					}
					else
					{
						ArrayDeleteItem(entries, sizeEntries)
					}
					
					break;
				}
			}
		}
	}
	
	nvault_util_close(vault)
	iTotalEntries = sizeEntries
	
	for(new i = 0; i < sizeEntries; i++)
	{
		ArrayGetArray(entries, i, data)
		if(equal(data[VD_Key],szKey))
		{
			gData[id][Data_Rank] = i+1
			break;
		}
	}
	
	ArrayDestroy(entries)
	return gData[id][Data_Rank];
}

UTIL_ColorChat(id, const szText[], any:...)
{
	new szBuffer[512]
	
	if(!id)
	{
		new iPlayers[32], iNum, y, id2
		get_players(iPlayers, iNum, "ch")
		for(y=0;y<iNum;y++)
		{
			id2 = iPlayers[y]
			if(!is_user_connected(id2)) continue;
			
			vformat(szBuffer, charsmax(szBuffer), szText, 3)
			message_begin(MSG_ONE_UNRELIABLE, iMsgSayText, _, id2)
			write_byte(id2)
			write_string(szBuffer)
			message_end()
		}
	}
	else
	{
		vformat(szBuffer, charsmax(szBuffer), szText, 3)
		message_begin(MSG_ONE, iMsgSayText, _, id)
		write_byte(id)
		write_string(szBuffer)
		message_end()
	}
}

stock client_cmd_ex(id, const command[], any:...)
{
	#pragma unused command
	
	if (id == 0 || is_user_connected(id))
	{
		new szMessage[256]
		
		format_args(szMessage, charsmax(szMessage), 1)
		
		message_begin(id == 0 ? MSG_ALL : MSG_ONE, 51, _, id)
		write_byte(strlen(szMessage) + 2)
		write_byte(10)
		write_string(szMessage)
		message_end()
	}
}
Нарочно не съм редактирал предишното мнение.
Пиша от избата, защото горе имаме течове..

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Грешно извеждане на Data_Rank 0/x

Мнение от LayerFort DJBosma » 24 фев 2019, 15:26

МНЕНИЕТО Е СКРИТО ОТ СТРАНА НА МОДЕРАТОР! ЦЪКНИ ВЪРХУ ЛЕНТАТА ЗА ДА ГО ПРЕГЛЕДАШ.
Последна промяна от OciXCrom TM на 24 фев 2019, 15:26, променено общо 1 път.
Причина: Още един бут и ще получиш предупреждение! Има си бутон за избутване на темата.
Пиша от избата, защото горе имаме течове..

Потребителски аватар

Автор на темата
LayerFort DJBosma
Потребител
Потребител
Мнения: 74
Регистриран: 25 дек 2018, 04:14
Местоположение: Alkmaar
Се отблагодари: 2 пъти
Получена благодарност: 2 пъти
Години: 24
Контакти:

nVault; Грешно извеждане на Data_Rank 0/x

Мнение от LayerFort DJBosma » 25 фев 2019, 14:20

Реших го, заключвайте!
:pepo_mustache:
Пиша от избата, защото горе имаме течове..

Заключена

Върни се в “Кошче”

Кой е на линия

Потребители, разглеждащи този форум: Няма регистрирани потребители и 0 госта