Участник
Пользователь
- Сообщения
- 272
- Реакции
- 14
Hi. How to add rank name prefix before nick in chat. I try but nothing comes up .... I don't know why.
I added this as you can see:
Код:
#define AUTHOR "AcE"
#define VERSION "1.5"
#define PLUGIN "Lite Rank System"
#define LASTUPDATE "4, December (12), 2017"
#include <amxmodx>
#include <reapi>
#if AMXX_VERSION_NUM < 183
#include <colorchat>
#define argbreak strbreak
#define client_disconnected client_disconnect
#endif
//#define CS_MYSQL
//#define CS_MYSQL_HUD_SKILL
//#define CSSTATSX_SQL
//#define CSSTATSX_SQL_HUD_SKILL
#define HUD_POSITION
//#define STATUS_VALUE
#if defined CS_MYSQL
native csstats_get_statsnum()
native csstats_get_user_stats(id, stats[22])
#if defined CS_MYSQL_HUD_SKILL
#define FRAGS 0
#define DEATHS 1
native statsx_get_skill(stats[22], string[] = "", len = 0)
#endif
#endif
#if defined CSSTATSX_SQL
native get_statsnum_sql()
native get_user_stats_sql(index, stats[8], bodyhits[8])
#if defined CSSTATSX_SQL_HUD_SKILL
native get_user_skill(player, &Float:skill)
new const g_skill_letters[][] = {"L-", "L", "L+", "M-", "M", "M+", "H-", "H", "H+", "P-", "P", "P+", "G"}
new Float:g_skill_opt[sizeof g_skill_letters]
#endif
#endif
#if !defined CS_MYSQL && !defined CSSTATSX_SQL
#include <csstats>
#endif
#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
enum _:udata
{
level, exp, informer
}
new UserData[33][udata]
new Float:HudUpdateInterval
new g_Cvar[9], LEVELS[22], g_Connected
#define IsUserValid(%1) (1 <= %1 <= 32)
#define get_bit(%1,%2) (%1 & (1 << (%2 & 31)))
#define set_bit(%1,%2) (%1 |= (1 << (%2 & 31)))
#define reset_bit(%1,%2) (%1 &= ~(1 << (%2 & 31)))
new const CLASSES[][] =
{
"", "Курсант", "Рядовой", "Ефрейтор",
"Мл. Сержант", "Сержант", "Ст. Сержант",
"Старшина", "Прапорщик", "Ст. Прапорщик",
"Мл. Лейтенант", "Лейтенант", "Ст. Лейтенант",
"Капитан", "Майор", "Подполковник",
"Полковник", "Генерал-майор", "Генерал-лейтенант",
"Генерал-полковник", "Генерал армии", "Маршал РФ"
}
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("lrs_version", VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)
#if defined STATUS_VALUE
gStatusText = get_user_msgid("StatusText")
register_event("StatusValue", "StatusValueShow", "be")
#endif
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed_Post", true)
register_clcmd("say /lrshud", "informer_switch", 0, "switch experience informer on/off")
g_Cvar[1] = register_cvar("lrs_add_exp", "1")
g_Cvar[2] = register_cvar("lrs_add_exp_hs", "2")
g_Cvar[3] = register_cvar("lrs_levels", "0 20 40 60 100 150 200 300 400 600 1000 1500 2100 2700 3400 4200 5100 5900 7000 10000 15000")
g_Cvar[4] = register_cvar("lrs_hud_exp_type", "1")
g_Cvar[5] = register_cvar("lrs_hud_xypos", "0.01 0.22")
g_Cvar[6] = register_cvar("lrs_hud_color", "50 255 50")
g_Cvar[7] = register_cvar("lrs_hud_random_color", "0")
g_Cvar[8] = register_cvar("lrs_hud_update", "1.0")
HudUpdateInterval = get_pcvar_float(g_Cvar[8])
set_task(HudUpdateInterval, "lrs_informer", _, _, _, "b")
}
public plugin_cfg()
{
new LVL[22][16], cvLevels[256]
get_pcvar_string(g_Cvar[3], 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 (new i = 0; i < 21; i ++)
LEVELS[i +1] = str_to_num(LVL[i])
#if defined CSSTATSX_SQL
#if defined CSSTATSX_SQL_HUD_SKILL
new levelString[512], stPos, ePos, rawPoint[20], cnt
new g_pCvarSkill = get_cvar_pointer("aes_statsx_skill")
get_pcvar_string(g_pCvarSkill, levelString, charsmax(levelString))
do {
ePos = strfind(levelString[stPos], " ")
formatex(rawPoint, ePos, levelString[stPos])
g_skill_opt[cnt] = str_to_float(rawPoint)
stPos += ePos + 1; cnt ++
if (cnt > sizeof g_skill_letters - 1)
break
} while(ePos != -1)
#endif
#endif
server_print(""); server_print(" %s Copyright (c) 2017 %s", PLUGIN, AUTHOR)
server_print(" Version %s build on %s", VERSION, LASTUPDATE); server_print("")
}
public client_putinserver(id)
{
set_bit(g_Connected, id)
arrayset(UserData[id], 0, udata)
set_task(0.9, "load_client_data", id + 555)
}
public client_disconnected(id)
reset_bit(g_Connected, id)
public load_client_data(index)
{
new id = index - 555
if (!get_bit(g_Connected, id)) return
#if defined CS_MYSQL
new st[22]
csstats_get_user_stats(id, st)
#endif
#if defined CSSTATSX_SQL
new st[8], bh[8]
get_user_stats_sql(id, st, bh)
#endif
#if !defined CS_MYSQL && !defined CSSTATSX_SQL
new st[8], bh[8]
get_user_stats(id, st, bh)
#endif
if (UserData[id][level] <= 1)
UserData[id][level] = 1
if (UserData[id][exp] < 0)
UserData[id][exp] = 0
if (get_pcvar_num(g_Cvar[2]) > 1)
{
new not_hs_num = st[0] - st[2]
new hs_points = st[2] * get_pcvar_num(g_Cvar[2])
new not_hs_points = not_hs_num * get_pcvar_num(g_Cvar[1])
UserData[id][exp] = hs_points + not_hs_points
}
else
{
UserData[id][exp] = (st[0] * get_pcvar_num(g_Cvar[1]))
}
for (new i = 1; i <= 21; i ++)
{
if (i < 21)
{
if (UserData[id][exp] >= LEVELS[i] && UserData[id][exp] < LEVELS[i +1])
UserData[id][level] = i
else if (UserData[id][exp] >= LEVELS[21])
UserData[id][level] = 21
}
}
}
public CBasePlayer_Killed_Post(const victim, killer, iGib)
{
if (!get_bit(g_Connected, killer))
return
if (!IsUserValid(killer) || !IsUserValid(victim) || killer == victim || get_member(victim, m_bKilledByBomb))
return
static szName[32]
get_entvar(killer, var_netname, szName, 31)
if (UserData[killer][level] < 21)
{
static TempEXP
TempEXP = get_member(victim, m_bHeadshotKilled) ? get_pcvar_num(g_Cvar[2]) : get_pcvar_num(g_Cvar[1])
UserData[killer][exp] += TempEXP
if (UserData[killer][exp] >= LEVELS[UserData[killer][level] +1])
{
UserData[killer][level] ++
client_cmd(0, "spk events/task_complete")
client_print_color(0, print_team_default, "^1[^4LRS^1] Боец ^3%s ^1получил новое звание - ^4%s^1. Поздравляем!", szName, CLASSES[UserData[killer][level]])
}
}
}
public lrs_informer()
{
static id, target
static buffer[192], len, SyncHudMsg
if (!SyncHudMsg) SyncHudMsg = CreateHudSyncObj()
for (id = 1; id <= 32; id ++)
{
if (!get_bit(g_Connected, id)) continue
if (UserData[id][informer]) continue
ClearSyncHud(id, SyncHudMsg)
target = get_entvar(id, var_iuser2)
#if defined HUD_POSITION
static g_rank[33], g_maxrank
#if defined CS_MYSQL
static st[22]
g_maxrank = csstats_get_statsnum()
g_rank[id] = csstats_get_user_stats(id, st)
g_rank[target] = csstats_get_user_stats(target, st)
#endif
#if defined CSSTATSX_SQL
static st[8], bh[8]
g_maxrank = get_statsnum_sql()
g_rank[id] = get_user_stats_sql(id, st, bh)
g_rank[target] = get_user_stats_sql(target, st, bh)
#endif
#if !defined CS_MYSQL && !defined CSSTATSX_SQL
static st[8], bh[8]
g_maxrank = get_statsnum()
g_rank[id] = get_user_stats(id, st, bh)
g_rank[target] = get_user_stats(target, st, bh)
#endif
#endif
if (is_user_alive(id))
{
len = format(buffer, charsmax(buffer), "Звание: %s", CLASSES[UserData[id][level]])
if (UserData[id][level] < 21)
{
if (get_pcvar_num(g_Cvar[4]) == 0)
len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: [%d/%d]", UserData[id][exp], LEVELS[UserData[id][level] +1])
else len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: [%d/%d] [+%d]", UserData[id][exp], LEVELS[UserData[id][level] +1], (LEVELS[UserData[id][level] +1] - UserData[id][exp]))
}
else
{
len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: Максимальный")
}
#if defined CS_MYSQL
#if defined CS_MYSQL_HUD_SKILL
new iRank = csstats_get_user_stats(id, st)
if (iRank > 0)
{
if (st[FRAGS] && st[DEATHS])
{
new szSkill[3], iSkill = statsx_get_skill(st, szSkill, charsmax(szSkill))
len += format(buffer[len], charsmax(buffer) - len, "^nСкилл: [%s|%d]", szSkill, iSkill)
}
}
#endif
#endif
#if defined CSSTATSX_SQL
#if defined CSSTATSX_SQL_HUD_SKILL
new Float:szSkill, szSkill_id
get_user_skill(id, szSkill)
szSkill_id = aes_statsx_get_skill_id(szSkill)
len += format(buffer[len], charsmax(buffer) - len, "^nСкилл: [%s|%.0f]", g_skill_letters[szSkill_id], szSkill)
#endif
#endif
#if defined HUD_POSITION
len += format(buffer[len], charsmax(buffer) - len, "^nПозиция: [%d из %d]", g_rank[id], g_maxrank)
#endif
}
else
{
if (target > 0 && !is_user_alive(id))
{
static szName[32]
get_entvar(target, var_netname, szName, 31)
len = format(buffer, charsmax(buffer), "Ник: %s", szName)
len += format(buffer[len], charsmax(buffer) - len, "^nЗвание: %s", CLASSES[UserData[target][level]])
if (UserData[target][level] < 21)
{
if (get_pcvar_num(g_Cvar[4]) == 0)
len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: [%d/%d]", UserData[target][exp], LEVELS[UserData[target][level] +1])
else len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: [%d/%d] [+%d]", UserData[target][exp], LEVELS[UserData[target][level] +1], (LEVELS[UserData[target][level] +1] - UserData[target][exp]))
}
else
{
len += format(buffer[len], charsmax(buffer) - len, "^nОпыт: Максимальный")
}
#if defined CS_MYSQL
#if defined CS_MYSQL_HUD_SKILL
new iRank = csstats_get_user_stats(target, st)
if (iRank > 0)
{
if (st[FRAGS] && st[DEATHS])
{
new szSkill[3], iSkill = statsx_get_skill(st, szSkill, charsmax(szSkill))
len += format(buffer[len], charsmax(buffer) - len, "^nСкилл: [%s|%d]", szSkill, iSkill)
}
}
#endif
#endif
#if defined CSSTATSX_SQL
#if defined CSSTATSX_SQL_HUD_SKILL
new Float:szSkill, szSkill_id
get_user_skill(target, szSkill)
szSkill_id = aes_statsx_get_skill_id(szSkill)
len += format(buffer[len], charsmax(buffer) - len, "^nСкилл: [%s|%.0f]", g_skill_letters[szSkill_id], szSkill)
#endif
#endif
#if defined HUD_POSITION
len += format(buffer[len], charsmax(buffer) - len, "^nПозиция: [%d из %d]", g_rank[target], g_maxrank)
#endif
}
}
static r, g, b, Float:x, Float:y
HudMsgPos(x, y); HudMsgColor(g_Cvar[6], r, g, b)
if (get_pcvar_num(g_Cvar[7]) == 0)
set_hudmessage(r, g, b, x, y, 0, 0.0, HudUpdateInterval, _, _, -1)
else set_hudmessage(random_num(0, 255), random_num(0, 255), random_num(0, 255), x, y, 0, 0.0, HudUpdateInterval, _, _, -1)
ShowSyncHudMsg(id, SyncHudMsg, "%s", buffer)
}
}
public informer_switch(id)
{
if (!get_bit(g_Connected, id)) return
if (UserData[id][informer])
{
UserData[id][informer] = 0
client_cmd(id, "spk fvox/activated")
client_print_color(id, print_team_default, "^1[^4LRS^1] ^3Информер звания ^1<^4Включён^1>")
}
else
{
UserData[id][informer] = 1
client_cmd(id, "spk fvox/deactivated")
client_print_color(id, print_team_default, "^1[^4LRS^1] ^3Информер звания ^1<^4Выключен^1>")
}
}
#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)
switch(num)
{
case TYPE_RELATION:
{
if (!update && is_user_alive(id))
{
message_begin(MSG_ONE_UNRELIABLE, gStatusText, _, id)
write_byte(0); write_string(""); message_end()
}
}
case TYPE_PLAYER:
{
if (is_user_alive(id))
{
new message[192]
switch(status_value[TYPE_RELATION])
{
case LOOK_FRIEND:
{
copy(message, charsmax(message), "Друг: %name% ХП: %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[64]
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), "%s", CLASSES[UserData[player][level]])
}
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 plugin_natives()
register_native("lrs_get_level_name", "_lrs_get_level_name")
public _lrs_get_level_name(plugin, params)
{
new buffer[192]
new id = get_param(1)
new len = get_param(3)
format(buffer, len, "%s", CLASSES[UserData[id][level]])
set_string(2, buffer, len)
}
stock HudMsgPos(&Float:x, &Float:y)
{
static coords[16], piece[10]
get_pcvar_string(g_Cvar[5], coords, 15)
argbreak(coords, piece, 9, coords, 15)
x = str_to_float(piece)
y = str_to_float(coords)
}
stock HudMsgColor(cvar, &r, &g, &b)
{
static color[16], piece[5]
get_pcvar_string(cvar, color, 15)
argbreak(color, piece, 4, color, 15)
r = str_to_num(piece)
argbreak(color, piece, 4, color, 15)
g = str_to_num(piece)
b = str_to_num(color)
}
#if defined CSSTATSX_SQL
#if defined CSSTATSX_SQL_HUD_SKILL
aes_statsx_get_skill_id(Float:szSkill)
{
for (new i; i < sizeof g_skill_opt; i ++)
{
if (szSkill < g_skill_opt[i])
{
return i
}
}
return (sizeof g_skill_opt - 1)
}
#endif
#endif
public handleSayText(msgId,msgDest,msgEnt){
new id = get_msg_arg_int(1);
if(is_user_connected(id)){
new szTmp[256],szTmp2[256];
get_msg_arg_string(2,szTmp, charsmax(szTmp))
new szPrefix[64];
formatex(szPrefix,charsmax(szPrefix),"^1[^4%s^1]", CLASSES[UserData[id][level]]);
if(!equal(szTmp,"#Cstrike_Chat_All")){
add(szTmp2,charsmax(szTmp2),szPrefix);
add(szTmp2,charsmax(szTmp2)," ");
add(szTmp2,charsmax(szTmp2),szTmp);
}
else{
add(szTmp2,charsmax(szTmp2),szPrefix);
add(szTmp2,charsmax(szTmp2)," ^3%s1 ^1: %s2");
}
set_msg_arg_string(2,szTmp2);
}
return PLUGIN_CONTINUE;
}
29 Сен 2022
Код:
public handleSayText(msgId,msgDest,msgEnt){
new id = get_msg_arg_int(1);
if(is_user_connected(id)){
new szTmp[256],szTmp2[256];
get_msg_arg_string(2,szTmp, charsmax(szTmp))
new szPrefix[64];
formatex(szPrefix,charsmax(szPrefix),"^1[^4%s^1]", CLASSES[UserData[id][level]]);
if(!equal(szTmp,"#Cstrike_Chat_All")){
add(szTmp2,charsmax(szTmp2),szPrefix);
add(szTmp2,charsmax(szTmp2)," ");
add(szTmp2,charsmax(szTmp2),szTmp);
}
else{
add(szTmp2,charsmax(szTmp2),szPrefix);
add(szTmp2,charsmax(szTmp2)," ^3%s1 ^1: %s2");
}
set_msg_arg_string(2,szTmp2);
}
return PLUGIN_CONTINUE;
}