SA-MP Forums Archive
Problems with sscanf - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problems with sscanf (/showthread.php?tid=308615)



Problems with sscanf - Bogdan1992 - 04.01.2012

When i type /car it gaves me unknown command and i want to return this message " SendClientMessage(playerid, COLOR_RED, "USAGE:{FFFFFF} /car [modelid/carname] [color1] [color2]"); ". But if i type /car model col1 col2 its working. Any ideas.

PHP Code:
CMD:car(playeridparams[])
{
    if(
DMZONE[playerid] == || DMZONE[playerid] == 2) return SendClientMessage(playeridCOLOR_RED"ERROR: {FFFFFF}You can't spawn a vehicle in dm zone.");
    
iSeat GetPlayerVehicleSeat(playerid);    if(!(iSeat == || iSeat == -1)) return SendClientMessage(playeridCOLOR_RED"ERROR: {FFFFFF}You can't spawn a car if you are into someones vehicle.");
    new 
Indexcar;    new tmp[256];  tmp  strtok(params,Index);    new tmp2[256]; tmp2 strtok(params,Index);    new tmp3[256]; tmp3 strtok(params,Index); new colour1colour2string[128];
    if(
sscanf(params,"i",tmp)) return    SendClientMessage(playeridCOLOR_RED"USAGE:{FFFFFF} /car [modelid/carname] [color1] [color2]");
    if(!
IsNumeric(tmp))    car GetVehicleModelIDFromName(tmp);    else car strval(tmp);
    if(!
IsValidCar(car)) return SendClientMessage(playerid,COLOR_RED,"ERROR: {FFFFFF}This model is blacklisted");
    if(!
strlen(tmp2)) colour1 random(126); else colour1 strval(tmp2);
    if(!
strlen(tmp3)) colour2 random(126); else colour2 strval(tmp3);
    if(
SpawnedVehicles[playerid] != 0DestroyVehicle(SpawnedVehicles[playerid]);
    new 
Float:Xx,Float:Yy,Float:Zz;    new Float:Angle,int1;    new LVehicleID GetPlayerVehicleID(playerid);
    
GetPlayerPos(playeridXx,Yy,Zz);    GetPlayerFacingAngle(playerid,Angle);    int1 GetPlayerInterior(playerid);
    
SpawnedVehicles[playerid] = CreateVehicle(carXx,Yy,ZzAnglecolour1colour2, -1);
    
LinkVehicleToInterior(LVehicleID,int1);    PutPlayerInVehicle(playerid,SpawnedVehicles[playerid],0);
    
format(stringsizeof(string), "SYSTEM:{FFFFFF} You spawned a %s"VehicleNames[car-400]);
    return 
SendClientMessage(playeridCOLOR_REDstring);




Re: Problems with sscanf - Vince - 04.01.2012

That is some messy code with a lot of unnecessary variables. Your script won't get any slower if you just add some whitespace. Here's the fixed code.

pawn Code:
CMD:car(playerid, params[])
{
    if(DMZONE[playerid] == 1 || DMZONE[playerid] == 2)
        return SendClientMessage(playerid, COLOR_RED, "ERROR: {FFFFFF}You can't spawn a vehicle in dm zone.");

    iSeat = GetPlayerVehicleSeat(playerid);
    if(!(iSeat == 0 || iSeat == -1))
        return SendClientMessage(playerid, COLOR_RED, "ERROR: {FFFFFF}You can't spawn a car if you are into someones vehicle.");
       
    new
        car,
        colour1,
        colour2,
        string[128];
       
    if(sscanf(params,"iI(-1)I(-1)", car, colour1, colour2))
        return SendClientMessage(playerid, COLOR_RED, "USAGE:{FFFFFF} /car [modelid/carname] [color1] [color2]");

    if(!IsValidCar(car))
        return SendClientMessage(playerid,COLOR_RED,"ERROR: {FFFFFF}This model is blacklisted");

    colour1 = (colour1 == -1) ? random(126) : colour1;
    colour2 = (colour2 == -1) ? random(126) : colour2;

    if(SpawnedVehicles[playerid] != 0)
        DestroyVehicle(SpawnedVehicles[playerid]);

    new
        Float:Xx,
        Float:Yy,
        Float:Zz,
        Float:Angle,
        int1;

    GetPlayerPos(playerid, Xx,Yy,Zz);
    GetPlayerFacingAngle(playerid,Angle);
    int1 = GetPlayerInterior(playerid);

    SpawnedVehicles[playerid] = CreateVehicle(car, Xx, Yy, Zz, Angle, colour1, colour2, -1);
    LinkVehicleToInterior(SpawnedVehicles[playerid], int1);
    PutPlayerInVehicle(playerid, SpawnedVehicles[playerid], 0);

    format(string, sizeof(string), "SYSTEM:{FFFFFF} You spawned a %s", VehicleNames[car-400]);
    SendClientMessage(playerid, COLOR_RED, string);
    return 1;
}