AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Change letters in a SayText hook (https://forums.alliedmods.net/showthread.php?t=194839)

shavit 08-31-2012 18:45

Change letters in a SayText hook
 
Hey there!
I made an SayHook:
PHP Code:

public SayHook()
{
    new 
client read_data(1);
    new 
message[128];
    
read_data(4message128);

    if(
Cool[client])
    {
        
    }


Now I need to change some letters. [Lets say that I want to change any A in the hook to B]
I have no idea how it works on AMX Mod X. Only in SourceMod.
Thanks!

Edit: Found myself
PHP Code:

replace(message128"a""b"); 


ConnorMcLeod 08-31-2012 19:16

Re: Change letters in a SayText hook
 
Use replace_all if you want to proceed the whole string.
But replace and replace_all are more to replace a string with another string, here you just want to replace a char with another char.

You could use this stock :
PHP Code:

replace_char_allstring[], lencWhatcWith )
{
    for(new 
ii<=leni++)
    {
        if( 
string[i] == cWhat )
        {
            
string[i] == cWith
        
}
    }
    return 
1


Remember that after replacing the string (whatever the method you use), you have to block the command (PLUGIN_HANDLED_MAIN if you want other plugin to be able to receive original text), and to send yours with engclient_cmd(id, "say", string)

Edit : seems you hook SayText with register_event, then you can't block it and you can't change string.
Either hook say command with register_clcmd, then consider the comment i made after stock, either you hook SayText message with register_message and there you can use set_msg_arg_string.

shavit 08-31-2012 19:30

Re: Change letters in a SayText hook
 
Quote:

Originally Posted by ConnorMcLeod (Post 1788173)
Use replace_all if you want to proceed the whole string.
But replace and replace_all are more to replace a string with another string, here you just want to replace a char with another char.

You could use this stock :
PHP Code:

replace_char_allstring[], lencWhatcWith )
{
    for(new 
ii<=leni++)
    {
        if( 
string[i] == cWhat )
        {
            
string[i] == cWith
        
}
    }
    return 
1


Remember that after replacing the string (whatever the method you use), you have to block the command (PLUGIN_HANDLED_MAIN if you want other plugin to be able to receive original text), and to send yours with engclient_cmd(id, "say", string)

Edit : seems you hook SayText with register_event, then you can't block it and you can't change string.
Either hook say command with register_clcmd, then consider the comment i made after stock, either you hook SayText message with register_message and there you can use set_msg_arg_string.

Thanks, a great optimization!


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

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