Senior Member
|
01-25-2024
, 06:39
Re: Hook Chat
|
#8
|
Quote:
Originally Posted by fysiks
Well, that is wrong. It needs to be how I described in my previous post.
I don't think this is causing any issues because, based on the posted code, all the iterations in loops that use that value will just kick out due to the is_user_connected() check.
|
I was unsure about the last two
PHP Code:
new
iLine,
iLength,
iPre_Flags_Count,
iPre_IPs_Count,
iPre_Names_Count,
iPre_SteamIDs_Count,
sz_saytext;
new
iText[128],
iPrefix[32],
iType[2],
iKey[32],
str_id[16],
temp_key[35],
playerPrefix[33][PREFIX_STRING_LENGTH+1],
configs_dir[64];
new
Trie:iPre_IPs_Collect,
Trie:iPre_Names_Collect,
Trie:iPre_SteamIDs_Collect,
Trie:iPre_Flags_Collect;
Trie:client_prefix,
public plugin_init()
{
sz_saytext = get_user_msgid ("SayText");
register_clcmd("say", "iHookSay")
register_clcmd("say_team", "iHookSayT")
iPre_IPs_Collect = TrieCreate()
iPre_Names_Collect = TrieCreate()
iPre_SteamIDs_Collect = TrieCreate()
iPre_Flags_Collect = TrieCreate()
client_prefix = TrieCreate()
get_configsdir(configs_dir, charsmax(configs_dir))
formatex(iFile_Prefix, charsmax(iFile_Prefix), "%s/admin_prefixes.ini", configs_dir)
xLoadPrefix(0)
g_iMaxPlayers = get_maxplayers() + 1
}
public xLoadPrefix(id)
{
if (!(get_user_flags(id) & FLAG_RELOADPREFIX))
return PLUGIN_HANDLED;
TrieClear(iPre_IPs_Collect);
TrieClear(iPre_Names_Collect);
TrieClear(iPre_SteamIDs_Collect);
TrieClear(iPre_Flags_Collect);
iLine = 0;
iLength = 0;
iPre_Flags_Count = 0;
iPre_IPs_Count = 0;
iPre_Names_Count = 0;
if (!file_exists(iFile_Prefix))
set_fail_state("Arquivo admin_prefixes.ini nao encontrado.");
while (read_file(iFile_Prefix, iLine++, iText, charsmax(iText), iLength) && (iPre_IPs_Count + iPre_Names_Count + iPre_SteamIDs_Count + iPre_Flags_Count) <= MAX_PREFIXES)
{
if (!iText[0] || iText[0] == '^n' || iText[0] == ';' || (iText[0] == '/' && iText[1] == '/'))
continue;
parse(iText, iType, charsmax(iType), iKey, charsmax(iKey), iPrefix, charsmax(iPrefix));
trim(iPrefix);
if (!iType[0] || !iPrefix[0] || !iKey[0])
continue;
replace_all(iPrefix, charsmax(iPrefix), "!g", "^x04");
replace_all(iPrefix, charsmax(iPrefix), "!t", "^x03");
replace_all(iPrefix, charsmax(iPrefix), "!y", "^x01");
switch (iType[0])
{
case 'f':
{
iPre_Flags_Count++;
TrieSetString(iPre_Flags_Collect, iKey, iPrefix);
}
case 'i':
{
iPre_IPs_Count++;
TrieSetString(iPre_IPs_Collect, iKey, iPrefix);
}
case 's':
{
iPre_SteamIDs_Count++;
TrieSetString(iPre_SteamIDs_Collect, iKey, iPrefix);
}
case 'n':
{
iPre_Names_Count++;
TrieSetString(iPre_Names_Collect, iKey, iPrefix);
}
default:
continue;
}
}
for (new i = 1; i <= g_iMaxPlayers; i++)
{
if (!is_user_connected(i))
{
continue;
}
num_to_str(i, str_id, charsmax(str_id));
TrieDeleteKey(client_prefix, str_id);
xPutPrefix(i);
}
return PLUGIN_HANDLED;
}
public xPutPrefix(id)
{
new szBuffer[PREFIX_STRING_LENGTH+1]
num_to_str(id, str_id, charsmax(str_id))
TrieSetString(client_prefix, str_id, "")
new sflags[32], temp_flag[2];
get_flags(get_user_flags(id), sflags, charsmax(sflags))
for(new i = 0; i <= charsmax(sflags); i++)
{
formatex(temp_flag, charsmax(temp_flag), "%c", sflags[i])
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
}
get_user_ip(id, temp_key, charsmax(temp_key), 1);
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
get_user_authid(id, temp_key, charsmax(temp_key));
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
get_user_name(id, temp_key, charsmax(temp_key));
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
return PLUGIN_HANDLED;
}
public iHookSay(id)
{
new szChatMessage[190];
read_args(szChatMessage, charsmax(szChatMessage));
remove_quotes(szChatMessage);
trim(szChatMessage);
if (equal(szChatMessage, "") || !is_user_connected(id) || is_user_bot(id) || is_user_hltv(id) || check_say_characters(szChatMessage))
return PLUGIN_HANDLED_MAIN;
new szEstado[32]
if(is_user_alive(id)) szEstado = ""
else szEstado = "•MORTO• "
get_user_name(id, g_szName[id], charsmax(g_szName[]));
replace_all(szChatMessage, charsmax(szChatMessage), "!g", ""); // green
replace_all(szChatMessage, charsmax(szChatMessage), "!n", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "!y", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "!t", ""); // team
replace_all(szChatMessage, charsmax(szChatMessage), "x04", ""); // green
replace_all(szChatMessage, charsmax(szChatMessage), "x03", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "x01", ""); // normal
new eRank[RankInfo]
ArrayGetArray(g_aRanks, g_pPlayerData[id][Level], eRank)
new szClanTag[MAX_CLAN_TAG_LENGTH];
cm_get_user_clan_tag(id, szClanTag);
if(!cm_get_user_clan_tag(id, szClanTag))// ^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s
{
if(playerPrefix[id][0] == EOS)
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^4%s", szEstado, playerPrefix, eRank[RankName], g_szName[id], szChatMessage);
}
else
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^1%s", szEstado, playerPrefix, eRank[RankName], g_szName[id], szChatMessage);
}
}
else
{
if(playerPrefix[id][0] == EOS)
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s", szEstado, playerPrefix, szClanTag, eRank[RankName], g_szName[id], szChatMessage);
}
else
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s", szEstado, playerPrefix, szClanTag, eRank[RankName], g_szName[id], szChatMessage);
}
}
for (new i = 1; i <= g_iMaxPlayers; i++)
{
if (!is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
continue;
send_message(id, i, szChatMessage)
}
return PLUGIN_HANDLED_MAIN;
}
public iHookSayT(id)
{
new szChatMessage[190];
read_args(szChatMessage, charsmax(szChatMessage));
remove_quotes(szChatMessage);
trim(szChatMessage);
if (equal(szChatMessage, "") || !is_user_connected(id) || is_user_bot(id) || is_user_hltv(id) || check_say_characters(szChatMessage))
return PLUGIN_HANDLED_MAIN;
new szEstado[32];
if (is_user_alive(id))
szEstado = "";
else
szEstado = "*MORTO*";
get_user_name(id, g_szName[id], charsmax(g_szName[]));
replace_all(szChatMessage, charsmax(szChatMessage), "!g", ""); // green
replace_all(szChatMessage, charsmax(szChatMessage), "!n", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "!y", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "!t", ""); // team
replace_all(szChatMessage, charsmax(szChatMessage), "x04", ""); // green
replace_all(szChatMessage, charsmax(szChatMessage), "x03", ""); // normal
replace_all(szChatMessage, charsmax(szChatMessage), "x01", ""); // normal
new eRank[RankInfo];
ArrayGetArray(g_aRanks, g_pPlayerData[id][Level], eRank);
new szClanTag[MAX_CLAN_TAG_LENGTH];
new TeamName:iPlayerTeam = rg_get_user_team(id)
new szTeamInfo[32];
if (iPlayerTeam == TEAM_TERRORIST)
copy(szTeamInfo, charsmax(szTeamInfo), "(T)");
else if(iPlayerTeam == TEAM_CT)
copy(szTeamInfo, charsmax(szTeamInfo), "(CT)")
if (!cm_get_user_clan_tag(id, szClanTag))
{
if(playerPrefix[id][0] == EOS)
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^4%s", szTeamInfo, szEstado, playerPrefix, eRank[RankName], g_szName[id], szChatMessage);
}
else
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s", szTeamInfo, szEstado, playerPrefix, eRank[RankName], g_szName[id], szChatMessage);
}
}
else
{
if(playerPrefix[id][0] == EOS)
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s ", szTeamInfo, szEstado, playerPrefix, szClanTag, eRank[RankName], g_szName[id], szChatMessage);
}
else
{
format(szChatMessage, charsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s ", szTeamInfo, szEstado, playerPrefix, szClanTag, eRank[RankName], g_szName[id], szChatMessage);
}
}
for (new i = 1; i <= g_iMaxPlayers; i++)
{
if (!is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
continue;
send_message(id, i, szChatMessage);
}
return PLUGIN_HANDLED_MAIN;
}
send_message(const id, const target, const message[190])
{
// Format message for player
static buffer[191]
vformat(buffer, charsmax(buffer), message, 3);
replace_all(buffer, charsmax(buffer),"!g","^4");// green
replace_all(buffer, charsmax(buffer),"!n","^1");// normal
replace_all(buffer, charsmax(buffer),"!y","^1");// normal
replace_all(buffer, charsmax(buffer),"!t","^3");// team
replace_all(buffer, charsmax(buffer),"x04","^4");// green
replace_all(buffer, charsmax(buffer),"x03","^3");// Team
replace_all(buffer, charsmax(buffer),"x01","^1");// normal
// Say
message_begin(MSG_ONE, sz_saytext, {0, 0, 0}, target)
write_byte(id)
write_string(buffer)
message_end()
}
Last edited by yagami; 01-25-2024 at 06:40.
|
|