[Tutorial] [ZCMD]How to make most of the basic admin commands
#1

•Introduction•

So hello guys first of all after long time of leaving SA-MP i decided to come back to have fun by scripting because scripting was surely a part of my life!.Well to have a good system you need to have and a good admin system too. Indeed, there are a lot admin filterscripts around but i don't really think it will be at 100% what you really need so what i suggest is: MAKE YOUR OWN ADMIN SYSTEM.
Anyway today i am here to show you how to make basic admin commands for your server. Let's start making some commands.

•Requirements•
First of all we will need the fast & simple command processor zcmd,sscanf and a proper login/registering system with adminlevel variable in user's database!
Zcmd command processor format goes like that:

pawn Code:
CMD:commandhere(playerid,params[])
{
      //Code here
      return 1;
}
params[] is for the parameters string!
playerid, the player's ID who sends this command!

Sscanf is more flexible and quicker for us to use for the parameters string!

Lets Start
Lets make the first command which as usual is the /makeadmin or /setlevel command to make a player admin of your server
pawn Code:
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
Explanation:

1.command here [ remember format CMD:mycommand(playerid,params[] ]

2.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!
3.u parameter = username/id[example:vassilis,1], "d" parameter = integer[example:1,22,33]

4.checks if the id of the player you want to set admin is online, if not... sends the client message that it is not connected

5.you can change that according to how many admin levels you have
here we said that if the level that the player wants to set to the second player is less than 1 and higher than 3 then it will return a client message that he cant do that

6.getting second player's name

7.making the string to send a client message to the 1st player to say that he has set the admirable admin level he choosed
%s = getting name(gname), level = getting admin level (level)

8.anouncing level %d = to get the admin level

9.Sending 1st player the formmated string!

10.Sending 2nd player the formmated string2!!!

11.WARNING : this VARIABLE IS JUST AN EXAMPLE YOU HAVE TO SET IT BY YOUR OWN ACCORDING TO YOUR OWN USER SYSTEM!!! by that we confirm that the "level" will set the pinfo[ID][AdminLevel] to the adminlevel that the 1st player chose for the second player in the user database you have by the system you got


I hope i have explained as much as i could the setlevel admin command. Its my second actually tutorial so please be good to me
In case you don't have a system i will update the tutorial by a simple login/registering system using adminlevel variable too!

Lets continue now making a kick command!!
pawn Code:
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
•Warning•
You need to have a proper login/register system to save the admin level
The tutorial is under construction and it is not even on 20%
•Updates•
As soon as possible i will add a simple login & registering system using dialogs with an admin level variable in it to show how to save the admin level to user folder!
Adding of course more commands like /setcash, /setvip, /kick, /car [vehid], /spec etc...

•UPDATING SOON•
Reply
#2

Very nice tutorial mate. +1 Rep.
Reply
#3

Very good tutorial.

@Tip: Try to place the explanations out of the code boxes.
rep+=4
Reply
#4

Quote:
Originally Posted by benjaminjones
View Post
Very nice tutorial mate. +1 Rep.
Thank you i try to explain it as much as possible

Quote:
Originally Posted by Schocc
View Post
Very good tutorial.

@Tip: Try to place the explanations out of the code boxes.
rep+=4
I am glad you like it. Ok i will !!
The tutorial is under construction yet .
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)