Код:
#include < amxmodx >
#include < amxmisc >
#include < nvault >
#include < fakemeta >
#define PLUGIN_NAME "Level_System"
#define PLUGIN_VERSION "0.2"
#define PLUGIN_AUTHOR "Bos93 & FirsT & xoymiii"
#define MAX_CLIENTS 32
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
enum (+= 100)
{
TASK_SHOWHUD = 10
}
new const RANK_NAMES[128] =
{
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19"
}
new const MAX_LEVELS[20] =
{
2, //1
3, //2
4, //3
5, //4
6, //5
200, //6
400, //7
800, //8
1000, //9
1500, //10
2200, //11
3000, //12
3500, //13
4000, //14
4700, //15
5400, //16
6000, //17
6800, //18
7500, //19
9000 //20
}
const Float:HUD_STATS_X = 0.02;
const Float:HUD_STATS_Y = 0.9025;
const Float:HUD_SPECT_X = -1.0;
const Float:HUD_SPECT_Y = 0.8;
const PEV_SPEC_TARGET = pev_iuser2
new g_iLevel[ MAX_CLIENTS + 1 ],
g_iExp[ MAX_CLIENTS + 1 ],
g_playername[ MAX_CLIENTS + 1 ][ MAX_CLIENTS ];
new g_vault
public plugin_init( )
{
register_plugin ( PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR );
register_event( "DeathMsg", "EV_DeathMsg", "a" );
g_vault = nvault_open("Levels__System")
register_dictionary("levels.txt" );
}
public plugin_natives()
{
register_native("get_user_level", "native_get_user_level", 1)
register_native("set_user_level", "native_set_user_level", 1)
register_native("get_user_exp", "native_get_user_exp", 1)
register_native("set_user_exp", "native_set_user_exp", 1)
}
public client_disconnect(id)
{
SaveData(id);
}
public client_putinserver( iPlayer )
{
get_user_name(iPlayer, g_playername[iPlayer], charsmax(g_playername[]))
set_task(1.0, "ShowHUD", iPlayer+TASK_SHOWHUD, _, _, "b")
LoadData( iPlayer );
}
public plugin_end()
{
nvault_close(g_vault)
}
public EV_DeathMsg( )
{
static iVictim, iKiller;
iVictim = read_data( 2 );
iKiller = read_data( 1 );
if( !is_user_connected( iVictim ) )
return;
if( iKiller == iVictim || !iKiller )
return;
g_iExp[ iKiller ] += 1;
while( g_iExp[ iKiller ] >= MAX_LEVELS[ g_iLevel[ iKiller ] ] )
{
g_iLevel[ iKiller ] += 1;
color_print( iKiller , "!g[SERVER]!y Ваш уровень поднят !");
}
public ShowHUD(taskid)
{
static iPlayer
iPlayer = ID_SHOWHUD;
if (!is_user_alive( iPlayer ) )
{
iPlayer = pev(iPlayer, PEV_SPEC_TARGET)
// Target not alive
if (!is_user_alive(iPlayer) ) return;
}
if (iPlayer != ID_SHOWHUD)
{
set_hudmessage( 100, 100, 100, HUD_SPECT_X, HUD_SPECT_Y, 0, 5.0, 3.0, 1.0, 1.0, -1 );
show_hudmessage( ID_SHOWHUD , "Наблюдение за: %s^n[Уровень: %L] [Опыт: %d / %d]", LANG_PLAYER, g_playername[ iPlayer ] , (RANK_NAMES[g_iLevel[ ID_SHOWHUD ]]) , g_iExp[ ID_SHOWHUD ] , (MAX_LEVELS[g_iLevel[ ID_SHOWHUD ]]) );
}
else
{
set_hudmessage( 0, 255, 0, HUD_STATS_X, HUD_STATS_Y, 0, 5.0, 3.0, 1.0, 1.0, -1 );
show_hudmessage( ID_SHOWHUD , "[Уровень: %L] [Опыт: %d / %d]", LANG_PLAYER, (RANK_NAMES[g_iLevel[ ID_SHOWHUD ]]) , g_iExp[ ID_SHOWHUD ] , (MAX_LEVELS[g_iLevel[ ID_SHOWHUD ]]));
}
}
public SaveData(id) {
new AuthID[35]
get_user_authid(id,AuthID,34)
new vaultkey[64],vaultdata[256]
format(vaultkey,63,"%s-cso",AuthID)
format(vaultdata,255,"%i#%i#",g_iLevel[id],g_iExp[id])
nvault_set(g_vault,vaultkey,vaultdata)
return PLUGIN_CONTINUE
}
public LoadData(id)
{
new AuthID[35]
get_user_authid(id,AuthID,34)
new vaultkey[64],vaultdata[256]
format(vaultkey,63,"%s-cso",AuthID)
format(vaultdata,255,"%i#%i#",g_iLevel[id],g_iExp[id])
nvault_get(g_vault,vaultkey,vaultdata,255)
replace_all(vaultdata, 255, "#", " ")
new experience[32], playerlevel[32]
parse(vaultdata, experience, 31, playerlevel, 31)
g_iLevel[id] = str_to_num(experience)
g_iExp[id] = str_to_num(playerlevel)
return PLUGIN_CONTINUE
}
public native_get_user_exp(id)
{
return g_iExp[id];
}
public native_set_user_exp(id, amount)
{
g_iExp[id] = amount;
}
public native_get_user_level(id)
{
return g_iLevel[id];
}
public native_set_user_level(id, amount)
{
g_iLevel[id] = amount;
}
stock color_print( const id , const input[], any:...)
{
new count = 1, players[32]
static msg[191]
vformat(msg, 190, input, 3)
replace_all(msg, 190, "!g", "^4" ) // Green Color
replace_all(msg, 190, "!y", "^1" ) // Default Color
replace_all(msg, 190, "!team", "^3" ) // Team Color
if (id) players[0] = id; else get_players(players, count, "ch")
{
for (new i = 0; i < count; i++)
{
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText" ), _, players[i])
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}