Код за потвърждение: Избери целия код
#include <amxmodx>
#include <fvault>
#include <cstrike>
#include <wm_play>
#define PLUGIN "XP + LEVEL + RANK SYSTEM"
#define VERSION "1.1"
#define maxranks 11
#define maxlevels 50
#define xPrefix "RANK"
#define RANKS_Noobest 0
#define RANKS_Noob 1
#define RANKS_Newbiee 2
#define RANKS_Easy 3
#define RANKS_Normal 4
#define RANKS_Hard 5
#define RANKS_Expert 6
#define RANKS_SuperExpert 7
#define RANKS_Specialist 8
#define RANKS_Leader 9
#define RANKS_Mayor 10
#define RANKS_Pro 11
#define RANKS_SuperPro 12
#define RANKS_Heroic 13
#define RANKS_God 14
new const db_save[] = "level_xp_rank"
new level[33], xp[33], rank[33], cvars[3], g_status_sync
new const xp_num[maxlevels+1] = { 0, 20, 40, 80, 150, 150, 260, 360, 490, 790, 1700, 3000, 8000}
new const ranks_names[maxranks][]=
{
"Newbie",
"Advanced",
"Great",
"Perfect",
"Excellent",
"Killer",
"Multi Killer",
"Ultra Killer",
"The Best",
"Zombie Rider",
"The best of the BESTS"
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
// system of xp+lvl+rank
cvars[0] = register_cvar("rank_level_bonus", "10000") // Amount of money when passing level.
cvars[1] = register_cvar("rank_save_type", "2") // 1 - IP || 2 - Nick || 3 - SteamID
register_event("StatusValue", "showStatus", "be", "1=2", "2!0")
register_event("StatusValue", "hideStatus", "be", "1=1", "2=0")
register_event("DeathMsg", "xDeathMsg", "a", "1>0") // Used for xps and etc...
g_status_sync = CreateHudSyncObj()
}
/*----------------------------------------------------------------------------------------------------------------
-HUD OF THE GAME
----------------------------------------------------------------------------------------------------------------*/
public hud_status(id)
{
if(!is_user_alive(id) || !is_user_connected(id) )
return;
if(level[id] >= maxlevels)
{
static r, g, b; r = random_num(0, 255), g = random_num(0, 255), b = random_num(0, 255);
set_hudmessage(r, g, b, 0.80, -1.0, 0, 1.0, 1.1, 0.0, 0.0, -1)
show_hudmessage(id,"» Level: %d/%d^n» Rank: %s^n» XP: %d/%d", level[id], maxlevels, ranks_names[rank[id]], xp[id], xp[id])
}
else
{
set_hudmessage(255, 255, 255, 0.80, -1.0, 0, 1.0, 1.1, 0.0, 0.0, -1)
show_hudmessage(id,"» Level: %d/%d^n» Rank: %s^n» XP: %d/%d", level[id], maxlevels, ranks_names[rank[id]], xp[id], xp_num[level[id]])
}
}
/*----------------------------------------------------------------------------------------------------------------
-EVENT TO ADD XP
----------------------------------------------------------------------------------------------------------------*/
public xDeathMsg()
{
new id = read_data(1)
new hs = read_data(3)
xp[id]++
if(hs)
xp[id] += 3
check_level(id, 1)
save_data(id)
}
/*----------------------------------------------------------------------------------------------------------------
-CHECK LEVEL OF ADD ++
----------------------------------------------------------------------------------------------------------------*/
public check_level(id, sound)
{
if(!is_user_connected(id)) return PLUGIN_HANDLED;
new name[32]; get_user_name(id, name, 31)
if(level[id] < maxlevels)
{
while(xp[id] >= xp_num[level[id]])
{
level[id]++
if(sound)
{
if(level[id] == maxlevels)
{
client_print_color(id, "!g[%s] !yYour have reached the maximum level. Level maximum: !t%s!y.", xPrefix, level[id])
client_print_color(0, "!g%s !yreached the maximum level. Level maximum: !t%s!y.", name, level[id])
client_cmd(0, "spk ambience/wolfhowl02.wav")
return PLUGIN_HANDLED
}
client_print_color(0, "!g%s !yhas won !t%d !ymoney for raising a level.", name, get_pcvar_num(cvars[0]))
cs_set_user_money(id, cs_get_user_money(id) + get_pcvar_num(cvars[0]))
client_cmd(0, "spk ambience/lv_fruit1.wav")
set_ranks(id)
}
}
}
// Bug Preventions... (Back to top)
if(level[id] == maxlevels && xp[id] > xp_num[level[id]-1])
{
xp[id] = xp_num[level[id]-1]
save_data(id)
}
if(level[id] >= maxlevels)
{
level[id] = maxlevels
xp[id] = xp_num[level[id]-1]
save_data(id)
}
return PLUGIN_HANDLED
}
/*----------------------------------------------------------------------------------------------------------------
-SET THE RANK POSITION
----------------------------------------------------------------------------------------------------------------*/
public set_ranks(id)
{
if(level[id] <= 2) rank[id] = RANKS_Noobest
if(level[id] >= 2) rank[id] = RANKS_Noob
if(level[id] >= 5) rank[id] = RANKS_Newbiee
if(level[id] >= 8) rank[id] = RANKS_Easy
if(level[id] >= 11) rank[id] = RANKS_Normal
if(level[id] >= 14) rank[id] = RANKS_Hard
if(level[id] >= 17) rank[id] = RANKS_Expert
if(level[id] >= 20) rank[id] = RANKS_SuperExpert
if(level[id] >= 23) rank[id] = RANKS_Specialist
if(level[id] >= 26) rank[id] = RANKS_Leader
if(level[id] >= 29) rank[id] = RANKS_Mayor
if(level[id] >= 32) rank[id] = RANKS_Pro
if(level[id] >= 33) rank[id] = RANKS_SuperPro
if(level[id] >= 36) rank[id] = RANKS_Heroic
if(level[id] >= 43) rank[id] = RANKS_God
}
/*----------------------------------------------------------------------------------------------------------------
-SAVE LEVEL, XP AND RANK
----------------------------------------------------------------------------------------------------------------*/
public save_data(id)
{
if(!is_user_connected(id)) return PLUGIN_HANDLED;
new auth[40], data[50]
switch(get_pcvar_num(cvars[1]))
{
case 1: get_user_ip(id, auth, charsmax(auth), 1)
case 2: get_user_name(id, auth, charsmax(auth))
case 3: get_user_authid(id, auth, charsmax(auth))
}
formatex(data, charsmax(data), "%d %d", level[id], xp[id])
fvault_pset_data(db_save, auth, data)
return PLUGIN_HANDLED;
}
/*----------------------------------------------------------------------------------------------------------------
-LOAD DATA
----------------------------------------------------------------------------------------------------------------*/
public client_putinserver(id)
{
new auth[40], data[50], x1[10], x2[10]
switch(get_pcvar_num(cvars[1]))
{
case 1: get_user_ip(id, auth, charsmax(auth), 1)
case 2: get_user_name(id, auth, charsmax(auth))
case 3: get_user_authid(id, auth, charsmax(auth))
}
fvault_get_data(db_save, auth, data, charsmax(data))
parse(data, x1, charsmax(x1), x2, charsmax(x2))
level[id] = str_to_num(x1)
xp[id] = str_to_num(x2)
set_task(2.0, "set_ranks", id)
check_level(id, 0)
set_task(1.1, "hud_status", id, _, _, "b")
}
/*----------------------------------------------------------------------------------------------------------------
-SHOW XP BY LOOKING AT THE PERSON
----------------------------------------------------------------------------------------------------------------*/
public showStatus(id)
{
if(!is_user_bot(id) && is_user_connected(id))
{
new name[32], pid = read_data(2)
get_user_name(pid, name, 31)
new color1 = 0, color2 = 0
new xxx = get_user_team(id)
new xxx2 = get_user_team(pid)
new team1 = xxx == 1, team2 = xxx2 == 1
if (team2 == 1)
color1 = 255
else
color2 = 255
if (team1 == team2) // friend
{
set_hudmessage(color1, 50, color2, -1.0, 0.60, 1, 0.01, 3.0, 0.01, 0.01, -1)
ShowSyncHudMsg(id, g_status_sync, "Name: %s^nRank: %s^nLevel: %d^nXP: %d/%d", name, ranks_names[rank[pid]], level[pid], xp[pid], xp_num[level[pid]])
}
}
}
public hideStatus(id)
{
ClearSyncHud(id, g_status_sync)
}