AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How str NULL (https://forums.alliedmods.net/showthread.php?t=101685)

lovemf 08-26-2009 05:09

How str NULL
 
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.

paegus 08-26-2009 05:20

Re: How str NULL
 
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.

lovemf 08-26-2009 05:53

Re: How str NULL
 
thanks friend..

DJ Tsunami 08-26-2009 07:21

Re: How str NULL
 
Quote:

Originally Posted by paegus (Post 913344)
// 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.

paegus 08-26-2009 07:24

Re: How str NULL
 
ahh didn't know that... thanks


All times are GMT -4. The time now is 19:05.

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