sscanf optional parameters
#1

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.
Reply
#2

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
}
Reply
#3

Nevermind. I've removed the angle and interior params from the command, I have /angle and /setinterior anyway.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)