SA-MP Forums Archive
Replace a word in chat - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Replace a word in chat (/showthread.php?tid=349659)



Replace a word in chat - [NWA]Hannes - 09.06.2012

Hello, I want something to like, replace a word that someone writes in chat.

Like if I replace "hi" with "hello", if someone write oh hi guys it gets replaced to oh hello guys.

Is this possible to do? Im not looking to censor words but to replace them with another word.

I'm only doing this for 1 word, not more.


Re: Replace a word in chat - ryansheilds - 09.06.2012

pawn Code:
public OnPlayerText(playerid, text[])
{              
    if(strcmp("hi", text, true) == 0)
    {
    // Code here..
    }
}
Think this should work?


Re: Replace a word in chat - [NWA]Hannes - 09.06.2012

Quote:
Originally Posted by ryansheilds
View Post
pawn Code:
public OnPlayerText(playerid, text[])
{              
    if(strcmp("hi", text, true) == 0)
    {
    // Code here..
    }
}
Think this should work?
No it should work like that.. This just checks if player only writes "hi"

If it makes it any easier, i only want to replace "hi" with "hello", i dont want to replace any more words.

Like if someone writes "hi" in any message it will be turned to "hello".
hi my friends > hello my friends
oh hi hannes > oh hello hannes
omg hi i havent seen you for a long time > omg hello i havent seen you for a long time


Re: Replace a word in chat - ryansheilds - 09.06.2012

Hmm use 'strfind', to find a word, but I'm not sure how to change/delete it.
pawn Code:
public OnPlayerText(playerid, text[])
{
    if(strfind(text,"hi",true) != -1 )
    {
    }
}



Re: Replace a word in chat - ReVo_ - 09.06.2012

pawn Code:
#define STRING_TO_FOUND     "hi"
    #define STRING_TO_ADD       "hello"
   
    new text[128] = "hi, whats up? im here for u";
    if(strfind(text, STRING_TO_FOUND, true) != -1) {
        new pos = strfind(text, STRING_TO_FOUND, true);
        new length = strlen(STRING_TO_FOUND);
        strdel(text, pos, length);
        strins(text, STRING_TO_ADD, pos, length);
    }
    print(text);
this little code's example maybe can help you.. i do this fast.. im not sure if it work


Re: Replace a word in chat - Mauzen - 09.06.2012

Edit: Oops, that a custom function, not a native. Dont know where I got it, but Revos code should do that job.


Re: Replace a word in chat - [NWA]Hannes - 09.06.2012

Quote:
Originally Posted by ReVo_
View Post
pawn Code:
#define STRING_TO_FOUND     "hi"
    #define STRING_TO_ADD       "hello"
   
    new text[128] = "hi, whats up? im here for u";
    if(strfind(text, STRING_TO_FOUND, true) != -1) {
        new pos = strfind(text, STRING_TO_FOUND, true);
        new length = strlen(STRING_TO_FOUND);
        strdel(text, pos, length);
        strins(text, STRING_TO_ADD, pos, length);
    }
    print(text);
this little code's example maybe can help you.. i do this fast.. im not sure if it work
Can you make an example of this at OnPlayerText?


Re : Re: Replace a word in chat - ricardo178 - 09.06.2012

Quote:
Originally Posted by [NWA]Hannes
View Post
Can you make an example of this at OnPlayerText?
pawn Code:
public OnPlayerText(playerid, text[])
{
    #define STRING_TO_FOUND     "hi"
    #define STRING_TO_ADD       "hello"
    new text[128] = "hi, whats up? im here for u";
    if(strfind(text, STRING_TO_FOUND, true) != -1) {
        new pos = strfind(text, STRING_TO_FOUND, true);
        new length = strlen(STRING_TO_FOUND);
        strdel(text, pos, length);
        strins(text, STRING_TO_ADD, pos, length);
    }
    print(text);
}
Someone with a scripting level over 9000 should know how to do this...


Re: Re : Re: Replace a word in chat - [NWA]Hannes - 09.06.2012

Quote:
Originally Posted by ricardo178
View Post
pawn Code:
public OnPlayerText(playerid, text[])
{
    #define STRING_TO_FOUND     "hi"
    #define STRING_TO_ADD       "hello"
    new text[128] = "hi, whats up? im here for u";
    if(strfind(text, STRING_TO_FOUND, true) != -1) {
        new pos = strfind(text, STRING_TO_FOUND, true);
        new length = strlen(STRING_TO_FOUND);
        strdel(text, pos, length);
        strins(text, STRING_TO_ADD, pos, length);
    }
    print(text);
}
Someone with a scripting level over 9000 should know how to do this...
Thats the wrong way to do it, I know how to copy and paste.