Raised This Month: $ Target: $400
 0% 

How to get a word is in String/player name or not?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-18-2015 , 08:38   How to get a word is in String/player name or not?
Reply With Quote #1

Tried StrEqual/StrContains/strcmp to check if there's a word in string or player name, none of them work. any help about it?

This is now what i do:

PHP Code:
new String:sAuthString[32];
GetClientName(clientsAuthStringsizeof(sAuthString));
        
if(!
IsFakeClient(client) && StrEqual(sAuthString""false))
    return;
    
new 
Handle:hFile OpenFile(logfilepath"r");
if(
hFile != INVALID_HANDLE)
{
    new 
String:sLine[4096];
    while(!
IsEndOfFile(hFile))
    {
        
ReadFileLine(hFilesLinesizeof(sLine));
        for(new 
0;<= MaxClients;i++)
        {
            if(
StrContains(sLine[i], sAuthStringfalse) != -1)
            {
                
//do something here
            
}
        }
    }
    
CloseHandle(hFile);

Also.. the for loop will cause a bug make this function run many time, for example i want print out something will be

Code:
Playername is xxx
Playername is xxx
Playername is xxx
Playername is xxx
Playername is xxx
Playername is xxx
...
but if i remove the for loop, this function don't work.

Last edited by gilmon; 09-19-2015 at 04:34.
gilmon is offline
Send a message via MSN to gilmon
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-19-2015 , 04:35   Re: How to get a word is in String/player name or not?
Reply With Quote #2

Sorry guys, problem changed so i bump it myself.
gilmon is offline
Send a message via MSN to gilmon
lingzhidiyu
Senior Member
Join Date: Mar 2014
Old 09-19-2015 , 09:51   Re: How to get a word is in String/player name or not?
Reply With Quote #3

remove loop and

if(StrContains(sLine[i], sAuthString, false) != -1)
{
//do something here
}

if(StrContains(sLine, sAuthString, false) != -1)
{
//do something here
}

Last edited by lingzhidiyu; 09-19-2015 at 09:52.
lingzhidiyu is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-19-2015 , 09:53   Re: How to get a word is in String/player name or not?
Reply With Quote #4

ReadFileLine returns the line WITH the newline character at the end IIRC, so you would need to remove that

also I'm assuming you want StrContains(sLine, sAuthString, false), not StrContains(sLine[i], sAuthString, false)

Quote:
Originally Posted by gilmon View Post
Also.. the for loop will cause a bug make this function run many time
That's the purpose of for loops
Miu is offline
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-20-2015 , 04:13   Re: How to get a word is in String/player name or not?
Reply With Quote #5

thanks, will try it later when back home.
gilmon is offline
Send a message via MSN to gilmon
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-20-2015 , 07:14   Re: How to get a word is in String/player name or not?
Reply With Quote #6

Sorry still don't work, although it won't loop many time but the main function is still not working right.

For example i want check is playername include "abc" when his name is "abcdefg" or with space/symbol in his name like "abc def" , "abc d e f" , "abc : def" this not work, only will work right when his name is "abc" complete match.
gilmon is offline
Send a message via MSN to gilmon
lingzhidiyu
Senior Member
Join Date: Mar 2014
Old 09-20-2015 , 08:06   Re: How to get a word is in String/player name or not?
Reply With Quote #7

if(StrContains(sLine, sAuthString, false) != -1)
{
//do something here
}

if(StrContains(sAuthString, sLine, false) != -1)
{
//do something here
}
lingzhidiyu is offline
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-20-2015 , 08:21   Re: How to get a word is in String/player name or not?
Reply With Quote #8

still.. and this function don't work again even name complete match.
gilmon is offline
Send a message via MSN to gilmon
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-20-2015 , 08:46   Re: How to get a word is in String/player name or not?
Reply With Quote #9

How about you print out what you compare like this so you can see why it fails?
PHP Code:
PrintToServer("Comparing '%s' with '%s'"sLinesAuthString); 
__________________

Last edited by Impact123; 09-20-2015 at 09:21.
Impact123 is offline
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 09-20-2015 , 09:05   Re: How to get a word is in String/player name or not?
Reply With Quote #10

Quote:
Originally Posted by Impact123 View Post
PHP Code:
PrintToServer("Comparing '%s' ´with '%s'"sLinesAuthString); 
yes it will show what compared like

Code:
Comparing 'ABCDEFG' ´with '123'
Comparing 'abcdefg' ´with '123'
Comparing '12345678' ´with '123'
Comparing 'ABC' ´with '123'
Comparing '123' ´with '123'
Comparing '123456' ´with '123'
this is now what i do more:

PHP Code:
if(StrContains(sAuthStringsLinefalse) != -1)
{
    
PrintHintText(client"Please change your name, you can't use name like %N!"sAuthString);
}
else
{
    
PrintToServer("Comparing '%s' ´with '%s'"sLinesAuthString); 


Last edited by gilmon; 09-20-2015 at 09:06.
gilmon is offline
Send a message via MSN to gilmon
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:55.


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