How To Replace Words 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: How To Replace Words In Chat ? (
/showthread.php?tid=339730)
How To Replace Words In Chat ? -
anonim72 - 04.05.2012
Hello,
This Is My First Post.
I need script that would replace words in chat (example: tree = leaves)
I hope you help me
Re: How To Replace Words In Chat ? -
aco_SRBIJA - 04.05.2012
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;
}
Re: How To Replace Words In Chat ? -
JaTochNietDan - 04.05.2012
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.