Codes on the wiki that i do not understand. Need help with them. -
CSMajor - 27.07.2010
Code 1:
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;
}
Code 2:
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?
Re: Codes on the wiki that i do not understand. Need help with them. -
Conroy - 27.07.2010
sizeof()
This function is used to get the size of a variable. The size of the variable is often used in other functions.
strtok()
This will get the next word (as in, after a space) and store it in a variable. Used in a lot of commands.
cmdtext[]
Cmdtext is the text entered if there is a "/" at the beginning of the user input.
strcmp()
Strcmp stands for 'String Compare', which can be used to compare two strings to check for a difference.
new str[128]
The number in the brackets is the amount of characters which can be stored in the variable.
format
Format puts other variables into a string. Used to SendClientMessages. The last part is the variables you put into the string. %s meaning string (a word), %i meaning an integer (number). Others can be found on the wiki.
tmp
Tmp is just a variable.
strval()
Strval stands for 'String Value', which can be used to get the value of a variable (only used if a number is stored in the variable).
idx
Again, idx is just a variable, but if used with strtok or strrest, it stores the last point of extraction from the user input.
cmd[30]
Explained earlier, another variable used to store characters.
Re: Codes on the wiki that i do not understand. Need help with them. -
CSMajor - 27.07.2010
Ok so can i have help on understanding the /me command? on how to get what i stated earlier. (Look before the list of functions/commands/variables)
EDIT: I am still totally confused, with this.
EDIT 2: I really dont get this scripting language, i read the wikis tutorials thousands of times, and they still do not make sense.
Re: Codes on the wiki that i do not understand. Need help with them. -
Daren_Jacobson - 27.07.2010
I get confused looking at strtok, use sscanf.
Re: Codes on the wiki that i do not understand. Need help with them. -
CSMajor - 28.07.2010
GAH! I'm so confused. I can't figure out how to display a players name and their id.
EG: Player's Name: Bloop| ID: 0.
With the command being like so:
/playername [ID]