Sscanf ..
#1

So, eh, I created the command /vipcar, and it should allow you to choose one of the 4 cars.
For an example:
/vipcar Caddy
It would spawn you, and put you in a Caddy.

But, it doesn't let me select it, it just puts me in the Infernus.

Here's the code

pawn Код:
CMD:vipcar(playerid, params[]) {
    new string[84], car;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    new Float:Angle;
    GetPlayerFacingAngle(playerid, Angle);
    if(PlayerInfo[playerid][pVIP] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "[VIP] - Only VIPS can use this command!");
    new infernus, bullet, caddy, sultan;
    if(sscanf(params, "i", infernus))
    {
        car = CreateVehicle(411, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(sscanf(params, "i", bullet))
    {
        car = CreateVehicle(541, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(sscanf(params, "i", sultan))
    {
        car = CreateVehicle(560, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(sscanf(params, "i", caddy))
    {
        car = CreateVehicle(457, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    return 1;
}
I suppose that I've done something wrong at the "else if(sscanf.....))", but what?
Maybe the "i"?


EDIT:
If somebody fixes this, could you explain me what did you change?
Because i would need to fix /vipbike, /vipboat and /vipheli too then.
Reply
#2

i is for integers use %s and create 1 string variable to save the input from sscanf

pawn Код:
CMD:vipcar(playerid, params[])
{
    if(PlayerInfo[playerid][pVIP] == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "[VIP] - Only VIPS can use this command!");

    new vehicle[64];
    new string[84], car;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    new Float:Angle;
    GetPlayerFacingAngle(playerid, Angle);
    if(sscanf(params, "s[64]", vehicle)) return SendClientMessage(playerid,0xFFFFFFFF,"Usage: /vipcar name");
    if(strcmp(vehicle,"infernus",true,8) == 0) // If Vehicle == infernus, true means ignore CaSeSeNsItIvE
    {
        car = CreateVehicle(411, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(vehicle,"bullet",true,6) == 0) // the 6 is in this case is because bullet is 6 chars
    {
        car = CreateVehicle(541, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(vehicle,"sultan",true,6) == 0)
    {
        car = CreateVehicle(560, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(vehicle,"caddy",true,5) == 0)
    {
        car = CreateVehicle(457, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else
    {
        SendClientMessage(playerid,0xFFFFFFFF,"[VIP] Invalid Vip Car Type");
    }
    return 1;
}
Reply
#3

Using sscanf with zmcd to one parameter is stupid and not optimally.
Код:
CMD:vipcar(playerid, params[])
{
    new string[84], car;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x,y,z);
    new Float:Angle;
    GetPlayerFacingAngle(playerid, Angle);
    if(isnull(params)) return SendClientMessage(playerid,0xFFFFFFFF,"Usage: /vipcar name");
    if(strcmp(params,"infernus",true,8) == 0) // If Vehicle == infernus, true means ignore CaSeSeNsItIvE
    {
        car = CreateVehicle(411, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(params,"bullet",true,6) == 0) // the 6 is in this case is because bullet is 6 chars
    {
        car = CreateVehicle(541, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(params,"sultan",true,6) == 0)
    {
        car = CreateVehicle(560, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else if(strcmp(params,"caddy",true,5) == 0)
    {
        car = CreateVehicle(457, x,y,z, Angle, random(128), random(128), 180);
        PutPlayerInVehicle(playerid, car, 0);
        new sender[MAX_PLAYER_NAME];
        GetPlayerName(playerid, sender, sizeof(sender));
        format(string, sizeof(string), "[ADMIN] - VIP %s[%d] has used VIPCAR", sender, playerid);
        format(string, sizeof(string), "[VIP] - %s[%d] has used VIPCAR", sender, playerid);
        SendMessageToVIPS(string);
    }
    else
    {
        SendClientMessage(playerid,0xFFFFFFFF,"[VIP] Invalid Vip Car Type");
    }
    return 1;
}
Reply
#4

Thanks guys!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)