How To Replace Words In Chat ?
#1

Hello,

This Is My First Post.

I need script that would replace words in chat (example: tree = leaves)
I hope you help me
Reply
#2

hello. You just gonna use strfind. Nothing else

I'd do smth like this

pawn Код:
new word[][] =
{
"word1",
"word2",
"word3"
}

public OnPlayerText(playerid,text[])
{
//..........code there, without return 1;
for (new i;i!=20;i++)
{
if (strfind(text,word[i]) != -1)
return 0; //this will disable sennding that in chat;
}
return 1;
}
Reply
#3

I've whipped up a quick str_replace function for you:

pawn Код:
stock str_replace(needle[], replace[], haystack[])
{
    new index = strfind(haystack, needle, true);

    if(index == -1) return false;
   
    strdel(haystack, index, index + strlen(needle));
   
    strins(haystack, replace, index, strlen(haystack));
   
    return true;
}
You can use it like so:

pawn Код:
public OnPlayerText(playerid, text[])
{
    str_replace("tree", "leaves", text);
    return 1;
}
Hope that's what you were looking for.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)