sscanf optional parameters - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: sscanf optional parameters (
/showthread.php?tid=273820)
sscanf optional parameters -
MP2 - 03.08.2011
I have a /SETPOS command, with these parameters:
X, Y, Z, ANGLE, INTERIOR
X Y and Z are required, but angle and interior, if omitted, should remain the same.
If 4 parameters are input, the fourth should be interior, not angle. If 5 are input, the 5th will be interior.
Hope you understand, any help appreciated.
EDIT: I tried this, but it crashes the server:
pawn Code:
dcmd_setpos(playerid, params[])
{
new Float:setposx, Float:setposy, Float:setposz, Float:setposa, setposi;
if(sscanf(params, "fffF(-1.0)I(-1)", setposx, setposy, setposz, setposa, setposi)) return ShowSyntax(playerid, "/SETPOS [X] [Y] [Z] <ANGLE> <INTERIOR>", "Set your position.");
if(GetPlayerState(playerid) != 2) SetPlayerPos(playerid, setposx, setposy, setposz);
else SetVehiclePos(GetPlayerVehicleID(playerid), setposx, setposy, setposz);
SetPlayerFacingAngle(playerid, setposa);
SetPlayerInterior(playerid, setposi);
return 1;
}
I thought maybe I could then check if it was -1, to see if it was input.
Re: sscanf optional parameters -
Patrik356b - 03.08.2011
Why don't you swap angle and interior ? - it will be easier to construct
Code:
if(sscanf(params, "fffIF", tmpX, tmpY, tmpZ, tmpInt, tmpAngle))
{
// Error msg here
}
Re: sscanf optional parameters -
MP2 - 03.08.2011
Nevermind. I've removed the angle and interior params from the command, I have /angle and /setinterior anyway.