sscanf and multiple parameters -
2KY - 07.08.2013
I have this code:
pawn Код:
CMD:editveh(playerid, params[])
{
new
type [25];
if( sscanf( params, "s[25]", type ) )
{
SendClientMessage (playerid, COL_SILVER, "USAGE: /editveh <type>");
return 1;
}
if( !strcmp( type, "model" ) )
{
new
vID,
vModel;
strdel( params, 0, 5);
if( sscanf( params, "ii", vID, vModel ) )
{
SendClientMessage (playerid, COL_SILVER, "USAGE: /editveh model <vehicle id> <model id>");
return 1;
}
if( fexist( GetVehiclePath(vID) ) )
{
print("d");
new
INI: Vehicle = INI_Open (GetVehiclePath (vID) ),
annStr [128],
Float: vx,
Float: vy,
Float: vz,
Float: va,
tempVID;
GetVehiclePos (vID, vx, vy, vz);
GetVehicleZAngle (vID, va);
INI_SetTag (Vehicle, "data");
INI_WriteInt (Vehicle, "model", vModel);
INI_Close (Vehicle);
INI_ParseFile( GetVehiclePath (vID), "LoadVehicle_%s", .bExtra = true, .extra = vID );
DestroyVehicle (vID);
tempVID = CreateVehicle( VehicleInfo [vID] [Model], vx, vy, vz, va, VehicleInfo [vID] [SpawnCol1], VehicleInfo [vID] [SpawnCol2], 360000 );
SetVehicleParamsEx (tempVID, VehicleInfo [vID] [EngineStatus], VehicleInfo [vID] [LightStatus], VehicleInfo [vID] [AlarmStatus], \
VehicleInfo [vID] [Locked], VehicleInfo [vID] [HoodStatus], VehicleInfo [vID] [TrunkStatus], 0
);
format (annStr, 128, "[VEHICLE] "#INT_SILVER"Vehicle %d's model has been edited to %d.", vID, vModel);
SendClientMessage (playerid, COL_LIGHTBLUE, annStr);
}
else return SendClientMessage (playerid, COL_SILVER, "This vehicle does not exist!");
}
return 1;
}
The problem is I cannot seem to get the multiple parameters to work. (EG: /editveh <model>, then there's extra parameters after the model)
What am I doing wrong?
Re: sscanf and multiple parameters -
ThePhenix - 07.08.2013
Change:
PHP код:
if( !strcmp( type, "model" ) )
to:
PHP код:
if(strcmp(type,"model", true) == 0)//It's type sorry.
Re: sscanf and multiple parameters -
2KY - 07.08.2013
I've debugged it, and the strcmp part is not the problem. The code goes past the strcmp, it gets caught on the sscanf though and I'm not quite sure why.
Re: sscanf and multiple parameters -
Ada32 - 07.08.2013
Here,
http://pastebin.com/6bX44j6s. If you're ever stumped, you should always try to re-read information on the release page.
Re: sscanf and multiple parameters -
Scenario - 07.08.2013
Basically, you need to add the first specifier to the other sscanf line(s). There's a certain thing you can do so you don't waste processing power by storing the string again though. Check this out:
pawn Код:
CMD:editveh(playerid, params[])
{
new
type [25],
vID,
vModel;
if( sscanf( params, "s[25]I(-1)I(-1)", type, vID, vModel ) )
{
SendClientMessage (playerid, COL_SILVER, "USAGE: /editveh <type>");
return 1;
}
if( !strcmp( type, "model" ) )
{
if( sscanf( params, "{s[25]}ii", vID, vModel ) )
{
SendClientMessage (playerid, COL_SILVER, "USAGE: /editveh model <vehicle id> <model id>");
return 1;
}
if( fexist( GetVehiclePath(vID) ) )
{
print("d");
new
INI: Vehicle = INI_Open (GetVehiclePath (vID) ),
annStr [128],
Float: vx,
Float: vy,
Float: vz,
Float: va,
tempVID;
GetVehiclePos (vID, vx, vy, vz);
GetVehicleZAngle (vID, va);
INI_SetTag (Vehicle, "data");
INI_WriteInt (Vehicle, "model", vModel);
INI_Close (Vehicle);
INI_ParseFile( GetVehiclePath (vID), "LoadVehicle_%s", .bExtra = true, .extra = vID );
DestroyVehicle (vID);
tempVID = CreateVehicle( VehicleInfo [vID] [Model], vx, vy, vz, va, VehicleInfo [vID] [SpawnCol1], VehicleInfo [vID] [SpawnCol2], 360000 );
SetVehicleParamsEx (tempVID, VehicleInfo [vID] [EngineStatus], VehicleInfo [vID] [LightStatus], VehicleInfo [vID] [AlarmStatus], \
VehicleInfo [vID] [Locked], VehicleInfo [vID] [HoodStatus], VehicleInfo [vID] [TrunkStatus], 0
);
format (annStr, 128, "[VEHICLE] "#INT_SILVER"Vehicle %d's model has been edited to %d.", vID, vModel);
SendClientMessage (playerid, COL_LIGHTBLUE, annStr);
}
else return SendClientMessage (playerid, COL_SILVER, "This vehicle does not exist!");
}
return 1;
}
Re: sscanf and multiple parameters -
Edix - 07.08.2013
From what I understand when you type the cmd IG it should be like /editveh model [number] [number] right?