08.01.2011, 08:27
(
Последний раз редактировалось Haydz; 02.08.2011 в 11:50.
)
Table of contents.
This tutorial was made because i saw somebody ask how to get a another players name and i also had trouble doing commands on other players when i first started.
1 - Doing a basic command on another player.
2 - Doing a basic command on another player displaying there name.
Note: before starting this tut you will need the ZCMD include and the sscanf include.
1 - Doing a basic command on another player
This is a basic command when will send a message to the players id/name you type and kill them at the same time.
pawn Код:
COMMAND:hi(playerid, params[]) //using ZCMD this is how your command will start off looking like.
{
new otherplayerid;
if(sscanf(params, "u", otherplayerid)) return SendClientMessage(playerid, colorhere, "Use /hi [playerid/name]");
else if(!IsPlayerConnected(otherplayerid)) return SendClientMessage(playerid, colorhere, "This player is not connected");
else
{
SendClientMessage(otherplayerid,colorhere,"Hey man, I'm going to kill you lol!");
SetPlayerHealth(otherplayerid,0);
}
return 1;
}
pawn Код:
new otherplayerid;
pawn Код:
if(sscanf(params, "u", otherplayerid)) return SendClientMessage(playerid, colorhere, "Use /hi [playerid/name]");
pawn Код:
else if(!IsPlayerConnected(otherplayerid)) return SendClientMessage(playerid, colorhere, "This player is not connected");
pawn Код:
else
pawn Код:
SendClientMessage(otherplayerid,colorhere,"Hey man, i'm going to kill you lol!"); // sends a message to the other player, "id"
SetPlayerHealth(otherplayerid,0); // will set the other players health to 0, and kill them.
2 - doing basic commands on other players displaying there name.
we will be using this command to find out the other players name and display it in text with a clientmessage.
pawn Код:
COMMAND:whatareournames(playerid, params[])
{
if(sscanf(params, "u", otherplayerid)) return SendClientMessage(playerid, colorhere, "Use /whatareournames [playerid/name]");
else if(!IsPlayerConnected(otherplayerid)) return SendClientMessage(playerid, colorhere, "This player is not connected");
else
{
new otherplayerid,gName[25],pName[25],string[100];
GetPlayerName(playerid, pName, 24);
GetPlayerName(otherplayerid, gName, 24);
format(string, sizeof(string),"His name is %s and yours is %s,",gName,pName);
SendClientMessage(playerid, yourcolor,string);
}
return 1;
}
pawn Код:
if(sscanf(params, "u", otherplayerid)) return SendClientMessage(playerid, colorhere, "Use /whatareournames [playerid/name]");
pawn Код:
else if(!IsPlayerConnected(otherplayerid)) return SendClientMessage(playerid, colorhere, "This player is not connected");
pawn Код:
else
pawn Код:
new otherplayerid,gName[25],pName[25],string[100];
gName - this is what we will be using to display the other players name.
pName - This is what we will be using to display our name.
string - You always need to create a string if you're going to use format to display text. note - You don't have to call it "string" it can be called almost anything.
pawn Код:
GetPlayerName(playerid, pName, 24);
pName - what we will be using to display our name(the player who used the command).
24 - the max characters in a username is 24 so thats the max possible string we may need.
pawn Код:
GetPlayerName(otherplayerid, gName, 24);
gName - the other players name, we can now use gName to display his username.
24 - as above, the max username limit is 24.
pawn Код:
format(string, sizeof(string),"His name is %s and yours is %s,",gName,pName);
SendClientMessage(playerid, yourcolor,string);
You can find out more about 'format' on the wiki https://sampwiki.blast.hk/wiki/Format
End
This is my first tutorial so If you see anything i could improve on myself or a better way of doing a certain code which could improve the tutorial feel free to post. Cheers for reading.