Senior Member
|
01-31-2024
, 11:58
Re: Hook Chat
|
#12
|
Quote:
Originally Posted by fysiks
I put quite a bit of effort into making quite simple instructions for you. Just follow the instructions and it will fix major issues with your plugin. AFTER doing those steps and re-testing, then you can add more code.
The latest version that you just posted has some serious mistakes that weren't there in your original code. The most abundant one is that you changed a most of the charsmax() to sizeof() which is completely wrong. When you are providing a function with the maximum string length for a variable, you must NOT use sizeof. You should use charsmax() for this.
The one correct change you made by when removing all the charsmax() functions was when you used strlen(sflags) in your for loop for the flag string.
You also removed a string variable that is required (szChatMessage in iHookSay()).
The least important change that you made was to randomly remove semicolons and add other random semicolons. This just makes it harder for me to investigate the functional changes that you've made.
|
PHP Code:
new
iLine,
iLength,
iPre_Flags_Count,
iPre_IPs_Count,
iPre_Names_Count,
iPre_SteamIDs_Count;
new
iText[128],
iPrefix[32],
iType[2],
iKey[32],
str_id[16],
temp_key[35],
playerPrefix[64],
configs_dir[64],
szChatMessage[190];
new
Trie:iPre_IPs_Collect,
Trie:iPre_Names_Collect,
Trie:iPre_SteamIDs_Collect,
Trie:iPre_Flags_Collect,
Trie:client_prefix;
#define MAX_PREFIXES 30
#define FLAG_RELOADPREFIX ADMIN_CFG
public plugin_init()
{
register_clcmd("say_team", "cmdTop")
register_clcmd("say_team /hs", "menuStatsViewer1")
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 client_putinserver(id)
{
num_to_str(id, str_id, charsmax(str_id))
TrieSetString(client_prefix, str_id, "")
xPutPrefix(id)
if(!g_eSetting[RANK_BOTS] && is_user_bot(id))
{
return
}
g_szAuthID[id][0] = EOS
get_user_info(id, "*sid", g_szAuthID[id], charsmax(g_szAuthID[]))
formatex(g_szPlayerFile[id], charsmax(g_szPlayerFile[]), "%s/%s.txt", g_szSteamData, g_szAuthID[id])
if(!file_exists(g_szPlayerFile[id]))
{
curl_save_player_info(id, g_szPlayerFile[id], g_szAuthID[id])
}
else
{
set_task(0.1, "taskLoadStats", id)
}
set_task(1.0, "taskShowRank", id + TASK_RANK, .flags = "b")
set_task(0.1, "taskShowHud", id + TASK_HUD, .flags = "b")
}
public client_putinserver(id)
{
if(!g_eSetting[RANK_BOTS] && is_user_bot(id))
{
return
}
g_szAuthID[id][0] = EOS
get_user_info(id, "*sid", g_szAuthID[id], charsmax(g_szAuthID[]))
formatex(g_szPlayerFile[id], charsmax(g_szPlayerFile[]), "%s/%s.txt", g_szSteamData, g_szAuthID[id])
if(!file_exists(g_szPlayerFile[id]))
{
curl_save_player_info(id, g_szPlayerFile[id], g_szAuthID[id])
}
else
{
set_task(0.1, "taskLoadStats", id)
}
set_task(1.0, "taskShowRank", id + TASK_RANK, .flags = "b")
set_task(0.1, "taskShowHud", id + TASK_HUD, .flags = "b")
num_to_str(id, str_id, charsmax(str_id))
TrieSetString(client_prefix, str_id, "")
xPutPrefix(id)
}
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++)
{
num_to_str(i, str_id, charsmax(str_id))
TrieDeleteKey(client_prefix, str_id)
xPutPrefix(i)
}
return PLUGIN_HANDLED
}
public xPutPrefix(id)
{
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 < strlen(sflags); i++)
{
formatex(temp_flag, charsmax(temp_flag), "%c", sflags[i]);
if(TrieGetString(iPre_Flags_Collect, temp_flag, playerPrefix, charsmax(playerPrefix)))
{
TrieSetString(client_prefix, str_id, playerPrefix);
}
}
get_user_ip(id, temp_key, charsmax(temp_key), 1);
if (TrieGetString(iPre_IPs_Collect, temp_key, playerPrefix, charsmax(playerPrefix)))
{
TrieSetString(client_prefix, str_id, playerPrefix);
}
get_user_authid(id, temp_key, charsmax(temp_key));
if (TrieGetString(iPre_SteamIDs_Collect, temp_key, playerPrefix, charsmax(playerPrefix)))
{
TrieSetString(client_prefix, str_id, playerPrefix);
}
get_user_name(id, temp_key, charsmax(temp_key));
if (TrieGetString(iPre_Names_Collect, temp_key, playerPrefix, charsmax(playerPrefix)))
{
TrieSetString(client_prefix, str_id, playerPrefix);
}
return PLUGIN_HANDLED;
}
public iHookSay(id)
{
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;
num_to_str(id, str_id, charsmax(str_id))
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(playerPrefix[0])
{
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 ^1» ^4%s ^1« ^3%s: ^1%s", szEstado, 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(szChatMessage, id, i)
}
return PLUGIN_HANDLED_MAIN;
}
public iHookSayT(id)
{
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[0])
{
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 ^1» ^4%s ^1« ^3%s: ^1%s", szTeamInfo, szEstado, eRank[RankName], g_szName[id], szChatMessage);
}
}
else
{
if(playerPrefix[0])
{
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] ^1» ^4%s ^1« ^3%s: ^1%s ", szTeamInfo, szEstado, 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(szChatMessage, id, i)
}
return PLUGIN_HANDLED_MAIN;
}
send_message(const message[], const id, const i)
{
message_begin(MSG_ONE, sz_saytext, {0, 0, 0}, i)
write_byte(id)
write_string(message)
message_end()
}
I tried several times to do what you recommended, but every time I kept crashing the server in some way, so I didn't want to come back every time to ask what was going on, so I thought, well, I'll try to do it here the way I know how,
I realized that I was commenting some errors
inside
PHP Code:
if(!cm_get_user_clan_tag(id, szClanTag))// ^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s
{
if(playerPrefix[0])
{
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[0])
{
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);
}
}
I was using playerPrefix even if player didn't have the prefix
inside the else I was using playerPrefix
So I changed everything and tried again, but it's still going wrong.
|
|