27.07.2010, 22:02
Code 1:
It says hello to a specified player
Code 2:
it is the /me command.
on both of these codes, i do not understand how they get the player id or send a message Beyond the command part.
EG 1: /me says hello
EG 2:/sayhello 4
Commands and variables i do not understand:
It says hello to a specified player
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[30];
new idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/sayhello", true) == 0)
{
new tmp[30];
// assign the id (written by the user) to tmp
tmp = strtok(cmdtext, idx);
// convert the id to an integer using strval (this is essential)
// and assign to otherplayer
new otherplayer = strval(tmp);
if(IsPlayerConnected(otherplayer))
{
SendClientMessage(otherplayer, 0xFFFF00AA, "Hi, hello!");
}
return 1;
}
return 0;
}
it is the /me command.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
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;
}
return 0;
}
on both of these codes, i do not understand how they get the player id or send a message Beyond the command part.
EG 1: /me says hello
EG 2:/sayhello 4
Commands and variables i do not understand:
pawn Код:
sizeof()
strtok()
cmdtext[]
strcmp()
new str[128] where did the number come from and what does it represent?
format(str, sizeof(str), "* %s %s"-- this part, str, cmdtext[4]);
tmp
strval()
idx
cmd[30] again where did the number come from and whats it used for?