Posts: 815
Threads: 65
Joined: May 2010
Quote:
Originally Posted by Sarra
Hello, I'm learning scripting and everyday, I'm discovering more and more complicated things. I need the answer of few questions, mayve stupid questions, but I really need answers so I can Continue!
I'll give 2 examples a question for each example: here is a /me cmd
pawn Код:
if(!strcmp(cmdtext, "/me", true, 3)) // 3 is the length of /me { if(!cmdtext[3])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /me [action]"); new str[128]; GetPlayerName(playerid, str, sizeof(str)); format(str, sizeof(str), "* %s %s", str, cmdtext[4]); SendClientMessageToAll(0xFFFF00AA, str); return 1; }
now "cmdtext" is an array right? And what does if (!cmdtext[3]) mean? I always want to translate the code to english, so everything gets clear to me. For example there's GetPlayerName(playerid, str, sizeod(str)); which means that str contains the playername, then format(str, sizeof(str), "* %s %s", str, cmdtext[4]); so str is the output: What I understood from this : Str recieves Str + cmdtext[4] so we will get a string containing the player name and cmtext[4]..what is cmdtext[4] mean? if cmdtext is an array cmdtext[4] should be the character right after "/me", looks stupid but I need an explanation.
|
- cmdtext is a string.
- if (!cmdtext[3]) means if there is no character after the 2nd place (computers start at 0!), it will send a usage message.
-cmdtext[4] will return the cmdtext starting from that number in the brackets.
Quote:
Originally Posted by Sarra
the second example is :
pawn Код:
CMD:heal(playerid, params[]) { new id; if (sscanf(params, "u", id)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\""); else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found"); else { SetPlayerHealth(id, 100.0); SendClientMessage(id, 0x00FF00AA, "You have been healed"); SendClientMessage(playerid, 0x00FF00AA, "Player healed"); } return 1; }
what does if (sscanf(params, "u", id) mean? I understood that sscanf gets the input which is a string and checks it, the "u" is the type wanted in the command and the id is the output?So it checks if the "params" is a player ID or not? So confusing,
id is just a normal variable, when I /heal "string" , how does pawno know that id should recieve the "string"? As I see in the script, id is considered as the text that comes after the /heal!
Take it easy please :P I know it looks stupid
|
sscanf is a string splitter. In this command, it is splitting the "params" into different data types which, in this case, is "u". The values are stored into the variables, in this case: "id". Look for the other specifiers on
https://github.com/Y-Less/sscanf/wiki.
If you typed in a string, it wouldn't work because the specifier isn't a string, which has the specifier of "s". The storing variable is also not a string.