Raised This Month: $51 Target: $400
 12% 

Hook Chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 01-22-2024 , 21:21   Hook Chat
Reply With Quote #1

For some reason he is taking my FLAG and giving it to all other players, does anyone know why?

like I have MASTER flag

if another person enters they also have the MASTER flag

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,
    
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_dircharsmax(configs_dir))
    
formatex(iFile_Prefixcharsmax(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_PrefixiLine++, iTextcharsmax(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(iTextiTypecharsmax(iType), iKeycharsmax(iKey), iPrefixcharsmax(iPrefix));
        
trim(iPrefix);

        if (!
iType[0] || !iPrefix[0] || !iKey[0])
            continue;

        
replace_all(iPrefixcharsmax(iPrefix), "!g""^x04");
        
replace_all(iPrefixcharsmax(iPrefix), "!t""^x03");
        
replace_all(iPrefixcharsmax(iPrefix), "!y""^x01");

        switch (
iType[0])
        {
        case 
'f':
        {
            
iPre_Flags_Count++;
            
TrieSetString(iPre_Flags_CollectiKeyiPrefix);
        }
        case 
'i':
        {
            
iPre_IPs_Count++;
            
TrieSetString(iPre_IPs_CollectiKeyiPrefix);
        }
        case 
's':
        {
            
iPre_SteamIDs_Count++;
            
TrieSetString(iPre_SteamIDs_CollectiKeyiPrefix);
        }
        case 
'n':
        {
            
iPre_Names_Count++;
            
TrieSetString(iPre_Names_CollectiKeyiPrefix);
        }
        default:
            continue;
        }
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i))
        {
          continue;
        }

        
num_to_str(istr_idcharsmax(str_id));
        
TrieDeleteKey(client_prefixstr_id);
        
xPutPrefix(i);
    }

    return 
PLUGIN_HANDLED;
}

