sscanf problem
#1

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

pawn Код:
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
Reply
#2

@ShoortyFl
Not even that you define variables before needed/using them... are you srsly with this line?
PHP код:
if(sscanf(params"us[16]"idprice)) return SCM(playeridUPUTABOJA"[HELP]: /service [heal/repair/refill] [ID] [Price]"); 
bruh...

PHP код:
ocmd:service(playeridparams[])
{
    new 
idservice[16];
    if(
sccanf(params,"us",id,service))return SendClientMessage(playerid,0xFFFFFFFF,"[HELP]: /service [ID] [heal/repair/refill]");
    {
        if(
strcmp(service"heal"truestrlen(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.
Reply
#3

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

Quote:
Originally Posted by Crayder
Посмотреть сообщение
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

PHP код:
new idservice[16]; 
have to be
PHP код:
new idservice[16]; 
Iam sorry, its 4:37 AM here
Reply
#5

Here are your mistakes
PHP код:
CMD:service(playeridparams[])
{
    new 
idizbor[16], priceFloat:PosXFloat:PosYFloat:PosZstr[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
PHP код:
    if(sscanf(params"us[16]"idprice)) return SCM(playeridUPUTABOJA"[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
Quote:
Originally Posted by Corrected
sscanf(params, "s[16]ii",izbor, id, price))
PHP код:
        if(sscanf(params"{s[16]}i"izborprice)) return SCM(playeridUPUTABOJA"[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.
Reply
#6

This should work:
pawn Код:
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)
pawn Код:
if(sscanf(params, "us[16]", id, price)) return SCM(playerid, UPUTABOJA, "[HELP]: /service [heal/repair/refill] [ID] [Price]");
should be:
pawn Код:
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)
pawn Код:
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)