Raised This Month: $ Target: $400
 0% 

How str NULL


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lovemf
BANNED
Join Date: May 2009
Old 08-26-2009 , 05:09   How str NULL
Reply With Quote #1

Code:
    decl String:Name[MAX_LINE_WIDTH];
    GetClientName(client, Name, sizeof(Name));
 
    if( StrContains(Name, NULL_STRING, false)!= -1)
    return;
    SQL_TQuery(db, InsertPlayerDB, query, client);
this right? sorry my bad english,thanks.

Last edited by lovemf; 08-26-2009 at 05:14.
lovemf is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 08-26-2009 , 05:20   Re: How str NULL
Reply With Quote #2

Code:
decl Name[MAX_NAME_LENGTH] // MAX_NAME_LENGTH is predefined GetClientName(client, Name, MAX_NAME_LENGTH) // using that instead of sizeof() saves the work of figuring out how long the string is. if (strlen(Name) == 0) return
or perhaps
Code:
if (Name[0] == 0) return //...
would be better since that's even less work.

though why would it be empty? just wait until one's been retrieved. if the player really has a null string for a name then just save yourself and other players the hassle and kick/ban them right away because they're more than likely a griefer.
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod

Last edited by paegus; 08-26-2009 at 05:24.
paegus is offline
lovemf
BANNED
Join Date: May 2009
Old 08-26-2009 , 05:53   Re: How str NULL
Reply With Quote #3

thanks friend..
lovemf is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-26-2009 , 07:21   Re: How str NULL
Reply With Quote #4

Quote:
Originally Posted by paegus View Post
// using that instead of sizeof() saves the work of figuring out how long the string is.
Wrong, sizeof is calulcated at compile time, so it's not slower, and not using it gives you a lot of headaches if one of the string sizes changes.

Your second example would be the fastest, you can even do:
Code:
if(!name[0]) return;
To quickly check if the string is empty.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 08-26-2009 , 07:24   Re: How str NULL
Reply With Quote #5

ahh didn't know that... thanks
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod
paegus is offline
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 06:56.


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