Raised This Month: $ Target: $400
 0% 

Replacing letters


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Andu.
Member
Join Date: Oct 2013
Location: Belgravistan
Old 05-10-2016 , 14:42   Replacing letters
Reply With Quote #1

Hello.
I want to replace a word with '*'
I've done the code for that
PHP Code:
public cmdSay(id)
{
    new 
szArg[128], iPos,len;
    
read_args(szArg127);

    if((
iPos containi(szArg"word")) != -1)
    {
            
        
len strlen("word");
        while(
len--)
        {
            
szArg[iPos++] = '*';
            
//client_prin(id,print_chat, "%s",szArg);
        
}
    }

If i uncomment //client_prin(id,print_chat, "%s",szArg); it shows all steps like : if i say hello word it will show me hello *ord hello **rd etc.. else when i write the word, it shows on chat my word without censure.
Something i expected?
Andu. is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-10-2016 , 15:04   Re: Replacing letters
Reply With Quote #2

Well, you have to block the "SayText" message and supply your own.

In this plugin, it blocks the message and forces the client to write a new one with the edited string. Simple yet effective.
https://forums.alliedmods.net/showthread.php?t=1404

You can also create your own SayText message.
__________________

Last edited by Black Rose; 05-10-2016 at 15:07.
Black Rose is offline
Andu.
Member
Join Date: Oct 2013
Location: Belgravistan
Old 05-10-2016 , 15:14   Re: Replacing letters
Reply With Quote #3

I thought this method but i think there are a better way, thank you.
Andu. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-10-2016 , 20:22   Re: Replacing letters
Reply With Quote #4

How about using replace_all()?
PHP Code:
#include <amxmodx>

enum WordData
{
    
BadWord15 ],
    
ReplaceWith15 ]
}

new const 
Words[][ WordData ] = 
{
    { 
"heck" "****" },
    { 
"cheech" "******" },
    { 
"toot" "****" },
    { 
"lol" "***" }
}

public 
plugin_init() 
{
    
Test();
}

public 
Test() 
{
    new 
szTest[] = "Hey man, what the heck are you doing cheech? I think you just tried to toot. lol at that";
    
    for ( new 
sizeofWords ) ; i++ )
        
replace_allszTest charsmaxszTest ) , Words][ BadWord ] , Words][ ReplaceWith ] );
    
    
server_printszTest );

Output
Code:
Hey man, what the **** are you doing ******? I think you just tried to ****. *** at that
__________________

Last edited by Bugsy; 05-10-2016 at 22:21.
Bugsy is offline
Andu.
Member
Join Date: Oct 2013
Location: Belgravistan
Old 05-11-2016 , 07:07   Re: Replacing letters
Reply With Quote #5

That's a nice idea, thanks
Andu. is offline
Old 05-11-2016, 08:13
siriusmd99
This message has been deleted by siriusmd99. Reason: nvm
Old 05-11-2016, 08:18
Andu.
This message has been deleted by Andu.. Reason: wrong
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-11-2016 , 09:15   Re: Replacing letters
Reply With Quote #6

Ohh.. sorry i'm replacing first array cells which is not ok, i removed my post, remove your quote too because it contains my wrong code which can confuse people.

Last edited by siriusmd99; 05-11-2016 at 09:16.
siriusmd99 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 04:19.


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