How do I create a native to pull the name of the person's rank ?, already tried:
HTML Code:
#include <amxmodx>
#include <fvault>
#include <client_print_color>
#define PLUGIN "[CFK] Addon: Sistema de Patentes"
#define VERSION "1.0"
#define AUTHOR "Wilian M."
#define MAX_LEVELS 10
#define PREFIX "\r[\dCFK\r]"
#define PREFIXCHAT "!t[!gCFK!t]"
new xMyXP[33], xMyLevel[33]
new xCvarKillXp, xCvarKillXpHs, xCvarKillKnife, xCvarKillGrenade
new const xDataPatent[] = "cfk_patentes"
new xLevels[MAX_LEVELS] =
{
500, // General
750, // Sargento
950, // Coronel
1150, // Prata
1350, // Bronze
1650, // Ouro
1850, // Platinium
2850, // Diamante
5555, // Desafiador
10000000
}
new xRankNames[MAX_LEVELS][] =
{
"Iniciante",
"General",
"Sargento",
"Coronel",
"Prata",
"Bronze",
"Ouro",
"Platinium",
"Diamante",
"Desafiador"
}
forward ars_user_logged_post(id)
native ars_is_user_logged(id)
native ars_get_user_account_name(index, login[], len)
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
// Evento apos Morrer
register_event("DeathMsg","xDeathMsg","a")
register_clcmd("say xp", "xShowMyXp")
register_clcmd("say /xp", "xShowMyXp")
// Cvars do XP
xCvarKillXp = register_cvar("sp_exp_kill_normal", "3") // Experiencia ao matar normal
xCvarKillXpHs = register_cvar("sp_exp_kill_hs", "3") // Experiencia ao matar com HS
xCvarKillKnife = register_cvar("sp_exp_kill_knife", "3") // Experiencia ao matar com Faca
xCvarKillGrenade = register_cvar("sp_exp_kill_granada", "5") // Experiencia ao matar com Granada
}
public xShowMyXp(id) client_print_color(id, "%s !yExperiencia: !t%d!y, Minha Patente: !t%s!y.", PREFIXCHAT, xMyXP[id], native_sp_get_user_rankname(id))
public ars_user_logged_post(id) xLoadData(id)
public xSaveData(id)
{
if(!ars_is_user_logged(id) || !is_user_connected(id)) return;
new xAccount[40]; ars_get_user_account_name(id, xAccount, charsmax(xAccount))
new xData[50]
formatex(xData, charsmax(xData), "%d %d", xMyXP[id], xMyLevel[id])
fvault_set_data(xDataPatent, xAccount, xData)
}
public xLoadData(id)
{
new xAccount[40]; ars_get_user_account_name(id, xAccount, charsmax(xAccount))
new x1[15], x2[15], xData[50]
fvault_get_data(xDataPatent, xAccount, xData, charsmax(xData))
parse(xData, x1, charsmax(x1))
xMyXP[id] = str_to_num(x1)
xMyLevel[id] = str_to_num(x2)
xCheckMyLevel(id, 0)
}
public xDeathMsg()
{
new xKiller = read_data(1)
new xVictim = read_data(2)
new xHs = read_data(3)
new xUserWeapon = get_user_weapon(xKiller)
if(is_user_connected(xKiller) && is_user_alive(xKiller))
{
if(xVictim != xKiller)
{
if(!xHs)
{
xMyXP[xKiller] += get_pcvar_num(xCvarKillXp)
}
else if(xUserWeapon == CSW_KNIFE)
{
xMyXP[xKiller] += get_pcvar_num(xCvarKillKnife)
}
else if(xUserWeapon == CSW_HEGRENADE)
{
xMyXP[xKiller] += get_pcvar_num(xCvarKillGrenade)
}
else
{
xMyXP[xKiller] += get_pcvar_num(xCvarKillXpHs)
}
xCheckMyLevel(xKiller, 1)
xSaveData(xKiller)
}
}
}
public xCheckMyLevel(id, msg)
{
static xName[32]
get_user_name(id, xName, 31)
if(xMyLevel[id] < MAX_LEVELS)
{
while(xMyXP[id] >= xLevels[xMyLevel[id]])
{
xMyLevel[id]++
if(msg)
{
client_print_color(0, "%s !t%s !ySubiu de level. !gLevel: !y%d.", PREFIXCHAT, xName, xMyLevel[id])
//client_print_color(id, "%s !yVoce ganhou + 50 Coins por subir de Level.", PREFIXCHAT)
}
}
}
}
public plugin_natives()
{
register_native("sp_get_user_rankname", "native_sp_get_user_rankname", 1)
register_native("sp_get_user_level", "native_sp_get_user_level", 1)
register_native("sp_get_user_xp", "native_sp_get_user_xp", 1)
}
public native_sp_get_user_rankname(id)
{
if (!is_user_connected(id))
return false
return xRankNames[xMyLevel[id]]
}
public native_sp_get_user_level(id) return xMyLevel[id]
public native_sp_get_user_xp(id) return xMyXP[id]
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1046\\ f0\\ fs16 \n\\ par }
*/