CMD:coma(playerid,params[])
#1

Hi,

I want to ask.

When you use only one parameter in command like:

/heal [player name/id]

There not need to use sscanf? you can use params, but how them use?
Reply
#2

I don't use sscanf when i only use one parameter on a command (:
Reply
#3

if it's just /heal (playerid) it should be like this (if you are using ZCMD
pawn Code:
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
pawn Code:
CMD:heal(playerid, params[])
{

    if (isnull(params)) return SendClientMessage(playerid, -1, "Usage: /heal <playerid>");
    if (strval(params)==INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Invalid player id");
    new id;
    id = strval(params);
    SetPlayerHealth(id, 100);
    SendClientMessage(id, -1, "You have been healed");
    return 1;
}
not sure about the [playername/id] in the same time , for that, I just use sscanf, sorry I'm a beginner also
Reply
#4

Quote:
Originally Posted by Ralfie
View Post
sccanf is to be used with the "u" specifier since, imo its the best for fetching id's out there;

What he's trying to say is not to use the "s" specifier only in one function which is wrong, other than that, its all good.
As he said, you can sipmy sscanf, unless you need only one parameter which is a string
Reply
#5

here example with sscanf and zcmd
Code:
CMD:sethp(playerid, params[])
{
	new playerb, amount, string[128];
    if(sscanf(params, "ui", playerb, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sethp [playerid] [amount]");
    if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
    SetPlayerHealth(playerb, amount);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)