Senior Member
|
01-30-2024
, 00:24
Re: Hook Chat
|
#10
|
Quote:
Originally Posted by fysiks
It looks like you skipped step 3 entirely which MUST be done before step 4. In step 4, it looks like I made a typo (I fixed this in my original post). I'm not sure why you removed all of the if statements that used TrieGetString(), that will totally make this plugin not work correctly.
Where I put PREFIX_STRING_LENGTH, I meant for you to put your own value in there but I looked again and it you can simply replace "PREFIX_STRING_LENGTH+1" with "sizeof(iText)". I updated this in the original post.
Step 6 means that anywhere you need to get the prefix for that player, you need to use that variable in that way. So, you're doing this in your format() functions.
Step 7 is to make sure that a new player doesn't automatically get an old player's prefix. You do this by clearing out the string variable for that player when they connect. You should get familiar with client_connect().
Code:
public client_connect(id)
{
playerPrefix[id][0] = EOS
}
Overall, because some steps must be done before others, I highly recommend starting over and follow the steps exactly as they are written.
P.S. Prefixing a variable with "i" is generally used to indicate that the variable stores an integer value. In several cases in your plugin, the variables are actually storing strings. We typically use the prefix "sz" to indicate a string variable. If you're not sure how the prefixes works, I would recommend not using any prefixes so that there are not incorrectly prefixed variables that make the code more confusing.
|
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[64] 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()
}
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 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, sizeof(str_id));
TrieSetString(client_prefix, str_id, "");
new sflags[32], temp_flag[2] get_flags(get_user_flags(id), sflags, sizeof(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, sizeof(playerPrefix))) { TrieSetString(client_prefix, str_id, playerPrefix); } }
get_user_ip(id, temp_key, sizeof(temp_key), 1);
if (TrieGetString(iPre_IPs_Collect, temp_key, playerPrefix, sizeof(playerPrefix))) { TrieSetString(client_prefix, str_id, playerPrefix); }
get_user_authid(id, temp_key, sizeof(temp_key));
if (TrieGetString(iPre_SteamIDs_Collect, temp_key, playerPrefix, sizeof(playerPrefix))) { TrieSetString(client_prefix, str_id, playerPrefix); }
get_user_name(id, temp_key, sizeof(temp_key));
if (TrieGetString(iPre_Names_Collect, temp_key, playerPrefix, sizeof(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;
if(TrieGetString(client_prefix, str_id, playerPrefix, charsmax(playerPrefix)) || (!TrieGetString(client_prefix, str_id, playerPrefix, charsmax(playerPrefix)))) 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(!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);
} }
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() }
I tried to do it your way but I couldn't, my head hurts from thinking so much
I added TrieGetString
num_to_str to code
Last edited by yagami; 01-30-2024 at 00:34.
|
|