всем привет, в данном плагине
чат отображается s1 : s2, кто может то исправить???
а то очень нужен этот плагин
C++:
/*
* Prefix Manager v. 0.1
* by serfreeman1337 [URL='http://gf.hldm.org/']serfreeman1337[/URL]
*/
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Prefix Manager"
#define VERSION "0.1"
#define AUTHOR "serfreeman1337"
// префикс по флагам
#define USE_PREFIX_ACCESS
// префикс для топ игроков
#define USE_PREFIX_TOP // cstrike only
// префикс по steamid
#define USE_PREFIX_STEAMID
// префикс по клиенту
#define USE_PREFIX_DPROTO // no steam only
// префикс звания из AES
//#define USE_PREFIX_AES
#if defined USE_PREFIX_TOP
#include <csstats>
#endif
#if defined USE_PREFIX_AES
#include <aes_main>
#endif
enum _:cvars {
CVAR_MAX_PREFIXES
}
new cvar[cvars]
enum _:prfx {
PREFIX_ALL,
#if defined USE_PREFIX_ACCESS
PREFIX_ACCESS,
#endif
#if defined USE_PREFIX_TOP
PREFIX_TOP,
#endif
#if defined USE_PREFIX_STEAMID
PREFIX_STEAMID,
#endif
#if defined USE_PREFIX_DPROTO
PREFIX_DPROTO,
#endif
#if defined USE_PREFIX_AES
PREFIX_AES,
#endif
PREFIX_END
}
new prefixWayId[prfx][] = {
"all",
#if defined USE_PREFIX_ACCESS
"access",
#endif
#if defined USE_PREFIX_TOP
"top",
#endif
#if defined USE_PREFIX_STEAMID
"steamid",
#endif
#if defined USE_PREFIX_DPROTO
"dproto",
#endif
#if defined USE_PREFIX_AES
"aes",
#endif
""
}
enum _:prefixDataStruct {
PREFIX_ID,
PREFIX_POS,
PREFIX_DATA[128],
bool:pREFIX_FORMAT,
PREFIX_NAME[128],
PREFIX_WEIGHT,
PREFIX_GROUP,
Array:pREFIX_SKIP,
bool:pREFIX_UNCOUNT
}
new Array:prefixes
new prefixCount
new g_maxplayers
new teamMsgString[][] = {
"#Cstrike_Chat_CT",
"#Cstrike_Chat_T",
"#Cstrike_Chat_CT_Dead",
"#Cstrike_Chat_T_Dead",
"#Cstrike_Chat_Spec"
}
new Trie:teamMsgPointers
#if defined USE_PREFIX_STEAMID
new steamIdPrefix[33]
new Trie:prefixForId
#endif
#if defined USE_PREFIX_DPROTO
new pDprotoProvider
new playerClient[33]
#endif
new prefixMax
public plugin_init(){
register_plugin(PLUGIN,VERSION,AUTHOR)
// Максимальное кол-во префиксов
cvar[CVAR_MAX_PREFIXES] = register_cvar("pm_max_count","2")
}
/*
* загрузка конфигурации
*/
public plugin_cfg(){
new configFile[256]
get_configsdir(configFile,255)
add(configFile,255,"/prefixManager.ini")
new f = fopen(configFile,"rt")
if(!f){ // не удалось открыть конфиг-файл
log_amx("config file not found")
return PLUGIN_CONTINUE
}
prefixes = ArrayCreate(prefixDataStruct,1)
new buf[512]
new tmpWay[20],tmpData[128],tmpFormat[10],tmpName[128],tmpWeight[10],tmpSkip[20],tmpUncount[2],tmpGroup[10],datPrefixId
new prefixInfo[prefixDataStruct],bool:isTeamFormat,prefixNum
// читаем содержимое файла
while(!feof(f)){
fgets(f,buf,511)
trim(buf)
// пропускаем пустые строки и комментарии
if(!buf[0] || buf[0] == ';')
continue
// очищаем предыдущий результат
tmpWay[0] = 0 // указатель префикса
tmpData[0] = 0 // доп. информация для префикса
tmpFormat[0] = 0 // тип модифакции сообщений префиксом
tmpName[0] = 0 // название этого префикса
tmpSkip[0] = 0 // пропуск префиксов
tmpUncount[0] = 0 // не считать данный префикс
tmpGroup[0] = 0 // группа префикса
datPrefixId = -1 // ID префикса
parse(buf,tmpWay,19,tmpData,127,tmpFormat,9,tmpName,127,tmpWeight,9,tmpSkip,19,tmpUncount,1,tmpGroup,9)
// проверяем наличие признака префикса
for(new i ; i < prfx - 1 ; ++i){
if(strcmp(tmpWay,prefixWayId[I]) != 0)
continue
datPrefixId = i // нашли ID префикса
}
// префикс не найден, пероходим к следующей строке
if(datPrefixId == -1)
continue
arrayset(prefixInfo,0,prefixDataStruct)
// задаем параметры префикса
prefixInfo[PREFIX_ID] = datPrefixId // ID префикса
prefixInfo[PREFIX_POS] = prefixNum++
prefixInfo[PREFIX_FORMAT] = strcmp(tmpFormat,"prefix") == 0 ? false : true // форматирование чата или просто добавление префикса
prefixInfo[PREFIX_WEIGHT] = str_to_num(tmpWeight) // вес
prefixInfo[PREFIX_GROUP] = tmpGroup[0] ? str_to_num(tmpGroup) : 1
prefixInfo[PREFIX_UNCOUNT] = str_to_num(tmpUncount) ? true : false
// строим массив с префиксами для пропуска
if(tmpSkip[0]){
new stPos,ePos,rawPoint[20]
prefixInfo[PREFIX_SKIP] = _:ArrayCreate(1,1)
do {
ePos = strfind(tmpSkip[stPos],",")
formatex(rawPoint,ePos,tmpSkip[stPos])
ArrayPushCell(prefixInfo[PREFIX_SKIP] ,str_to_num(rawPoint))
stPos += ePos + 1
} while (ePos != -1)
}
replace_all2(tmpName,127,"^^1","^1")
replace_all2(tmpName,127,"^^2","^2")
replace_all2(tmpName,127,"^^3","^3")
replace_all2(tmpName,127,"^^4","^4")
replace_all2(tmpName,127,"%","%%")
// доп. обработка согласно префиксам
switch(datPrefixId){
case PREFIX_ALL: {
}
#if defined USE_PREFIX_ACCESS
case PREFIX_ACCESS:
prefixInfo[PREFIX_DATA][0] = read_flags(tmpData) // считаем бит сумму флагов
#endif
#if defined USE_PREFIX_TOP
case PREFIX_TOP:
prefixInfo[PREFIX_DATA][0] = str_to_num(tmpData)
#endif
#if defined USE_PREFIX_STEAMID
case PREFIX_STEAMID:{
if(prefixForId == Invalid_Trie)
prefixForId = TrieCreate()
prefixInfo[PREFIX_DATA][0] = prefixCount
TrieSetCell(prefixForId,tmpData,prefixCount)
}
#endif
#if defined USE_PREFIX_DPROTO
case PREFIX_DPROTO:
prefixInfo[PREFIX_DATA][0] = str_to_num(tmpData)
#endif
#if defined USE_PREFIX_AES
case PREFIX_AES:{}
#endif
default: continue
}
if(prefixInfo[PREFIX_FORMAT] && contain(tmpName,"#team#") != -1)
isTeamFormat = true
copy(prefixInfo[PREFIX_NAME],127,tmpName)
ArrayPushArray(prefixes,prefixInfo)
prefixCount ++
}
fclose(f)
if(!prefixCount)
return PLUGIN_CONTINUE
// сортировка префиксов по весу
#if AMXX_VERSION_NUM < 183
ArraySort(prefixes,"SortPrefixesByWeight")
#else
ArraySortEx(prefixes,"SortPrefixesByWeight")
#endif
if(isTeamFormat){
teamMsgPointers = TrieCreate()
for(new i ; i < sizeof teamMsgString ; ++i)
TrieSetCell(teamMsgPointers,teamMsgString[I],1)
}
#if defined USE_PREFIX_DPROTO
pDprotoProvider = get_cvar_pointer( "dp_r_id_provider" ) // dproto interface
#endif
g_maxplayers = get_maxplayers()
prefixMax = get_pcvar_num(cvar[CVAR_MAX_PREFIXES])
register_message(get_user_msgid("SayText"),"MsgHook_SayText")
register_dictionary("prefixManager.txt")
return PLUGIN_CONTINUE
}
public client_putinserver(id){
#if defined USE_PREFIX_STEAMID
new authId[36]
get_user_authid(id,authId,35)
if(prefixForId == Invalid_Trie || !TrieGetCell(prefixForId,authId,steamIdPrefix[id]))
steamIdPrefix[id] = -1
#endif
#if defined USE_PREFIX_DPROTO
if(!pDprotoProvider){
playerClient[id] = 0
}else if( is_user_bot(id) || is_user_hltv(id) )
playerClient[id] = 0
else {
server_cmd( "dp_clientinfo %d", id )
server_exec()
playerClient[id] = get_pcvar_num(pDprotoProvider)
}
#endif
}
#if AMXX_VERSION_NUM >= 183
public SortPrefixesByWeight(Array:array, prefix1[], prefix2[]){
if(prefix1[PREFIX_WEIGHT] > prefix2[PREFIX_WEIGHT])
return -1
else if (prefix1[PREFIX_WEIGHT] < prefix2[PREFIX_WEIGHT])
return 1
return 0
}
#else
public SortPrefixesByWeight(Array:array, item1, item2){
new prefix1[prefixDataStruct],prefix2[prefixDataStruct]
ArrayGetArray(array,item1,prefix1)
ArrayGetArray(array,item2,prefix2)
if(prefix1[PREFIX_WEIGHT] > prefix2[PREFIX_WEIGHT])
return -1
else if (prefix1[PREFIX_WEIGHT] < prefix2[PREFIX_WEIGHT])
return 1
return 0
}
#endif
public MsgHook_SayText(msgId,msgDest,reciever){
if(msgDest != MSG_ONE)
return PLUGIN_CONTINUE
new id = get_msg_arg_int(1)
if( !(0 < id <= g_maxplayers) )
return PLUGIN_CONTINUE
static formatedMsg[191],chatHead[191],contentMsg[191]
static msgLastId,Float:msgLastTime
if(msgLastId == id && msgLastTime == get_gametime()){
set_msg_arg_string(2,formatedMsg)
set_msg_arg_string(4,contentMsg)
return PLUGIN_CONTINUE
}
new len,bool:isTeamMsg
get_msg_arg_string(2,chatHead,190) // указатель
get_msg_arg_string(4,contentMsg,190) // сообщение
if(teamMsgPointers)
isTeamMsg = TrieGetCell(teamMsgPointers,chatHead,isTeamMsg)
if(!FormatPrefixes(id,formatedMsg,190,len,isTeamMsg)){
if(!strcmp(chatHead,"#Cstrike_Chat_All"))
len += formatex(formatedMsg[len],190-len,"^3%%s1^1 : %%s2")
else
len += formatex(formatedMsg[len],190-len,"%s",chatHead)
}
// не допускаем перехода лимита в 190 символов
if(strlen(formatedMsg) + strlen(contentMsg) >= 190){
new contentLen = 190 - strlen(chatHead) - strlen(contentMsg)
if(((contentMsg[contentLen - 1] & 0xFF) >= 0xC2) && ((contentMsg[contentLen - 1] & 0xFF) <= 0xEF)) // Don't truncate a double-byte character
contentLen--
contentMsg[contentLen] = 0
set_msg_arg_string(4,contentMsg)
}
set_msg_arg_string(2,formatedMsg)
msgLastId = id
msgLastTime = get_gametime()
return PLUGIN_CONTINUE
}
/*
* функция форматирования сообщения с префиксом
*/
public FormatPrefixes(id,fmt[],maxlen,&len,bool:isTeam){
new prefixInfo[prefixDataStruct]
new fmtPrefixes,msgFormer[128]
new Array:skipArray
len += formatex(fmt[len],maxlen-len,"^1")
new startLen = len // запоминаем для режима форматирования всего сообщения
static Trie:prefixByGroup,bool:prefixGroup
prefixGroup = false
for(new i ; i < prefixCount ; i++){
ArrayGetArray(prefixes,i,prefixInfo)
if(!prefixInfo[PREFIX_FORMAT] && fmtPrefixes >= prefixMax)
continue
if(skipArray && check_prefix_for_skip(skipArray,prefixInfo[PREFIX_POS]))
continue
switch(prefixInfo[PREFIX_ID]){
#if defined USE_PREFIX_ACCESS
case PREFIX_ACCESS:
if(!(get_user_flags(id) & prefixInfo[PREFIX_DATA][0]))
continue
#endif
#if defined USE_PREFIX_TOP
case PREFIX_TOP:{
new st[8],rank = get_user_stats(id,st,st)
if(rank > prefixInfo[PREFIX_DATA][0])
continue
new rankStr[10]
num_to_str(rank,rankStr,9)
replace_all2(prefixInfo[PREFIX_NAME],127,"#rank#",rankStr)
}
#endif
#if defined USE_PREFIX_STEAMID
case PREFIX_STEAMID:{
if(steamIdPrefix[id] == -1)
continue
else if(steamIdPrefix[id] != prefixInfo[PREFIX_DATA][0])
continue
}
#endif
#if defined USE_PREFIX_DPROTO
case PREFIX_DPROTO:
if(playerClient[id] != prefixInfo[PREFIX_DATA][0])
continue
#endif
#if defined USE_PREFIX_AES
case PREFIX_AES:{
new aStats[AES_ST_END],levelName[64]
aes_get_player_stats(id,aStats)
aes_get_level_name(aStats[AES_ST_LEVEL],levelName,63,LANG_SERVER)
replace_all2(prefixInfo[PREFIX_NAME],127,"#rank#",levelName)
}
#endif
}
if(prefixInfo[PREFIX_SKIP] != Invalid_Array)
skipArray = prefixInfo[PREFIX_SKIP]
// это простой префикс
if(!prefixInfo[PREFIX_FORMAT]){
if(prefixInfo[PREFIX_GROUP] == 1){
len += formatex(fmt[len],maxlen - len,"%s%s",fmtPrefixes ? " " : "",prefixInfo[PREFIX_NAME])
if(!prefixInfo[PREFIX_UNCOUNT])
fmtPrefixes ++
else if(!fmtPrefixes)
len += formatex(fmt[len],maxlen - len," ")
}else{
if(prefixByGroup == Invalid_Trie)
prefixByGroup = TrieCreate()
new groupKey[14],groupText[191],groupLen
formatex(groupKey,13,"#prefix%d#",prefixInfo[PREFIX_GROUP])
TrieGetString(prefixByGroup,groupKey,groupText,190)
groupLen = strlen(groupText)
formatex(groupText[groupLen],190 - groupLen,"%s%s",groupLen ? " " : "",prefixInfo[PREFIX_NAME])
TrieSetString(prefixByGroup,groupKey,groupText)
prefixGroup = true
}
}else if(!msgFormer[0]) // это режим форматирования вида сообщения
copy(msgFormer,127,prefixInfo[PREFIX_NAME])
arrayset(prefixInfo,0,prefixDataStruct)
}
if(fmtPrefixes)
len += formatex(fmt[len],maxlen - len," ")
// форматирование сообщения
if(msgFormer[0]){
replace_all2(msgFormer,127,"#prefix#",fmt) // заменяем на префиксы
if(prefixGroup){ // груповой префикс
new w,l,r = 0
new raw[14],groupText[191]
new fmted
do {
w = contain(msgFormer[l],"#prefix")
if(w == -1)
break
l += w + 7
r = contain(msgFormer[l],"#") + l
if(r - l <= 0)
continue
formatex(raw,r - l,msgFormer[l])
formatex(raw,13,"#prefix%d#",str_to_num(raw))
if(!TrieGetString(prefixByGroup,raw,groupText,190)){
replace(msgFormer,127,raw,"")
l -= strlen(raw) - 2
}else{
formatex(groupText,190,"%s%s",fmted ? " " : "",groupText)
replace_all2(msgFormer,127,raw,groupText)
l += strlen(groupText) - strlen(raw)
fmted ++
}
} while(l != -1)
TrieClear(prefixByGroup)
}
// тег команды для чата
if(contain(msgFormer,"#team#") != -1){
if(isTeam){
new lngKey[11],teamTag[30]
formatex(lngKey,10,"CHAT_TEAM%d",get_user_team(id))
formatex(teamTag,29,"%L",LANG_SERVER,lngKey)
replace_all2(msgFormer,127,"#team#",teamTag)
}else
replace_all2(msgFormer,127,"#team#","")
}
// тег убитого
if(contain(msgFormer,"#dead#") != -1){
if(!is_user_alive(id)){
new deadTag[30]
formatex(deadTag,29,"%L",LANG_SERVER,get_user_team(id) != 0 ? "CHAT_DEAD" : "CHAT_DEAD0")
replace_all2(msgFormer,127,"#dead#",deadTag)
}else
replace_all2(msgFormer,127,"#dead#","")
}
len = formatex(fmt[startLen],maxlen - startLen,msgFormer)
}
return msgFormer[0] ? true : false
}
check_prefix_for_skip(Array:which,prefixNum){
for(new i ; i < ArraySize(which) ; ++i)
if(ArrayGetCell(which,i) == prefixNum)
return true
return false
}
/* Replaces a contained string iteratively.
* This ensures that no infinite replacements will take place by
* intelligently moving to the next string position each iteration.
*/
/*
* небольшой фикс от serfreeman1337
* прекращаем заменять если не хвататет места
* чтобы избежать проблем с replace() buffer not big enough
*/
stock replace_all2(string[], len, const what[], const with[])
{
new pos = 0;
if ((pos = contain(string, what)) == -1)
{
return 0;
}
new total = 0;
new with_len = strlen(with);
new diff = strlen(what) - with_len;
new total_len = strlen(string);
new temp_pos = 0;
while (total_len + with_len < len && replace(string[pos], len - pos, what, with) != 0)
{
total++;
/* jump to position after replacement */
pos += with_len;
/* update cached length of string */
total_len -= diff;
/* will the next call be operating on the last character? */
if (pos >= total_len)
{
break;
}
/* find the next position from our offset */
temp_pos = contain(string[pos], what);
/* if it's invalid, we're done */
if (temp_pos == -1)
{
break;
}
/* otherwise, reposition and update counters */
pos += temp_pos;
}
return total;
}
а то очень нужен этот плагин
Последнее редактирование модератором: