Optional string (sscanf) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Optional string (sscanf) (
/showthread.php?tid=658929)
Optional string (sscanf) -
NealPeteros - 16.09.2018
So I wanted to create a /mute command wherein the admin who uses the command may or may not input a reason as to why he'd mute the player. Here's where I got so far
PHP код:
CMD:mute(playerid, params[])
{
new id, reason[64], time;
if (sscanf(params, "dS[24]d", id, reason, time))
{
SendClientMessage(playerid, -1, "USAGE: /mute [id] [reason (optional)] [minutes]");
return 1;
}
Mute(id, reason, time);
return 1;
}
Thing is that when I use it, say for example, like this
/mute - the command
1 - the ID
20 - the minutes
it sends me the
Код:
SendClientMessage(playerid, -1, "USAGE: /mute [id] [reason (optional)] [minutes]");
I wanted the reason to be optional. How u do that?
Oh and it sends me a
Код:
sscanf warning: No default value found.
Re: Optional string (sscanf) -
AlamoTR - 16.09.2018
Код:
CMD:mute(playerid, params[])
{
new id, reason[64], time;
if (sscanf(params, "dS(No Reason Given)[24]d", id, reason, time))
{
SendClientMessage(playerid, -1, "USAGE: /mute [id] [reason (optional)] [minutes]");
return 1;
}
Mute(id, reason, time);
return 1;
}
Re: Optional string (sscanf) -
Undef1ned - 16.09.2018
PHP код:
CMD:mute(playerid, params[])
{
new id, time, reason[64];
if(!sscanf(params, "uds[64]", id, time, reason))
{
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "disconnected");
Mute(id, reason, time);
return 1;
}
if(sscanf(params, "ud", params[0], params[1])) return SendClientMessage(playerid, -1, "USAGE: /mute [id] [minutes] [reason (optional)]");
Mute(params[0], "", params[1]); //I recommend using the code that is in "Mute" here.
return 1;
}