plugin-Lite Rank System
- Код: Выделить всё
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <csstats>
#include <csx>
#include <fakemeta>
#include <fun>
#define STATUS_VALUE // Показывать звание игрока при наведении прицела (Включено по умолчанию)
#define PREFIX // Включить префиксы Админа и Випа (Включено по умолчанию, закомментируйте если хотите выключить)
#define HUD_UPD 1.0 // Через сколько секунд обновлять информер
#if defined PREFIX
#define ADMIN_PREFIX ADMIN_BAN // Флаг для префикса админа (по умолчанию флаг d)
#define VIP_PREFIX ADMIN_LEVEL_H // Флаг для префикса випа (по умолчанию флаг t)
#endif
new szMessage[191]
new iPlayerRus[33], iPlayerRusInfo[33]
#define PLUGIN "Lite Rank System"
#define VERSION "2.3"
#define AUTHOR "xoymiii"
#define TASKID_INFO 7777
new PlayerXP[33], PlayerLevel[33], g_MsgHud, levelUp[33]
#if defined STATUS_VALUE
enum _:MAX_TYPES
{
TYPE_NONE,
TYPE_RELATION,
TYPE_PLAYER
}
enum
{
LOOK_FRIEND = 1,
LOOK_ENEMY,
LOOK_HOSTAGE
}
enum _:MAX_REPLACES
{
RE_HP,
RE_RANK,
RE_NAME
}
new const Replaces[MAX_REPLACES][] =
{
"%hp%",
"%rank%",
"%name%"
}
new status_value[MAX_TYPES], gStatusText
#endif
new g_XPvalue, g_XPheadshot, g_Bomb, g_XPc4def, g_XPc4pl, g_Bonus
new g_XPv, g_XPhead, g_B, g_Def, g_Pl, g_Bon
new bool:bonus_blocked
new g_Levels
new LEVELS[22]
new const CLASSES[][] = { "I_1", "I_1", "I_2", "I_3", "I_4", "I_5", "I_6", "I_7", "I_8", "I_9", "I_10", "I_11", "I_12", "I_13", "I_14", "I_15", "I_16", "I_17", "I_18", "I_19", "I_20", "I_21" }
new const eng[][]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","{","}",":",'"',"<",">","~","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","[","]",";","'",",",".","`","?","/","@","$","^^","&"}
new const rus[][]={"Ф","И","С","В","У","А","П","Р","Ш","О","Л","Д","Ь","Т","Щ","З","Й","К","Ы","Е","Г","М","Ц","Ч","Н","Я","Х","Ъ","ж","Э","Б","Ю","Ё","ф","и","с","в","у","а","п","р","ш","о","л","д","ь","т","щ","з","й","к","ы","е","г","м","ц","ч","н","я","х","ъ","ж","э","б","ю","ё",",",".","'",";", ":","?"}
new g_oldrank[33], maxrank
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("Lite_Rank_System.txt" )
register_event("DeathMsg", "EventDeath", "a", "1>0")
register_logevent( "RoundStart", 2, "1=Round_Start" )
set_task(HUD_UPD, "Info", TASKID_INFO, "", 0, "b")
g_MsgHud = CreateHudSyncObj()
#if defined STATUS_VALUE
gStatusText = get_user_msgid("StatusText")
register_event("StatusValue", "StatusValueShow", "be")
#endif
g_XPvalue = register_cvar("lrs_xp_value", "1")
g_Bomb = register_cvar("lrs_bomb", "1")
g_XPc4def = register_cvar("lrs_xp_c4def", "4")
g_XPc4pl = register_cvar("lrs_xp_c4pl", "3")
g_XPheadshot = register_cvar("lrs_xp_hs", "2")
g_Levels = register_cvar("lrs_levels", "0 10 20 30 50 100 150 200 250 300 350 400 500 600 700 800 1000 1200 1500 2000 2500")
g_Bonus = register_cvar("lrs_bonus", "1")
register_srvcmd("lrs_lockmap", "lockmap")
new const szRegisterClmd[][] =
{
"say /rus", "LangRus",
"say /eng", "LangEng",
"say", "Say",
"say_team", "SayTeam"
}
for(new a; a < sizeof szRegisterClmd; a += 2)
register_clcmd(szRegisterClmd[a],szRegisterClmd[a + 1])
}
public plugin_cfg()
{
new configsDir[64]
get_configsdir(configsDir, 63)
server_cmd("exec %s/Lite_Rank_System.cfg", configsDir)
g_XPv = get_pcvar_num(g_XPvalue)
g_B = get_pcvar_num(g_Bomb)
g_Def = get_pcvar_num(g_XPc4def)
g_Pl = get_pcvar_num(g_XPc4pl)
g_XPhead = get_pcvar_num(g_XPheadshot)
g_Bon = get_pcvar_num(g_Bonus)
set_task(1.0, "LoadSettings")
}
///////////////// BLOCK MAP BONUS /////////////////////
public lockmap()
{
new getmap[32],map[32]
read_args(getmap,31)
remove_quotes(getmap)
get_mapname(map,31)
if(!strcmp(getmap,map))
{
bonus_blocked = true
}
else
{
bonus_blocked = false
}
}
///////////////////////////////////////////////////////////////////
/////////////////// CHAT /////////////////////
public LangRus(id)
{
if(!iPlayerRus[id])
{
iPlayerRus[id] = true
PrintMsg(id, 0, "^4Русский ^1чат активирован!")
}
else PrintMsg(id, 0, "^3Русский ^1чат уже активирован!")
}
public LangEng(id)
{
if(iPlayerRus[id])
{
iPlayerRus[id] = false
PrintMsg(id, 0, "^4Английский ^1чат активирован!")
}
else PrintMsg(id, 0, "^3Английский ^1чат уже активирован!")
}
public Say(id)
return SayHandler(id, false)
public SayTeam(id)
return SayHandler(id, true)
public SayHandler(id, bool:is_say_team)
{
read_args(szMessage, charsmax(szMessage))
remove_quotes(szMessage)
if(!szMessage[0] || szMessage[0] == '/') return PLUGIN_HANDLED_MAIN
replace_all2(szMessage, charsmax(szMessage), "%", "")
if(!iPlayerRusInfo[id])
{
if(!iPlayerRus[id])
{
iPlayerRusInfo[id] = true
PrintMsg(id, 0, "^1У Вас есть возможность писать ^3по-русски. ^1Наберите ^4/rus ^1или ^4/eng ^1для переключения.")
}
}
if(iPlayerRus[id])
{
for(new i; i < sizeof eng; i++)
replace_all2(szMessage, charsmax(szMessage), eng[i], rus[i])
}
new szFormatedMsg[191], szLen, szName[32], iAlive = is_user_alive(id), iTeam = get_pdata_int(id, 114)
get_user_name(id, szName, charsmax(szName))
if(is_say_team)
{
switch(iTeam)
{
case 1: szLen = formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg), "%s(Команде) ", iAlive ? "^1" : "^1*УБИТ* ")
case 2: szLen = formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg), "%s(Команде) ", iAlive ? "^1" : "^1*УБИТ* ")
case 3: szLen = formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg), "^1(Наблюдатель) ")
}
}
else
{
if(iTeam == 3) szLen = formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg), "^1(Наблюдатель) ")
else szLen = formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "%s", iAlive ? "^1" : "^1*УБИТ* ")
}
#if defined PREFIX
new iFlags = get_user_flags(id)
if(iFlags & ADMIN_PREFIX)
szLen += formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "%L [^3%L^1] ^3%s^1 :^4 ", LANG_PLAYER, "ADMIN", LANG_PLAYER, CLASSES[PlayerLevel[id]], szName)
else if(iFlags & VIP_PREFIX)
szLen += formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "%L [^3%L^1] ^3%s^1 : ", LANG_PLAYER, "VIP", LANG_PLAYER, CLASSES[PlayerLevel[id]], szName)
else
szLen += formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "[^3%L^1] ^3%s^1 : ", LANG_PLAYER, CLASSES[PlayerLevel[id]], szName)
#else
szLen += formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "[^3%L^1] ^3%s^1 : ", LANG_PLAYER, CLASSES[PlayerLevel[id]], szName)
#endif
szLen += formatex(szFormatedMsg[szLen], charsmax(szFormatedMsg) - szLen, "%s", szMessage)
static players[32], pcount; get_players(players, pcount, "c")
if(is_say_team)
{
for(new i; i < pcount; i++)
if(get_user_flags(players[i]) & ADMIN_BAN || (iTeam == get_user_team(players[i]) && iAlive == is_user_alive(players[i])))
PrintMsg(players[i], id, szFormatedMsg)
}
else
{
for(new i; i < pcount; i++)
PrintMsg(players[i], id, szFormatedMsg)
}
return PLUGIN_HANDLED
}
stock PrintMsg(const iReceiver, const iSender, const szMessage[], any:...)
{
new szMsg[191]
vformat(szMsg, charsmax(szMsg), szMessage, 4)
message_begin(MSG_ONE_UNRELIABLE, 76, _, iReceiver)
write_byte(iSender ? iSender : iReceiver)
write_string(szMsg)
message_end()
}
stock replace_all2(string[], len, const what[], const with[])
{
new pos
if((pos = contain(string, what)) == -1) return 0
new total, with_len = strlen(with), diff = strlen(what) - with_len, total_len = strlen(string), temp_pos
while(total_len + with_len < len && replace(string[pos], len - pos, what, with) != 0)
{
total++
pos += with_len
total_len -= diff
if (pos >= total_len) break
temp_pos = contain(string[pos], what)
if (temp_pos == -1) break
pos += temp_pos
}
return total
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////// RANK, LEVEL i td... ////////////////////
public LoadSettings()
{
new i, LVL[22][16], cvLevels[256]
get_pcvar_string(g_Levels, cvLevels, 255)
trim(cvLevels)
parse(cvLevels, LVL[0], 15, LVL[1], 15, LVL[2], 15, LVL[3], 15, LVL[4], 15, LVL[5], 15, LVL[6], 15, LVL[7], 15, LVL[8], 15, LVL[9], 15, LVL[10], 15, LVL[11], 15, LVL[12], 15, LVL[13], 15, LVL[14], 15, LVL[15], 15, LVL[16], 15, LVL[17], 15, LVL[18], 15, LVL[19], 15, LVL[20], 15, LVL[21], 15)
for (i = 0; i < 21; i++)
LEVELS[i+1] = str_to_num(LVL[i])
return PLUGIN_HANDLED
}
public checkLvl(id)
{
new Name[32]
get_user_name(id, Name, 31)
if(id > 0 && id < 33)
{
if (PlayerLevel[id] <= 0)
PlayerLevel[id] = 1
if (PlayerLevel[id] < 21)
{
while(PlayerXP[id] >= LEVELS[PlayerLevel[id]+1])
{
PlayerLevel[id]++
levelUp[id] = 1
ChatColor(0, "%L %L", LANG_PLAYER,"LRS_TAG", LANG_PLAYER,"NEW_LEVEL", Name, LANG_PLAYER,CLASSES[PlayerLevel[id]])
}
}
}
}
public EventDeath()
{
new iKiller = read_data(1)
new iVictim = read_data(2)
if(iKiller != iVictim && get_pdata_int(iKiller, 114) != get_pdata_int(iVictim, 114) && is_user_connected(iKiller) && PlayerLevel[iKiller] < 21)
{
if (g_XPhead > 1)
{
if(read_data(3))
PlayerXP[iKiller] += g_XPv * g_XPhead
else
PlayerXP[iKiller] += g_XPv
}
else
PlayerXP[iKiller] += g_XPv
checkLvl(iKiller)
}
return PLUGIN_CONTINUE
}
public bomb_explode(id)
{
if(g_Pl < 1 || g_B != 1)
return
PlayerXP[id] += g_Pl
checkLvl(id)
}
public bomb_defused(id)
{
if(g_Def < 1 || g_B != 1)
return
PlayerXP[id] += g_Def
checkLvl(id)
}
public client_putinserver(id)
set_task(1.0, "load_client_data", id)
public load_client_data(id)
{
if(!is_user_connected(id))
return PLUGIN_HANDLED
new stats[8], bodyhits[8], stats2[4]
get_user_stats(id, stats, bodyhits)
get_user_stats2(id, stats2)
if (g_XPhead > 1 && g_B != 0)
PlayerXP[id] = ((stats[2] * g_XPhead + ((stats[0] - stats[2]) * g_XPv)) + (stats2[1] * g_Def + stats2[3] * g_Pl))
else if (g_XPhead <= 1 && g_B != 0)
PlayerXP[id] = (stats[0] * g_XPv + (stats2[1] * g_Def + stats2[3] * g_Pl))
else if (g_XPhead > 1 && g_B == 0)
PlayerXP[id] = (stats[2] * g_XPhead + ((stats[0] - stats[2]) * g_XPv))
else
PlayerXP[id] = stats[0] * g_XPv
for(new i = 1; i <= 21; i++)
{
if (i < 21)
{
if (PlayerXP[id] >= LEVELS[i] && PlayerXP[id] < LEVELS[i+1])
PlayerLevel[id] = i
}
else
{
if (PlayerXP[id] >= LEVELS[21])
PlayerLevel[id] = 21
}
}
return PLUGIN_HANDLED
}
///////////////////////////////////////////////////////////////////////////
#if defined STATUS_VALUE
public StatusValueShow(id)
{
new num = read_data(1)
if( num <= 0 || num >= MAX_TYPES )
return
new update = status_value[num] = read_data(2)
new live = is_user_alive(id)
switch( num )
{
case TYPE_RELATION:
{
if( !update && live )
{
message_begin( MSG_ONE_UNRELIABLE, gStatusText, _, id )
write_byte( 0 )
write_string( "" )
message_end()
}
}
case TYPE_PLAYER:
{
if( live )
{
new message[192]
switch( status_value[TYPE_RELATION] )
{
case LOOK_FRIEND:
{
copy(message, charsmax(message), "Друг: %name% HP: %hp% Звание: %rank%")
}
case LOOK_ENEMY:
{
copy(message, charsmax(message), "Враг: %name% Звание: %rank%")
}
case LOOK_HOSTAGE:
{
return
}
}
EditMessage( message, update, true, get_user_health( update ) )
message_begin( MSG_ONE_UNRELIABLE, gStatusText, _, id )
write_byte( 0 )
write_string( message )
message_end()
}
}
}
}
EditMessage( message[192], player, bool:status_text, hp )
{
new temp[35]
if( is_user_alive( player ) )
{
for( new i; i<MAX_REPLACES; i++ )
{
switch( i )
{
case RE_HP:
{
num_to_str(hp, temp, charsmax(temp))
}
case RE_RANK:
{
format(temp, charsmax(temp), "%L", LANG_PLAYER,CLASSES[PlayerLevel[player]])
}
case RE_NAME:
{
if(status_text)
copy(temp, charsmax(temp), "%p2")
else
get_user_name(player, temp, charsmax(temp))
}
default:
{
copy(temp, charsmax(temp), "")
}
}
replace(message, charsmax(message), Replaces[i], temp)
}
}
trim(message)
}
#endif
public RoundStart()
{
maxrank = get_statsnum()
if(g_Bon == 1)
{
if(!bonus_blocked)
{
static Players[32], Count
new id
get_players(Players, Count, "ach")
for(new i = 0; i < Count; i++)
{
id = Players[i]
if(levelUp[id] == 1)
{
GetWeapon(id)
levelUp[id] = 0
}
}
}
}
}
public GetWeapon(id)
{
new szText[700 char]
formatex( szText, charsmax( szText ), "%L", id, "TITLE")
new menu = menu_create( szText, "gw_menu" )
formatex( szText, charsmax( szText ), "AK47")
menu_additem( menu, szText, "1", 0 )
formatex( szText, charsmax( szText ), "M4A1")
menu_additem( menu, szText, "2", 0 )
formatex( szText, charsmax( szText ), "AWP")
menu_additem( menu, szText, "3", 0 )
formatex( szText, charsmax( szText ), "FAMAS")
menu_additem( menu, szText, "4", 0 )
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL )
menu_display( id, menu,0)
return PLUGIN_CONTINUE
}
public gw_menu(id,menu,item)
{
if( item == MENU_EXIT )
{
return PLUGIN_HANDLED
}
new data[ 6 ], iName[ 64 ], access, callback
menu_item_getinfo( menu, item, access, data, charsmax( data ), iName, charsmax( iName ), callback )
new key = str_to_num( data )
switch( key )
{
case 1:
{
give_item(id,"weapon_ak47")
cs_set_user_bpammo( id, CSW_AK47, 90)
}
case 2:
{
give_item(id,"weapon_m4a1")
cs_set_user_bpammo( id, CSW_M4A1, 90)
}
case 3:
{
give_item(id,"weapon_awp")
cs_set_user_bpammo( id, CSW_AWP, 30)
}
case 4:
{
give_item(id,"weapon_famas")
cs_set_user_bpammo( id, CSW_FAMAS, 90)
}
}
give_item(id,"weapon_smokegrenade")
give_item(id,"weapon_flashbang")
give_item(id,"weapon_hegrenade")
cs_set_user_armor(id, 100, CS_ARMOR_VESTHELM)
ChatColor(id, "%L %L", LANG_PLAYER,"LRS_TAG", LANG_PLAYER,"BONUS")
return PLUGIN_HANDLED
}
////////////////// INFORMER ///////////////////////
public Info()
{
static Players[32], Count, buffer[192], len
new id, id2, Name2[32], live, osef[8]
get_players(Players, Count, "ch")
for(new i = 0; i < Count; i++)
{
id = Players[i]
live = is_user_alive(id)
id2 = pev(id, pev_iuser2)
get_user_name(id2, Name2, 31)
g_oldrank[id] = get_user_stats(id, osef, osef)
if(!live)
{
if(id2 > 0)
{
if(PlayerLevel[id2] < 21)
{
len = format(buffer, charsmax(buffer), "%L: %s", LANG_PLAYER,"A_NAME", Name2)
len += format(buffer[len], charsmax(buffer) - len, "^n%L:", LANG_PLAYER,"ZVANIE")
len += format(buffer[len], charsmax(buffer) - len, " %L", LANG_PLAYER,CLASSES[PlayerLevel[id2]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d", LANG_PLAYER,"PL_XP",PlayerXP[id2])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d", LANG_PLAYER,"RANK", g_oldrank[id2])
}
else
{
len = format(buffer, charsmax(buffer), "%L: %s", LANG_PLAYER,"A_NAME", Name2)
len += format(buffer[len], charsmax(buffer) - len, "^n%L:",LANG_PLAYER,"ZVANIE")
len += format(buffer[len], charsmax(buffer) - len, " %L",LANG_PLAYER,CLASSES[PlayerLevel[id2]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %L",LANG_PLAYER,"PL_XP", LANG_PLAYER,"PL_MAX")
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d", LANG_PLAYER,"RANK", g_oldrank[id2])
}
}
else
{
if(PlayerLevel[id] < 21)
{
len = format(buffer, charsmax(buffer) - len, "%L: %L", LANG_PLAYER,"ZVANIE", LANG_PLAYER,CLASSES[PlayerLevel[id]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d",LANG_PLAYER,"PL_XP",PlayerXP[id])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d", LANG_PLAYER,"RANK", g_oldrank[id])
}
else
{
len = format(buffer, charsmax(buffer) - len, "%L: %L", LANG_PLAYER,"ZVANIE", LANG_PLAYER,CLASSES[PlayerLevel[id]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L",LANG_PLAYER,"PL_MAX")
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d", LANG_PLAYER,"RANK", g_oldrank[id])
}
}
}
else
{
if((PlayerLevel[id] < 21) && live)
{
len = format(buffer, charsmax(buffer), "%L", LANG_PLAYER,CLASSES[PlayerLevel[id]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d %L %d", LANG_PLAYER,"PL_XP",PlayerXP[id], LANG_PLAYER,"IZ", LEVELS[PlayerLevel[id]+1])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d %L %d", LANG_PLAYER,"RANK", g_oldrank[id], LANG_PLAYER,"IZ", maxrank)
}
else
{
len = format(buffer, charsmax(buffer), "%L",LANG_PLAYER,CLASSES[PlayerLevel[id]])
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %L",LANG_PLAYER,"PL_XP", LANG_PLAYER,"PL_MAX")
len += format(buffer[len], charsmax(buffer) - len, "^n%L: %d %L %d", LANG_PLAYER,"RANK", g_oldrank[id], LANG_PLAYER,"IZ", maxrank)
}
}
set_hudmessage(255, 255, 255, 0.01, 0.19, 0, 0.0, HUD_UPD, _, _, -1)
ShowSyncHudMsg(id, g_MsgHud, "%s", buffer)
}
return PLUGIN_CONTINUE
}
/////////////////////////////////////////////////////////////////
////////////////// STOCK //////////////////////
stock ChatColor(const id, const input[], any:...)
{
new count = 1, players[32]
static msg[192]
vformat(msg, 191, input, 3)
replace_all(msg, 191, "!g", "^4") // Green Color
replace_all(msg, 191, "!y", "^1") // Default Color
replace_all(msg, 191, "!t", "^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()
}
}
}
}
/////////////////////////////////////////////////////////////