11.03.2009, 13:10
I try to build a censor words filter.. but I have a problem with the strfind function :
Global vars :
Init the censor words array :
until now all works... I tried to print all the array, it's work.
Here is the problem :
lets say the censor words are : one, two, three.
If I write in the game sentence with one or more of the words except the last one, nothing happens.
But if I write a sentence with the last word it's work and censor the sentence.
edit :
hmmmm... if I init the array like this :
new words[MAX_WORDS][MAX_STRING] = {"one","two","three","*EOF*"};
All works... so I guess the problem in the OnFilterScriptInit.. but what :\ ?
Global vars :
Код:
enum String { string[50] }; new words[MAX_WORDS][String];
Код:
public OnFilterScriptInit() { new File:fp; new count = 0; new word[50]; fp = fopen("CensorWords.txt",io_read); while (fread(fp,word,sizeof(word))) words[count++][string] = word; printf("number of censor words : %d",count); word = "*EOF*"; words[count][string] = word; fclose(fp); return 1; }
Here is the problem :
Код:
public OnPlayerText(playerid, text[]) { new censor[50], num; new line[128]; for (new i=0; i<MAX_WORDS; i++) { memcpy(censor,words[i][string],0,sizeof(censor)); if (!strcmp(censor,"*EOF*",true)) break; SendClientMessage(playerid,0xff0022ff,censor); num = strfind(text,censor,true); if (num != -1) { format(line,sizeof(line),"%s message censored by the system !",GetName(playerid)); SendClientMessage(playerid,0xff0033ff,line); return false; } } return true; }
If I write in the game sentence with one or more of the words except the last one, nothing happens.
But if I write a sentence with the last word it's work and censor the sentence.
edit :
hmmmm... if I init the array like this :
new words[MAX_WORDS][MAX_STRING] = {"one","two","three","*EOF*"};
All works... so I guess the problem in the OnFilterScriptInit.. but what :\ ?