public 
xPutPrefix(id)
{
    
num_to_str(idstr_idcharsmax(str_id))
    
TrieSetString(client_prefixstr_id"")

    new 
sflags[32], temp_flag[2];
    
get_flags(get_user_flags(id), sflagscharsmax(sflags))

    for(new 
0<= charsmax(sflags); i++)
    {
        
formatex(temp_flagcharsmax(temp_flag), "%c"sflags[i])

        if(
TrieGetString(iPre_Flags_Collecttemp_flagplayerPrefixcharsmax(playerPrefix)))
        {
            
TrieSetString(client_prefixstr_idplayerPrefix)
        }
    }    

    
get_user_ip(idtemp_keycharsmax(temp_key), 1);

    if (
TrieGetString(iPre_IPs_Collecttemp_keyplayerPrefixcharsmax(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    
get_user_authid(idtemp_keycharsmax(temp_key));

    if (
TrieGetString(iPre_SteamIDs_Collecttemp_keyplayerPrefixcharsmax(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    
get_user_name(idtemp_keycharsmax(temp_key));

    if (
TrieGetString(iPre_Names_Collecttemp_keyplayerPrefixcharsmax(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    return 
PLUGIN_HANDLED;
}


public 
iHookSay(id)
{
    new 
szChatMessage[190];
    
read_args(szChatMessagecharsmax(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(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo]
    
ArrayGetArray(g_aRanksg_pPlayerData[id][Level], eRank)

    new 
szClanTag[MAX_CLAN_TAG_LENGTH];
    
cm_get_user_clan_tag(idszClanTag);

    if(!
cm_get_user_clan_tag(idszClanTag))// ^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s
    
{
        if(
playerPrefix[0])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }    
    }
    else
    {
        if(
playerPrefix[0])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        } 
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage)

    }

    return 
PLUGIN_HANDLED_MAIN;


public 
iHookSayT(id)
{
    new 
szChatMessage[190];
    
read_args(szChatMessagecharsmax(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(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo];
    
ArrayGetArray(g_aRanksg_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(szTeamInfocharsmax(szTeamInfo), "(T)");
    else if(
iPlayerTeam == TEAM_CT)
        
copy(szTeamInfocharsmax(szTeamInfo), "(CT)")
    

    if (!
cm_get_user_clan_tag(idszClanTag))
    {
        if(
playerPrefix[id])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        
    }
    else
    {
        if(
playerPrefix[id][0])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage);
    }

    return 
PLUGIN_HANDLED_MAIN;
}

send_message(const id, const target, const message[190])
{
    
// Format message for player
    
static buffer[191]
    
vformat(buffercharsmax(buffer), message3);
    
replace_all(buffercharsmax(buffer),"!g","^4");// green
    
replace_all(buffercharsmax(buffer),"!n","^1");// normal
    
replace_all(buffercharsmax(buffer),"!y","^1");// normal
    
replace_all(buffercharsmax(buffer),"!t","^3");// team
    
replace_all(buffercharsmax(buffer),"x04","^4");// green
    
replace_all(buffercharsmax(buffer),"x03","^3");// Team
    
replace_all(buffercharsmax(buffer),"x01","^1");// normal

    // Say
    
message_begin(MSG_ONEsz_saytext, {000}, target)
    
write_byte(id)
    
write_string(buffer)
    
message_end()

yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-22-2024 , 23:38   Re: Hook Chat
Reply With Quote #2

Very important parts of this code make absolutely no sense and should not even compile. "playerPrefix" is declared as a scalar variable and therefore cannot be used as a string, anywhere. This is why posting the entire plugin is preferred, because you will inevitably create errors and make it harder to help you.

If "playerPrefix" is actually declared as a string variable (e.g. playerPrefix[32]) then you need to do the following:
  1. Declare playerPrefix as playerPrefix[33][sizeof(iText)].
  2. In xPutPrefix(), create a new buffer string (e.g. szBuffer[sizeof(iText)])
  3. In xPutPrefix(), replace every instance of playerPrefix with szBuffer.
  4. In xPutPrefix(), replace every instance of TrieSetString(client_prefix, str_id, playerPrefix) with copy(playerPrefix[id], charsmax(playerPrefix[]), szBuffer)
  5. To check if a prefix has been set, use if( playerPrefix[id][0] == EOS )
  6. To get the string, use playerPrefix[id] (e.g. in your format function)
  7. Add playerPrefix[id][0] = EOS to client_connect()



A bit off-topic:
Code:
g_iMaxPlayers = get_maxplayers() + 1
is bad code because the name of the variable does not represent what the variable contains. Also, because of this +1, you have one too many iterations in your loops (at least the ones in the posted code). If you're looking to optimize, you might consider switching to use get_players()/get_players_ex() method of looping through players.
__________________

Last edited by fysiks; 01-25-2024 at 23:28. Reason: fix step 4, fix string length declaration to remove ambiguity
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 01-23-2024 , 05:39   Re: Hook Chat
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Very important parts of this code make absolutely no sense and should not even compile. "playerPrefix" is declared as a scalar variable and therefore cannot be used as a string, anywhere. This is why posting the entire plugin is preferred, because you will inevitably create errors and make it harder to help you.

If "playerPrefix" is actually declared as a string variable (e.g. playerPrefix[32]) then you need to do the following:
  1. Declare playerPrefix as playerPrefix[33][PREFIX_STRING_LENGTH+1].
  2. In xPutPrefix(), create a new buffer string (e.g. szBuffer[PREFIX_STRING_LENGTH+1])
  3. In xPutPrefix(), replace every instance of playerPrefix with szBuffer.
  4. In xPutPrefix(), replace every instance of TrieSetString(client_prefix, str_id, playerPrefix) with copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
  5. To check if a prefix has been set, use if( playerPrefix[id][0] == EOS )
  6. To get the string, use playerPrefix[id] (e.g. in your format function)
  7. Add playerPrefix[id][0] = EOS to client_connect()



A bit off-topic:
Code:
g_iMaxPlayers = get_maxplayers() + 1
is bad code because the name of the variable does not represent what the variable contains. Also, because of this +1, you have one too many iterations in your loops (at least the ones in the posted code). If you're looking to optimize, you might consider switching to use get_players()/get_players_ex() method of looping through players.
I was trying to make changes and ended up forgetting to change playerPrefix

the correct one is playerPrefix[64]
yagami is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 01-23-2024 , 10:51   Re: Hook Chat
Reply With Quote #4

Quote:
Originally Posted by yagami View Post
PHP Code:
    g_iMaxPlayers get_maxplayers() + 
__________________
mlibre is offline
yagami
Senior Member
Join Date: Jan 2021
Old 01-23-2024 , 15:19   Re: Hook Chat
Reply With Quote #5

Quote:
Originally Posted by mlibre View Post
I don't understand
yagami is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 01-23-2024 , 17:26   Re: Hook Chat
Reply With Quote #6

the +1 this extra could be the origin of the bug, try to make that change simpler, how it behaves...
__________________
mlibre is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-23-2024 , 22:53   Re: Hook Chat
Reply With Quote #7

Quote:
Originally Posted by yagami View Post
I was trying to make changes and ended up forgetting to change playerPrefix

the correct one is playerPrefix[64]
Well, that is wrong. It needs to be how I described in my previous post.

Quote:
Originally Posted by mlibre View Post
the +1 this extra could be the origin of the bug, try to make that change simpler, how it behaves...
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.
__________________

Last edited by fysiks; 01-23-2024 at 22:53. Reason: fixed verbiage with a synonym for clarity.
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 01-25-2024 , 06:39   Re: Hook Chat
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post
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_dircharsmax(configs_dir))
    
formatex(iFile_Prefixcharsmax(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_PrefixiLine++, iTextcharsmax(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(iTextiTypecharsmax(iType), iKeycharsmax(iKey), iPrefixcharsmax(iPrefix));
        
trim(iPrefix);

        if (!
iType[0] || !iPrefix[0] || !iKey[0])
            continue;

        
replace_all(iPrefixcharsmax(iPrefix), "!g""^x04");
        
replace_all(iPrefixcharsmax(iPrefix), "!t""^x03");
        
replace_all(iPrefixcharsmax(iPrefix), "!y""^x01");

        switch (
iType[0])
        {
        case 
'f':
        {
            
iPre_Flags_Count++;
            
TrieSetString(iPre_Flags_CollectiKeyiPrefix);
        }
        case 
'i':
        {
            
iPre_IPs_Count++;
            
TrieSetString(iPre_IPs_CollectiKeyiPrefix);
        }
        case 
's':
        {
            
iPre_SteamIDs_Count++;
            
TrieSetString(iPre_SteamIDs_CollectiKeyiPrefix);
        }
        case 
'n':
        {
            
iPre_Names_Count++;
            
TrieSetString(iPre_Names_CollectiKeyiPrefix);
        }
        default:
            continue;
        }
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i))
        {
          continue;
        }

        
num_to_str(istr_idcharsmax(str_id));
        
TrieDeleteKey(client_prefixstr_id);
        
xPutPrefix(i);
    }

    return 
PLUGIN_HANDLED;
}

public 
xPutPrefix(id)
{
    new 
szBuffer[PREFIX_STRING_LENGTH+1]
    
num_to_str(idstr_idcharsmax(str_id))
    
TrieSetString(client_prefixstr_id"")

    new 
sflags[32], temp_flag[2];
    
get_flags(get_user_flags(id), sflagscharsmax(sflags))

    for(new 
0<= charsmax(sflags); i++)
    {
        
formatex(temp_flagcharsmax(temp_flag), "%c"sflags[i])

        
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)
    }    

    
get_user_ip(idtemp_keycharsmax(temp_key), 1);

    
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)

    
get_user_authid(idtemp_keycharsmax(temp_key));

    
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)

    
get_user_name(idtemp_keycharsmax(temp_key));

    
copy(playerPrefix[id], charsmax(playerPrefix[]), playerPrefix)

    return 
PLUGIN_HANDLED;
}


public 
iHookSay(id)
{
    new 
szChatMessage[190];
    
read_args(szChatMessagecharsmax(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(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo]
    
ArrayGetArray(g_aRanksg_pPlayerData[id][Level], eRank)

    new 
szClanTag[MAX_CLAN_TAG_LENGTH];
    
cm_get_user_clan_tag(idszClanTag);

    if(!
cm_get_user_clan_tag(idszClanTag))// ^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s
    
{
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }    
    }
    else
    {
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        } 
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage)

    }

    return 
PLUGIN_HANDLED_MAIN;


public 
iHookSayT(id)
{
    new 
szChatMessage[190];
    
read_args(szChatMessagecharsmax(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(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo];
    
ArrayGetArray(g_aRanksg_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(szTeamInfocharsmax(szTeamInfo), "(T)");
    else if(
iPlayerTeam == TEAM_CT)
        
copy(szTeamInfocharsmax(szTeamInfo), "(CT)")
    

    if (!
cm_get_user_clan_tag(idszClanTag))
    {
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        
    }
    else
    {
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage);
    }

    return 
PLUGIN_HANDLED_MAIN;
}

send_message(const id, const target, const message[190])
{
    
// Format message for player
    
static buffer[191]
    
vformat(buffercharsmax(buffer), message3);
    
replace_all(buffercharsmax(buffer),"!g","^4");// green
    
replace_all(buffercharsmax(buffer),"!n","^1");// normal
    
replace_all(buffercharsmax(buffer),"!y","^1");// normal
    
replace_all(buffercharsmax(buffer),"!t","^3");// team
    
replace_all(buffercharsmax(buffer),"x04","^4");// green
    
replace_all(buffercharsmax(buffer),"x03","^3");// Team
    
replace_all(buffercharsmax(buffer),"x01","^1");// normal

    // Say
    
message_begin(MSG_ONEsz_saytext, {000}, target)
    
write_byte(id)
    
write_string(buffer)
    
message_end()


Last edited by yagami; 01-25-2024 at 06:40.
yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-25-2024 , 23:35   Re: Hook Chat
Reply With Quote #9

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.
__________________
fysiks is offline
yagami
Senior Member
Join Date: Jan 2021
Old 01-30-2024 , 00:24   Re: Hook Chat
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
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_dircharsmax(configs_dir))
    
formatex(iFile_Prefixcharsmax(iFile_Prefix), "%s/admin_prefixes.ini"configs_dir)


    
xLoadPrefix(0)

    
g_iMaxPlayers get_maxplayers()

}

public 
client_putinserver(id)
{
    
num_to_str(idstr_idcharsmax(str_id))
    
TrieSetString(client_prefixstr_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_szSteamDatag_szAuthID[id])

    if(!
file_exists(g_szPlayerFile[id]))
    {
        
curl_save_player_info(idg_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_PrefixiLine++, iTextcharsmax(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(iTextiTypecharsmax(iType), iKeycharsmax(iKey), iPrefixcharsmax(iPrefix));
        
trim(iPrefix);

        if (!
iType[0] || !iPrefix[0] || !iKey[0])
            continue;

        
replace_all(iPrefixcharsmax(iPrefix), "!g""^x04");
        
replace_all(iPrefixcharsmax(iPrefix), "!t""^x03");
        
replace_all(iPrefixcharsmax(iPrefix), "!y""^x01");

        switch (
iType[0])
        {
        case 
'f':
        {
            
iPre_Flags_Count++;
            
TrieSetString(iPre_Flags_CollectiKeyiPrefix);
        }
        case 
'i':
        {
            
iPre_IPs_Count++;
            
TrieSetString(iPre_IPs_CollectiKeyiPrefix);
        }
        case 
's':
        {
            
iPre_SteamIDs_Count++;
            
TrieSetString(iPre_SteamIDs_CollectiKeyiPrefix);
        }
        case 
'n':
        {
            
iPre_Names_Count++;
            
TrieSetString(iPre_Names_CollectiKeyiPrefix);
        }
        default:
            continue;
        }
    }

    for(new 
1<= g_iMaxPlayersi++)
    {
        
num_to_str(istr_idcharsmax(str_id))
        
TrieDeleteKey(client_prefixstr_id)
        
xPutPrefix(i)
    }

    return 
PLUGIN_HANDLED
}

public 
xPutPrefix(id)
{

    
num_to_str(idstr_idsizeof(str_id));

    
TrieSetString(client_prefixstr_id"");

    new 
sflags[32], temp_flag[2]
    
get_flags(get_user_flags(id), sflagssizeof(sflags));

    for(new 
0strlen(sflags); i++)
    {
        
formatex(temp_flagcharsmax(temp_flag), "%c"sflags[i]);

        if(
TrieGetString(iPre_Flags_Collecttemp_flagplayerPrefixsizeof(playerPrefix)))
        {
            
TrieSetString(client_prefixstr_idplayerPrefix);
        }
    }

    
get_user_ip(idtemp_keysizeof(temp_key), 1);

    if (
TrieGetString(iPre_IPs_Collecttemp_keyplayerPrefixsizeof(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    
get_user_authid(idtemp_keysizeof(temp_key));

    if (
TrieGetString(iPre_SteamIDs_Collecttemp_keyplayerPrefixsizeof(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    
get_user_name(idtemp_keysizeof(temp_key));

    if (
TrieGetString(iPre_Names_Collecttemp_keyplayerPrefixsizeof(playerPrefix)))
    {
        
TrieSetString(client_prefixstr_idplayerPrefix);
    }

    return 
PLUGIN_HANDLED;
}

public 
iHookSay(id)
{
    
read_args(szChatMessagecharsmax(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_prefixstr_idplayerPrefixcharsmax(playerPrefix))  || (!TrieGetString(client_prefixstr_idplayerPrefixcharsmax(playerPrefix)))) 
        return 
PLUGIN_HANDLED_MAIN

    num_to_str
(idstr_idcharsmax(str_id))
        
    new 
szEstado[32]
    if(
is_user_alive(id)) szEstado ""
    
else szEstado "•MORTO• "

    
get_user_name(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo]
    
ArrayGetArray(g_aRanksg_pPlayerData[id][Level], eRank)

    new 
szClanTag[MAX_CLAN_TAG_LENGTH];
    
cm_get_user_clan_tag(idszClanTag);

    if(!
cm_get_user_clan_tag(idszClanTag))// ^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s
    
{
        if(
playerPrefix[0])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);

        }    
    }
    else
    {
        if(
playerPrefix[0])
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s"szEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);

        } 
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage)

    }

    return 
PLUGIN_HANDLED_MAIN;



public 
iHookSayT(id)
{
    new 
szChatMessage[190];
    
read_args(szChatMessagecharsmax(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(idg_szName[id], charsmax(g_szName[]));

    
replace_all(szChatMessagecharsmax(szChatMessage), "!g"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "!n"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!y"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "!t"""); // team
    
replace_all(szChatMessagecharsmax(szChatMessage), "x04"""); // green
    
replace_all(szChatMessagecharsmax(szChatMessage), "x03"""); // normal
    
replace_all(szChatMessagecharsmax(szChatMessage), "x01"""); // normal

    
new eRank[RankInfo];
    
ArrayGetArray(g_aRanksg_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(szTeamInfocharsmax(szTeamInfo), "(T)");
    else if(
iPlayerTeam == TEAM_CT)
        
copy(szTeamInfocharsmax(szTeamInfo), "(CT)")
    

    if (!
cm_get_user_clan_tag(idszClanTag))
    {
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^4%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^1» ^4%s ^1« ^3%s: ^1%s"szTeamInfoszEstadoplayerPrefixeRank[RankName], g_szName[id], szChatMessage);
        }
        
    }
    else
    {
        if(
playerPrefix[id][0] == EOS)
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^4%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        else 
        {
            
format(szChatMessagecharsmax(szChatMessage), "^1%s^1%s ^4%s ^4[%s] ^1» ^4%s ^1« ^3%s: ^1%s "szTeamInfoszEstadoplayerPrefixszClanTageRank[RankName], g_szName[id], szChatMessage);
        }
        
    }

    for (new 
1<= g_iMaxPlayersi++)
    {
        if (!
is_user_connected(i) || is_user_bot(i) || is_user_hltv(i))
            continue;

        
send_message(idiszChatMessage);
    }

    return 
PLUGIN_HANDLED_MAIN;
}

send_message(const id, const target, const message[190])
{
    
// Format message for player
    
static buffer[191]
    
vformat(buffercharsmax(buffer), message3);
    
replace_all(buffercharsmax(buffer),"!g","^4");// green
    
replace_all(buffercharsmax(buffer),"!n","^1");// normal
    
replace_all(buffercharsmax(buffer),"!y","^1");// normal
    
replace_all(buffercharsmax(buffer),"!t","^3");// team
    
replace_all(buffercharsmax(buffer),"x04","^4");// green
    
replace_all(buffercharsmax(buffer),"x03","^3");// Team
    
replace_all(buffercharsmax(buffer),"x01","^1");// normal

    // Say
    
message_begin(MSG_ONEsz_saytext, {000}, 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.
yagami is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode