optimizing code
#1

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

It doesn't look messy at all and I'm not sure if you can even optimize that code even more.
Reply
#3

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

PHP код:
new blocked[][] = {
    
"php","html","java"
};
Checkwords(string[]) {
    for(new 
0sizeof(blocked); i++) {
        if(
strfind(stringblocked[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
Reply
#5

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)