sscanf error
#1

Код:
CMD:changeplate(playerid, params[])
{
	if(Player_Data[playerid][Donator] == 0)
	{
		return SCM(playerid, RED, "You need to have atleast Donator level 1 for this command.");
	}
	else
 	{
  		if(GetPlayerState(playerid != PLAYER_STATE_DRIVER))
  		{
  			return SCM(playerid, RED, "You need to be in a vehicle to change it's numberplate.");
		}
		else
    	{
    	    new VehID = GetPlayerVehicleID(playerid);

       		if(sscanf(params, "s[8]", stringnplate)) return SCM(playerid, GREY, "[SERVER]: Usage: /changeplate [NUMBER/WORD COMBINATION] - Maximum 8 numbers/letters");
			if(1 > strlen(stringnplate) > 8)
			{
				SCM(playerid, GREY, "[SERVER]: ERROR: Your numberplate must be be between 1 and 8 characters");
			}
			else
			{
          		SetVehicleNumberPlate(VehID, stringnplate);
          		SetVehicleToRespawn(VehID);
          		PutPlayerInVehicle(playerid, VehID, 0);
          		return 1;
			}
                }
	}
	return 1;
}
I get the error in the console: sscanf warning: Format specifier does not match parameter count.
Reply
#2

pawn Код:
CMD:changeplate(playerid, params[])
{
    if(Player_Data[playerid][Donator] == 0)
    {
        return SCM(playerid, RED, "You need to have atleast Donator level 1 for this command.");
    }
    else
    {
        if(GetPlayerState(playerid != PLAYER_STATE_DRIVER))
        {
            return SCM(playerid, RED, "You need to be in a vehicle to change it's numberplate.");
        }
        else
        {
            new VehID = GetPlayerVehicleID(playerid), stringnplate[8];

            if(sscanf(params, "s[8]", stringnplate)) return SCM(playerid, GREY, "[SERVER]: Usage: /changeplate [NUMBER/WORD COMBINATION] - Maximum 8 numbers/letters");
            if(strlen(stringnplate) < 1 || strlen(stringnplate) > 8)
            {
                SCM(playerid, GREY, "[SERVER]: ERROR: Your numberplate must be be between 1 and 8 characters");
            }
            else
            {
                SetVehicleNumberPlate(VehID, stringnplate);
                SetVehicleToRespawn(VehID);
                PutPlayerInVehicle(playerid, VehID, 0);
                return 1;
            }
                }
    }
    return 1;
}
Reply
#3

Thanks but, now it says sscanf warning: String buffer overflow. :/
Reply
#4

Quote:
Originally Posted by Duck4coder
Посмотреть сообщение
Thanks but, now it says sscanf warning: String buffer overflow. :/
pawn Код:
CMD:changeplate(playerid, params[])
{
    if(Player_Data[playerid][Donator] == 0)
    {
        return SCM(playerid, RED, "You need to have atleast Donator level 1 for this command.");
    }
    else
    {
        if(GetPlayerState(playerid != PLAYER_STATE_DRIVER))
        {
            return SCM(playerid, RED, "You need to be in a vehicle to change it's numberplate.");
        }
        else
        {
            new VehID = GetPlayerVehicleID(playerid), stringnplate[128];

            if(sscanf(params, "s[128]", stringnplate)) return SCM(playerid, GREY, "[SERVER]: Usage: /changeplate [NUMBER/WORD COMBINATION] - Maximum 8 numbers/letters");
            if(strlen(stringnplate) < 1 || strlen(stringnplate) > 8)
            {
                SCM(playerid, GREY, "[SERVER]: ERROR: Your numberplate must be be between 1 and 8 characters");
            }
            else
            {
                SetVehicleNumberPlate(VehID, stringnplate);
                SetVehicleToRespawn(VehID);
                PutPlayerInVehicle(playerid, VehID, 0);
                return 1;
            }
                }
    }
    return 1;
}
Reply
#5

It's not necessary to use sscanf for it when you can use params.

pawn Код:
CMD:changeplate(playerid, params[])
{
    if (!Player_Data[playerid][Donator]) return SCM(playerid, RED, "You need to have atleast Donator level 1 for this command.");
    if (GetPlayerState(playerid != PLAYER_STATE_DRIVER)) return SCM(playerid, RED, "You need to be in a vehicle to change it's numberplate.");
    if (isnull(params)) return SCM(playerid, GREY, "[SERVER]: Usage: /changeplate [NUMBER/WORD COMBINATION] - Maximum 8 numbers/letters");
    if (!(1 <= strlen(params) <= 8)) return SCM(playerid, GREY, "[SERVER]: ERROR: Your numberplate must be be between 1 and 8 characters");
    new VehID = GetPlayerVehicleID(playerid);
    SetVehicleNumberPlate(VehID, params);
    SetVehicleToRespawn(VehID);
    PutPlayerInVehicle(playerid, VehID, 0);
    return 1;
}
Reply
#6

Thanks soo much man
1+ Rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)