CMD:commandhere(playerid,params[])
{
//Code here
return 1;
}
CMD:setlevel(playerid,params[]) //1
{ //opening bracket 1
new ID,level,gname[MAX_PLAYER_NAME],string[125],string2[125];
if(!IsPlayerAdmin(playerid)) return 0; //2
//using sscanf now
if(sscanf(params,"ud",ID,level)) return SendClientMessage(playerid,-1," (ERROR) : /setlevel [playerid] [level]"); //3
if(id == INVALID_PLAYER_ID || !IsPlayerConnected(ID)) return SendClientMessage(playerid,-1," (ERROR) : The id you have typed is invalid!"); //4
if(level < 1 || level > 3) return SendClientMessage(playerid,-1, " (ERROR) : You must put an admin level between 1-3"); //5
GetPlayerName(ID,gname,sizeof(gname)); //6
format(string, sizeof(string), "SERVER SYSTEM: You have set %s admin level to %d", gname, level); //7
format(string2, sizeof(string2), "SERVER SYSTEM: Server Owner has set your Admin Level to %d", level); //8
SendClientMessage(playerid, -1, string); //9
SendClientMessage(ID, -1, string2); //10
pinfo[ID][AdminLevel] = level; //11
return 1; // to return that the command is valid
} // closing bracket 1
CMD:kick(playerid,params[]) //command here [ remember format CMD:mycommand(playerid,params[] ]
{ //opening bracket 1
new ID,gname[MAX_PLAYER_NAME],string[125],reason[70];
if(!IsPlayerAdmin(playerid)) return 0; //If Player isn't RCON Admin returns a client message("Unkown command") Warning : the "!" mark is used for negative statements... example:
// if(IsPlayerConnected(playerid) = asks if the player is connected
// if(!IsPlayerConnected(playerid) = asks if the player isn't connected!
//using sscanf now
if(sscanf(params,"us[70]",ID,reason)) return SendClientMessage(playerid,-1," (ERROR) : /setlevel [playerid] [reason]"); //u parameter = username/id[example:vassilis,1], "s" parameter = string[example : this is string]
if(id == INVALID_PLAYER_ID || !IsPlayerConnected(ID)) return SendClientMessage(playerid,-1," (ERROR) : The id you have typed is invalid!"); //checks if the id of the player you want to kick is online, if not... sends the client message that he is not connected
GetPlayerName(ID,gname,sizeof(gname)); //getting second player's name
format(string, sizeof(string), "SERVER SYSTEM: %s has been kicked from the server Reason: %s", gname,reason); //anouncing level %d = to get the admin level
SendClientMessageToAll( -1, string); //Sending to all players the formatted string
Kick(ID); //kicking the second player!!
return 1; // to return that the command is valid
} // closing bracket 1
Very good tutorial.
@Tip: Try to place the explanations out of the code boxes. rep+=4 |