strval with sscanf? -
Baltimore - 16.08.2014
Hello !
In my script i use sscanf + zcmd.
In my last script i used strval.. but it's work with sscanf + zcmd?!
Re: strval with sscanf? -
Virtual1ty - 16.08.2014
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.
Re: strval with sscanf? -
MicroD - 16.08.2014
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!
Respuesta: strval with sscanf? -
Sn0wk - 16.08.2014
You really don't need sscanf if the command has
one parameter.
Anyway:
pawn Код:
static value ;
sscanf(params, "d", value);
Re: Respuesta: strval with sscanf? -
MicroD - 16.08.2014
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.
Re: strval with sscanf? -
Baltimore - 27.08.2014
How "converting" strval (strtok) in sscanf then?
Re: strval with sscanf? -
Sarra - 27.08.2014
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;
}
Re: strval with sscanf? -
Baltimore - 28.08.2014
It's good? I'm not sure
Re: strval with sscanf? -
Sarra - 28.08.2014
Yes it is!!
very easy to use, it will make it alot easier for you if you have many parameters!