Help me understand sscanf
#1

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
Reply
#2

Refer to this. https://sampforum.blast.hk/showthread.php?tid=280476
Reply
#3

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?
Reply
#4

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(playeridparams[])
{
    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(stringsizeof(string), "%s"text); //Format the string
    
SendClientMessageToAll(-1string);
    return 
1;

Reply
#5

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.
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)