Raised This Month: $ Target: $400
 0% 

Change letters in a SayText hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 08-31-2012 , 18:45   Change letters in a SayText hook
Reply With Quote #1

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"); 
__________________
retired

Last edited by shavit; 08-31-2012 at 18:47.
shavit is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-31-2012 , 19:16   Re: Change letters in a SayText hook
Reply With Quote #2

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.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 08-31-2012 at 19:19.
ConnorMcLeod is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 08-31-2012 , 19:30   Re: Change letters in a SayText hook
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
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!
__________________
retired
shavit is offline
Reply


Thread Tools
Display Modes

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 08:12.


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