02.08.2014, 19:24
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
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.
the second example is :
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
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;
}
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;
}
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