strval with sscanf?
#1

Hello !

In my script i use sscanf + zcmd.

In my last script i used strval.. but it's work with sscanf + zcmd?!

pawn Код:
time = strval(timeStr);
Reply
#2

Explain more what it is that you're trying to do. Yes, sscanf can split integer values in a string by a delimiter into variables.
Reply
#3

I did not quite understand your question but if you want to ask if you could use strval+zcmd yes it's possible but pointless. Sscanf + zcmd is better way of doing command processing!
Reply
#4

You really don't need sscanf if the command has one parameter.

Anyway:

pawn Код:
static value ;
sscanf(params, "d", value);
Reply
#5

Quote:
Originally Posted by Sn0wk
Посмотреть сообщение
You really don't need sscanf if the command has one parameter.

Anyway:

pawn Код:
static value ;
sscanf(params, "d", value);
We're not talking about that kind of commands, there are more commands which require more parameters than just commands with one parameter. In that case you can simply use params as a value.
Reply
#6

How "converting" strval (strtok) in sscanf then?
Reply
#7

example
pawn Код:
CMD:getmoney(playerid, params[])
{
    new amount;
    if (sscanf(params, "i", amount) )  return SendClientMessage(playerid, -1, "Usage: /getmoney <amount>");
    GivePlayerMoney(playerid, amount);
    return 1;
}
In this example sscanf will extract the integer(amount) from the string(params)

Read more about sscanf here
https://github.com/Y-Less/sscanf/wik...nners-Tutorial
-----------
Edit:
PS: in the previous example you can just use strval(params), I just provided a simple example,
for example if you want to make a /givemoney (playerid/playername) (amount) CMD , sscanf will be very useful:
pawn Код:
CMD:givemoney(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        new id,amount;
        new string[2][128], name[2][MAX_PLAYER_NAME+1];
        if (sscanf(params, "ui", id, amount))  SendClientMessage  (playerid, 0xFFFFFFFF, "Usage: /givemoney [Player ID] [Amount]");
        else if (id == INVALID_PLAYER_ID ) SendClientMessage (playerid, 0xFF0000AA, "Invalid ID");
        else if (amount == 0) SendClientMessage(playerid, 0xFF0000AA, "Amount can't be 0$");
        else
        {
        GivePlayerMoney(id, amount);
        GetPlayerName(playerid, name[0], sizeof(name[]));
        GetPlayerName(id, name[1], sizeof(name[]));
        format(string[0], sizeof(string[]), "You have recieved %i$ from %s",amount, name[0]);
        format(string[1], sizeof(string[]), "You have given %s %i$",name[1],amount);
        SendClientMessage(playerid, 0xFFFFFFF, string[0]);
        SendClientMessage(id, 0xFFFFFFF, string[1]);
        }
    }
    return 1;

}
Reply
#8

It's good? I'm not sure
Reply
#9

Yes it is!!
very easy to use, it will make it alot easier for you if you have many parameters!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)