COmmand makes my server crash
#1

Just made this command, if I insert a (valid) name, the server crashes.

pawn Код:
command(referral, playerid, params[])
{
    new Name[128], string[128], string2[128], IP[21], IPRef[21];
   
    if(sscanf(params, "z", Name))
    {
        if(Player[playerid][PlayingHours] >= 0)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /referral [name]");
            SendClientMessage(playerid, GREY, "Type the FULL NAME of your referral, and not an ID");
            SendClientMessage(playerid, GREY, "NOTE: This command is CaSe SeNsItIvE.");
        }
    }
    else
    {
        if(Player[playerid][PlayingHours] >= 0)
        {
            if(strlen(Name) >= 3 && strlen(Name) < MAX_PLAYER_NAME+1)
            {
                format(string2, sizeof(string2), "Accounts/%s.ini", Name);
                if(fexist(string2))
                {
                    if(Player[playerid][PlayingHours] >= 3)
                    {
                        SendClientMessage(playerid, WHITE, "You already have more than two playing hours, you cannot do this anymore!");
                    }
                    else
                    {
                        SendClientMessage(playerid, WHITE, "You added %s succesfully as your referral!", Name);
                        SendClientMessage(playerid, WHITE, "If you had a referral already, that one will be replaced by the new one!");
                        format(Player[playerid][Ref], 255, Name);
                    }
                }
                else
                {
                    SendClientMessage(playerid, WHITE, "Account not found. Remember this command is CaSe SeNsEtIvE ");
                }
            }
        }
    }
    return 1;
}
Reply
#2

wtf is this:
pawn Код:
format(Player[playerid][Ref], 255, Name);
??
Reply
#3

And this
Quote:

if(sscanf(params, "z", Name))

It should be "s"
Reply
#4

Use:

pawn Код:
command(referral, playerid, params[])
{
    new Name[128], string[128], string2[128], IP[21], IPRef[21];
   
    if(sscanf(params, "s", Name))
    {
        if(Player[playerid][PlayingHours] >= 0)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /referral [name]");
            SendClientMessage(playerid, GREY, "Type the FULL NAME of your referral, and not an ID");
            SendClientMessage(playerid, GREY, "NOTE: This command is CaSe SeNsItIvE.");
        }
    }
    else
    {
        if(Player[playerid][PlayingHours] >= 0)
        {
            if(strlen(Name) >= 3 && strlen(Name) < MAX_PLAYER_NAME+1)
            {
                format(string2, sizeof(string2), "Accounts/%s.ini", Name);
                if(fexist(string2))
                {
                    if(Player[playerid][PlayingHours] >= 3)
                    {
                        SendClientMessage(playerid, WHITE, "You already have more than two playing hours, you cannot do this anymore!");
                    }
                    else
                    {
                        format(string, sizeof(string), "You added %s succesfully as your referral!", Name);
                        SendClientMessage(playerid, WHITE, string);
                        SendClientMessage(playerid, WHITE, "If you had a referral already, that one will be replaced by the new one!");
                    }
                }
                else
                {
                    SendClientMessage(playerid, WHITE, "Account not found. Remember this command is CaSe SeNsEtIvE ");
                }
            }
        }
    }
    return 1;
}
Reply
#5

format(Player[playerid][Ref], 255, Name); is to put the name of the referral in their account.
Reply
#6

Well, but this line crashes your server:

SendClientMessage(playerid, WHITE, "You added %s succesfully as your referral!", Name);

You must format the string with the name and after thet sendckient message with string:

format(string, sizeof(string), "You added %s succesfully as your referral!", Name);
SendClientMessage(playerid, WHITE, string);
Reply
#7

Oh stupid me, I forgot to make it a string!

Thank you bro, I will change it and try if it works.
Reply
#8

format(Player[playerid][Ref], 255, Name); doesn't seem to work... it doesn't save the name of the player.
Reply
#9

So I tried this:
pawn Код:
format(Player[playerid][Ref], 255, "%s", Name);
But that did nto work either...
Reply
#10

You never used GetPlayerName so 'Name' is always blank.

@The guys who said you need to use 's' instead of 'z'

You can use both of them but using 'z' will give you a sscanf warning. Both of them do the same thing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)