Add commas to sscanf params. -
Black Axe - 14.01.2016
Hello!
I've started learning sscanf recently after a long time of painful strtok usage and I've realized that sscanf is SO much easier, I've been missing out.
Anyway, I am trying to make a simple /goto command. I've already written the command and it works fine.
Код:
CMD:goto(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pAdmin] >= 2)
{
new Float:X, Float:Y, Float:Z, string[128];
if(sscanf(params, "fff", X, Y, Z)) return SCM(playerid, -1, "USAGE: /goto [X] [Y] [Z]");
SetPlayerPos(playerid, X, Y, Z);
format(string, sizeof(string), "You have teleported to the follow coordinates: %f, %f, %f.", X, Y, Z);
SCM(playerid, -1, string);
return 1;
}
}
return 1;
}
The question is, is it possible to make it read the coords entry with commas?
Because for this command to works, it needs to be in such format:
Код:
/goto 0.00 0.00 0.00
Is it possible to make it like this aswell?
Код:
/goto 0.00, 0.00, 0.00
Thanks!
Re: Add commas to sscanf params. -
PrO.GameR - 14.01.2016
Here's a suggestion first,
A) if someone does a command, he is connected !
B) if you want to check if something is true and send an error message use it's opposite, so
PHP код:
if(PlayerInfo[playerid][pAdmin] < 2) return 0; // or /return scm(playerid,color,sth);
Here's your normal code
This will generally avoid unnecessary brackets just for 1 error message, and you won't be confused because the if and the error msg are not close to each other.
Now to your problem,
https://sampforum.blast.hk/showthread.php?tid=570927 section "Delimiters":
PHP код:
sscanf("1,2,3", "p<,>fff", x,y,z);
will do the trick for you.
Re: Add commas to sscanf params. -
Black Axe - 15.01.2016
Quote:
Originally Posted by PrO.GameR
Here's a suggestion first,
A) if someone does a command, he is connected !
B) if you want to check if something is true and send an error message use it's opposite, so
PHP код:
if(PlayerInfo[playerid][pAdmin] < 2) return 0; // or /return scm(playerid,color,sth);
Here's your normal code
This will generally avoid unnecessary brackets just for 1 error message, and you won't be confused because the if and the error msg are not close to each other.
Now to your problem, https://sampforum.blast.hk/showthread.php?tid=570927 section "Delimiters":
PHP код:
sscanf("1,2,3", "p<,>fff", x,y,z);
will do the trick for you.
|
Not really, That's what I get when I launch samp-server.exe :
Код:
sscanf warning: Unenclosed specifier parameters are deprecated, consider using something like p<,>.
I've been reading through sscanf's thread I cant find anything related to this.
EDIT: Never mind that's something else, fixed it tho. Thanks!
Re: Add commas to sscanf params. -
PrO.GameR - 15.01.2016
Np xD Just a tip, that warning was when someone used p, not p<,>
Both work, first one is the old version and gives the warning.