AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Replacing letters (https://forums.alliedmods.net/showthread.php?t=282572)

Andu. 05-10-2016 14:42

Replacing letters
 
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?

Black Rose 05-10-2016 15:04

Re: Replacing letters
 
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.

Andu. 05-10-2016 15:14

Re: Replacing letters
 
I thought this method but i think there are a better way, thank you.

Bugsy 05-10-2016 20:22

Re: Replacing letters
 
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

Andu. 05-11-2016 07:07

Re: Replacing letters
 
That's a nice idea, thanks

siriusmd99 05-11-2016 09:15

Re: Replacing letters
 
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.


All times are GMT -4. The time now is 18:34.

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