strlen not working
#1

In this cmd:
PHP код:
CMD:vipname(playeridparams[])
{
    new 
text[10], szMessage[256];
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(
sscanf(params"s[50]"text)) return SCM(playeridCOLOR_WHITE"SYNTAX: /vipname [name]");
    if(
PlayerInfo[playerid][pPremiumAccount] != 1) return SCM(playeridCOLOR_ERROR"You don't have a premium account");
    {
        if(
vText[playerid] != -1) return SCM(playeridCOLOR_WHITE"Use first /removename to put another name on your car.");
        if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playeridCOLOR_WHITE"You aren't in any car.");
        if(
GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SCM(playeridCOLOR_ERROR"You aren't the driver.");
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) != 411) return SCM(playeridCOLOR_ERROR"Car must be an Infernus in order to apply this command.");
        if(
OwnedVeh(vehicleid))
        {
            new 
maxc strlen(text);
            if(
maxc 10) return SCM(playerid,COLOR_WHITE,"{FFB870}Maximum caracters are 10.");
            
vText[playerid] = CreateObject(19327, -2597.0762, -2638.4270, -5.3536, -87.699990.4001, -87.1805);
            
SetObjectMaterialText(vText[playerid] , text050"Arial"1510xFFFFFFFF01);
            
AttachObjectToVehicle(vText[playerid] , vehicleid0.0,-1.90.3270.00.00.0);
            
format(szMessagesizeof(szMessage), "{F2CF09}Vipname is: '%s'"text);
            
SCM(playeridCOLOR_YELLOWszMessage);
            new var[
356];
            
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%s'"textPlayerInfo[playerid][pNormalName]);
            
mysql_tquery(SQL, var,"","");
        }
    }
    return 
1;

Player can override 10 caracters,
also i want a query to load this text string onplayerlogin
Reply
#2

Issue:

Look at this line, you have the string size for 'text' set to the size of 10, yet in your sscanf function your telling it the string can fit the size of 50 in it?

Код:
if(sscanf(params, "s[50]", text)) return SCM(playerid, COLOR_WHITE, "SYNTAX: /vipname [name]"); // "s[50]" should be "s[10]"
There also no need to create a variable to hold the value of strlen, when you only use it once.

Also: Why are you checking if the strlen is more then 10 after everything else? Move it to after you call your sscanf function. However you don't even need to do that, since sscanf will cut off the text after 10.

Код:
if( strlen( text ) > 10 ) return SCM( playerid, COLOR_WHITE, "{FFB870}Maximum allowed characters are 10." ); // if you must use it
Reply
#3

Just do
PHP код:
if(strlen(text) > 10// error message 
You don't need to create a new variable for the strlen.
And for the Info: '<' = lower | '>' = higher
Reply
#4

oh thanks both,
and what about the mysql load query on player login?
Reply
#5

Use Dini bro xD
Reply
#6

Quote:
Originally Posted by MiiSha
Посмотреть сообщение
Use Dini bro xD
This is a help section, your input does not help the users at all, but instead suggesting he uses an old include when there are far more better ones available.

Please keep your witty remarks to yourself, or find another fitting section to post on.
Reply
#7

Quote:
Originally Posted by MiiSha
Посмотреть сообщение
Use Dini bro xD
Dini? You must be kidding me. Why use Dini when there are 100x better INI processors? Not to even mention MySQL is superior in a lot of ways. Keep your remarks to yourself.

Can you elaborate on your question please? I am not sure if I understood what you wanted to do with the query.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)