PDA

View Full Version : sscanf problem


ShoortyFl
27/04/2016, 01:20 AM
I have a really big sscanf problem, i want to make something but i just don't know how to upi it together.
I want to use sscanf in different tasks, so look at the code

CMD:service(playerid, params[])
{
new id, izbor[16], price, Float:PosX, Float:PosY, Float:PosZ, str[128];

if(sscanf(params, "us[16]", id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");

if(!strcmp(izbor, "heal", true))
{
if(sscanf(params, "{s[16]}i", izbor, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service heal [ID] [Price($50-$500)]");
if(!IsPlayerConnected(id)) return SCM(playerid, ERRORCOLOR, "[ERROR]: That player is not online.");

GetPlayerPos(id, Float:PosX, Float:PosY, Float:PosZ);
if(!IsPlayerInRangeOfPoint(playerid, 5.0, PosX, PosY, PosZ)) return SCM(playerid, GREY, "You must be close to that player");

CenaLecenja[id] = price;
LecenjePonudio[id] = playerid;
}
return 1;
}

and nothing is happening,p please help me

GangstaSunny
27/04/2016, 02:20 AM
@ShoortyFl
Not even that you define variables before needed/using them... are you srsly with this line?
if(sscanf(params, "us[16]", id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");

bruh...


ocmd:service(playerid, params[])
{
new id; service[16];
if(sccanf(params,"us",id,service))return SendClientMessage(playerid,0xFFFFFFFF,"[HELP]: /service [ID] [heal/repair/refill]");
{
if(strcmp(service, "heal", true, strlen(service)) == 0)
{
new price;
if(sccanf(params,"usi",id,service,price))return SendClientMessage(playerid,0xFFFFFFFF,"[HELP]: /service [ID] [heal] [Price]");
{
//DoYourStuff
}
}
}
return 1;
}


Atleast my code is untestet, try it.

Crayder
27/04/2016, 02:26 AM
I can't answer your question right now since I'm on my phone...

But IGNORE GangstaSunny's ANSWER! It's completely wrong. From what I see GangstaSunny doesn't know much at all about pawn or sscanf.

GangstaSunny
27/04/2016, 02:32 AM
I can't answer your question right now since I'm on my phone...

But IGNORE GangstaSunny's ANSWER! It's completely wrong. From what I see GangstaSunny doesn't know much at all about pawn or sscanf.

Thats sounds hard, can you please tell me what i did wrong :o

new id; service[16];
have to be
new id, service[16];

Iam sorry, its 4:37 AM here :o

PrO.GameR
27/04/2016, 07:24 AM
Here are your mistakes
CMD:service(playerid, params[])
{
new id, izbor[16], price, Float:PosX, Float:PosY, Float:PosZ, str[128];

A) Don't take up memory for things you don't need, for example if someone types /service, you still create the str[128] and floats for no reason

if(sscanf(params, "us[16]", id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");

B)Your sscanf is instructed to get id, then price (which are both integers) as an ID and a string! it should be izbor,id,price
sscanf(params, "s[16]ii",izbor, id, price))

if(sscanf(params, "{s[16]}i", izbor, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service heal [ID] [Price($50-$500)]");

C)This is perfectly useless, just check if price is between 50 and 500$

Hope you can fix it, Good luck.

biker122
27/04/2016, 07:43 AM
This should work:

CMD:service(playerid, params[])
{
new id, izbor[16], price, Float:PosX, Float:PosY, Float:PosZ, str[128];

if(sscanf(params, "s[16]ui", izbor, id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [Username/ID] [Price]");

if(!strcmp(izbor, "heal", true))
{
if(!IsPlayerConnected(id)) return SCM(playerid, ERRORCOLOR, "[ERROR]: That player is not online.");

GetPlayerPos(id, Float:PosX, Float:PosY, Float:PosZ);
if(!IsPlayerInRangeOfPoint(playerid, 5.0, PosX, PosY, PosZ)) return SCM(playerid, GREY, "You must be close to that player");

CenaLecenja[id] = price;
LecenjePonudio[id] = playerid;
}
return 1;
}


1)

if(sscanf(params, "us[16]", id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");
should be:

if(sscanf(params, "s[16]ui", izbor, id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");

The order has be given properly, with corresponding variables.

2)

if(sscanf(params, "{s[16]}i", izbor, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service heal [ID] [Price($50-$500)]");

This isn't needed, because the first sscanf check is pretty enough. So when you don't enter either izbor or name/id or price, it'll just send him back the USAGE message.