Replace a word in chat
#1

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.
Reply
#2

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

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
Reply
#4

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 )
    {
    }
}
Reply
#5

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
Reply
#6

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

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?
Reply
#8

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...
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)