#include <sscanf>
#include <zcmd>
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xFF0000AA
At first, I'm going to say how to make a simple /heal and /armour command. (I mean like healing and armouring other players)
CMD:heal(playerid,params[]) First line.
{ // Opening bracket
new string[128], ID, name[MAX_PLAYER_NAME], aname[MAX_PLAYER_NAME]; // Here ID is the target, name is your name.(the player who is going to execute it) and aname is the target's name.
if(sscanf(params,"u",ID)) // "u" can be defined for inserting a name or an ID
{ // then
SendClientMessage(playerid,COLOR_RED,"[ERROR] /heal (Player Name/ID)"); //When the player didn't enter the fields correctly, It'll say this message to him.
return 1;
}
if(!IsPlayerAdmin(playerid)) // If the player is not an RCON admin
{ // then
SendClientMessage(playerid,COLOR_RED,"[ERROR] You are not authorized to use this command.");
return 1;
}
if(!IsPlayerConnected(ID)) // If the target ID is not connected
{ // then
SendClientMessage(playerid,COLOR_RED,"[ERROR] Entered player ID is not connected.");
return 1;
}
GetPlayerName(playerid,aname,sizeof(aname)); // Getting the name of the player who executes the command.
GetPlayerName(ID,name,sizeof(name)); // Getting the name of the target ID.
format(string,sizeof(string),"[ADMIN] RCON Administrator %s(%d) has healed %s(%d).",aname,playerid,name,ID);
SendClientMessageToAll(COLOR_GREEN,string); // Sends a message to everyone who is connected.
SetPlayerHealth(ID,100); // Sets the target ID's health to 100.
return 1;
} // Closing bracket.
CMD:heal(playerid,params[])
{
new string[128], ID, name[MAX_PLAYER_NAME], aname[MAX_PLAYER_NAME];
if(sscanf(params,"u",ID)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] /heal [player name/id]");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] You are not authorized to use this command.");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Entered player ID is not connected.");
GetPlayerName(playerid,aname,sizeof(aname)); // Getting the name of the player who executes the command.
GetPlayerName(ID,name,sizeof(name)); // Getting the name of the target ID.
format(string,sizeof(string),"[ADMIN] RCON Administrator %s(%d) has healed %s(%d).",aname,playerid,name,ID);
SendClientMessageToAll(COLOR_GREEN,string); // Sends a message to everyone who is connected.
SetPlayerHealth(ID,100); // Sets the target ID's health to 100.
return 1;
}
CMD:armour(playerid,params[])
{
new string[128], ID, name[MAX_PLAYER_NAME], aname[MAX_PLAYER_NAME];
if(sscanf(params,"u",ID)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] /armour [player name/id]");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] You are not authorized to use this command.");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Entered player ID is not connected.");
GetPlayerName(playerid,aname,sizeof(aname)); // Getting the name of the player who executes the command.
GetPlayerName(ID,name,sizeof(name)); // Getting the name of the target ID.
format(string,sizeof(string),"[ADMIN] RCON Administrator %s(%d) has armoured %s(%d).",aname,playerid,name,ID);
SendClientMessageToAll(COLOR_GREEN,string); // Sends a message to everyone who is connected.
SetPlayerArmour(ID,100); // Sets the target ID's armourto 100.
return 1;
}
CMD:me(playerid,params[])
{
new string[128];
new name[MAX_PLAYER_NAME];
if(!strlen(params)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] /me [message]"); // if the player didn't enter the fields it'll say this.
if(IsSpawned[playerid] != 1) return SendClientMessage(playerid,COLOR_RED,"[ERROR] You must be spawned to use this command."); // if the player is not spawned it'll say this
format(string,sizeof(string),"%s %s",name,params); // Here the first %s defines the player's name, and the second %s defines the text entered by the player(params)
SendClientMessageToAll(COLOR_GREEN,string); // Sending a message to all with the color green.
return 1;
}
CMD:kick(playerid,params[])
{
new string[128], name[MAX_PLAYER_NAME], aname[MAX_PLAYER_NAME], ID, cmdreason;
if(sscanf(params,"us",ID,cmdreason)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] /kick [player name/id] [reason]");
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] You are not authorized to use this command.");
if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"[ERROR] Entered player ID is not connected.");
GetPlayerName(playerid,aname,sizeof(aname)); // Getting the name of the player who executes the command.
GetPlayerName(ID,name,sizeof(name)); // Getting the name of the target ID.
format(string,sizeof(string),"[ADMIN] RCON Administrator %s(%d) has kicked %s(%d) for the reason : %s",aname,playerid,name,ID,cmdreason);
SendClientMessageToAll(COLOR_GREEN,string);
Kick(ID);
return 1;
}
If you like this tutorial, Please +rep me. :)
Great! You completed one command. You can make it short by using it like this |
if(sscanf(params,"u",ID)) // "u" can be defined for inserting a name or an ID
{ // then
SendClientMessage(playerid,COLOR_RED,"[ERROR] /heal (Player Name/ID)"); //When the player didn't enter the fields correctly, It'll say this message to him.
if(sscanf(params,"u",ID)) // "u" can be defined for inserting a name or an ID
CMD:heal(playerid, params[])
{
if(IsPlayerAdmin(playerid)) // Note: first is to check if you are an administrator.
{
if(sscanf(params, "u", params[0])) return SendClientMessage(playerid, -1, "usage: /heal [playerid/name].");
if(IsPlayerConnected(params[0]) && params[0] != INVALID_PLAYER_ID)
{
new g_string[91]; // You don't need 128 in its string.
SetPlayerHealth(params[0], 100.0);
format(g_string, sizeof(g_string), "RCON Administrator %s(%d) has healed %s(%d).", Name(playerid), playerid, Name(params[0]), params[0]);
SendClientMessage(params[0], -1, g_string);
}
}
else
{
SendClientMessage(playerid, -1, " You are not authorized to use this command.");
}
return true;
}
stock Name(playerid)
{
new name_player[24];
GetPlayerName(playerid, name_player, 24);
return name_player;
}