Help me understand sscanf -
Flacker - 18.06.2015
Hi guys. So i'm trying to understand how sscanf works , but i can't figure it out.... I know c++ and over 5 other languages.
Let's take an example. Let's say i want a command "/say [text]" . When player type this, the text after "/say" should appear on chat. How to do that?
CMD: say(playerid,params[]){
new text; //I define a variable to be our text
//Now how to give this variable that value?
}
Please someone post this command solved.
Another thing is , what does a function like this do ?
CMD: say(playerid,params[]){
new text;
if (sscanf(params,"s",text)){ return SendClientMessage(playerid,COLOR_RED,"respond");}}
When does this SendClientMessage command trigger? I see no indications.
Someone please help. Thanks
Re: Help me understand sscanf -
DarkLored - 18.06.2015
Refer to this.
https://sampforum.blast.hk/showthread.php?tid=280476
Re: Help me understand sscanf -
Flacker - 19.06.2015
Quote:
Originally Posted by DarkLored
|
I know that thread bro. This is where i downloaded the include from . But i can't get it. So can you help me with that command and some explications please?
Re: Help me understand sscanf -
J0sh... - 19.06.2015
Here some light on what you're trying to understand. Let's say I have a command called say and I use if(sscanf(parmas, "s[128]", text)) return SendClientMessage(playerid, -1, "ERROR: You haven't used the command correctly use /say testing1...2....3");
What that would do if you just did /say it would return that SendClientMessage, if you use /say siaais it will imput the command.
Edit: heres a command
PHP код:
CMD:test(playerid, params[])
{
new text[128], string[128];
if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, -1, "/test [message]"); //Check if the command has a extra input e.g /test hello :D
format(string, sizeof(string), "%s", text); //Format the string
SendClientMessageToAll(-1, string);
return 1;
}
Re: Help me understand sscanf -
Vince - 19.06.2015
Sscanf is a string
splitting routine. But you want the entire string. Hence, sscanf is useless in this case. Simply use isnull(params) to check if the player entered something and from there on out keep using the "params" variable.
Re: Help me understand sscanf -
Lajko1 - 19.06.2015
To trigger something that is saved in this variable you crated, you have to use format thingy:
pawn Код:
format(string, sizeof(string), "%s", text); //Format the string
SendClientMessageToAll(-1, string);
So this will send your text to everyone, this is what exactly triggers your text variable.