optimizing code - 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: optimizing code (
/showthread.php?tid=617243)
optimizing code -
Bondz - 18.09.2016
PHP код:
if(strfind(text, "php", true) || strfind(text, "html", true) != -1) //so on...
{
Error(playerid, "text not allowed.");
return false;
}
This code looks messy,how do i optimize them?
ignore the identation,it's okay on my script,not on this forum
Re: optimizing code -
FreAkeD - 18.09.2016
It doesn't look messy at all and I'm not sure if you can even optimize that code even more.
Re: optimizing code -
Bondz - 18.09.2016
I want to block lots of text,
(just an example)
PHP код:
if(strfind(text, "php", true) || strfind(text, "html", true) || strfind(text, "java", true) || strfind(text, "c++", true) || strfind(text, "pawn", true) || strfind(text, "pascal", true) || strfind(text, "c#", true) != -1)
{
Error(playerid, "text not allowed.");
return false;
}
is there any other method to do this?
Re: optimizing code -
DarkSkull - 18.09.2016
PHP код:
new blocked[][] = {
"php","html","java"
};
Checkwords(string[]) {
for(new i = 0; i < sizeof(blocked); i++) {
if(strfind(string, blocked[i], true))
return true;
}
return false;
}
if(Checkwords(text)) {
Error(playerid, "text not allowed.");
}
Try this. Just add more words to the array.
EDIT: I have edited the code. Try that
Re: optimizing code -
Gammix - 18.09.2016
pawn Код:
new const FORBIDDEN_WORDS[][] =
{
"word1",
"word2"
};
public OnPlayerText(playerid, text[])
{
for (new i, j = sizeof FORBIDDEN_WORDS; i < j; i++)
{
if (strfind(text, FORBIDDEN_WORDS[i], true) != -1)
{
Error(playerid, "text not allowed.");
return 0;
}
}
return 1;
}