AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   containi() always seems to match (https://forums.alliedmods.net/showthread.php?t=24838)

[DumB]Steamsucks 03-03-2006 12:13

containi() always seems to match
 
i have an ini file { minus the stars u know why there in there ) like so

f*ck|c*n8|nob|assh*le
sh*t|dick|wan*a|bas*ard

and the code i have is

Code:
#include <amxmodx> #include <amxmisc> #include <file> #include <cstrike> new Sarray[3][300] new inifile[101] new arg[192] new readdata[401]         // the data on the line it is reading new linelength = 0       // how long the line is new currline=0 stock explode( output[][], input[], delimiter, textlen, maxMatches )     {     new nIdx = 0     new nLen = (1 + copyc( output[nIdx], textlen, input, delimiter ))     new len = strlen(input)         while( nLen < len && nIdx < maxMatches )         nLen += (1 + copyc( output[++nIdx], textlen, input[nLen], delimiter ))     return nIdx + 1 } public plugin_init() {     register_plugin("Speak English", "0.1a", "[DumB]SteamSucks")         register_clcmd("say", "cmd_say")     register_clcmd("say_team", "cmd_sayteam")         inifile ="words.txt"    } public cmd_say(id)     {         new szFile[100]         get_configsdir( szFile , 99 )         format(szFile , 99 , "%s/%s", szFile, inifile)               read_args(arg, 191)     remove_quotes(arg) // Say Message are encase in Quotes           while(read_file(szFile,currline,readdata,400,linelength) != 0){  //checks every line in inifile, stores what it finds in readdata, and what line its on in currline                 explode(Sarray,readdata,'|',linelength,3)                 server_print("Badwords so far are: %s | %s | %s",Sarray[0],Sarray[1],Sarray[2])         server_print("words said are: %s",arg)                 if( !containi(arg,Sarray[2]) || !containi(arg,Sarray[1])  || !containi(arg,Sarray[2])) {             currline = 0             return PLUGIN_CONTINUE             } else {             client_print(id, print_chat, "Speak english only on this server please!!!")             server_cmd("kick %d Speak english",id)             client_cmd(id , "disconnect")             return PLUGIN_HANDLED           }                 currline++ //goes to the next line       }     currline = 0     return PLUGIN_HANDLED

when i say hi there in game in say it kicks me and i get this from console debug

Code:

Badwords so far are: f*ck | c*nt | w*nk*
words said are: hi there
Dropped ss from server
Reason:  Client sent 'drop'

none of the words i said where contained in any of the sarry items so why has it matched them any ideas any one ?

regards

[ --<-@ ] Black Rose 03-03-2006 12:24

i think you need to do like so:
Code:
if ( containi( message, "word" ) != -1 )

and shouldnt
Code:
if( !containi(arg,Sarray[2]) || !containi(arg,Sarray[1])  || !containi(arg,Sarray[2])) {
be
Code:
if( !containi(arg,Sarray[0]) || !containi(arg,Sarray[1])  || !containi(arg,Sarray[2])) {


and he wouldn't even have time to se the first msg
Code:
            client_print(id, print_chat, "Speak english only on this server please!!!")             server_cmd("kick %d Speak english",id)             client_cmd(id , "disconnect")

[DumB]Steamsucks 03-03-2006 12:30

Quote:

Originally Posted by [ --<-@
Black Rose]i think you need to do like so:
Code:
if ( containi( message, "word" ) != -1 )

and shouldnt
Code:
if( !containi(arg,Sarray[2]) || !containi(arg,Sarray[1])  || !containi(arg,Sarray[2])) {
be
Code:
if( !containi(arg,Sarray[0]) || !containi(arg,Sarray[1])  || !containi(arg,Sarray[2])) {


and he wouldn't even have time to se the first msg
Code:
            client_print(id, print_chat, "Speak english only on this server please!!!")             server_cmd("kick %d Speak english",id)             client_cmd(id , "disconnect")


i also tried the != -1 and that didnt make a difference also i put a none message in to the client while in game and it still kicked me

and i do see the speak english please on this server before it kicks me

any other ideas it would appear that it is ignoring the ini file loaded words array and just booting on any word including null string ?

p3tsin 03-03-2006 14:11

Code:

/* Checks if source contains string with case ignoring. On success function
* returns position in source, on failure returns -1. */
native containi(const source[],const string[]);

u should also have it like this (note && instead of ||):
Code:
if(containi(arg,Sarray[0]) < 0 && containi(arg,Sarray[1]) < 0 && containi(arg,Sarray[2]) < 0) {

v3x 03-03-2006 17:11

Quote:

Originally Posted by [ --<-@
Black Rose]i think you need to do like so:
Code:
if ( containi( message, "word" ) != -1 )

The way he's doing it is fine. When the string is found in the source it returns 0.


All times are GMT -4. The time now is 20:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.