[Tutorial] How To Make Simple Admins commands with Zcmd
#1

I just Making Simple Tutorial About Making Admins commands with zcmd


What We Need?


And This Code At the End of Your GM/FS

pawn Code:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Start

Kick Command

First We need To Check If Player Admin Or Not with This Code

pawn Code:
if(IsPlayerAdmin(playerid))
Second We Need Colors Define
pawn Code:
#define red 0xFF0000AA
now For the command


pawn Code:
CMD:kick(playerid,params[]) {
       if(IsPlayerAdmin(playerid))
   {
      new tmp[256], tmp2[256], Index;
      tmp = strtok(params,Index), tmp2 = strtok(params,Index);
      if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /kick [playerid] [reason]"); //Check If Player Does Not Added "Reason and the ID"
      new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
      player1 = strval(tmp); // << player1 = ID of The Player
      if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player Not Connected"); //<< Check If Player Connected Or Not
      GetPlayerName(player1, playername, sizeof(playername)); //get Selected Player Name
      GetPlayerName(playerid, adminname, sizeof(adminname)); //get Admin Name Who Use This command
         format(string,sizeof(string),"Admin %s Has Kicked %s | Reason ( %s )",adminname,playername,params[2]); //adminname = the player Who Use This command || playername = the Player who Going To Be kicked || params[2] = The Reason Of The Kick
         SendClientMessageToAll(red,string); // Send Message To all Players.
         Kick(player1);
   } else return SendClientMessage(playerid,red,"You Can't Use This Command!"); // This Code return the Player IF he's not Login in as RCON admin
   return 1;
}
Explain:

pawn Code:
if(IsPlayerAdmin(playerid))
Meaning: Check Who Use This command Is Rcon Admin
pawn Code:
if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /kick [playerid] [reason]");
Meaning: Check Player If He didn't Type Playerid Or Reason
pawn Code:
if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player Not Connected");
Meaning: Check Selected Player Connected or Not

pawn Code:
format(string,sizeof(string),"Admin %s Has Kicked %s | Reason ( %s )",adminname,playername,params[2]);
SendClientMessageToAll(red,string);
Meaning: Send Message to All Playera
____________________________________
Ban Command

As Always We Need Admin Check

pawn Code:
if(IsPlayerAdmin(playerid))
For The command


pawn Code:
CMD:ban(playerid,params[]) {
       if(IsPlayerAdmin(playerid))
 {
     new tmp[256], tmp2[256], Index;
     tmp = strtok(params,Index), tmp2 = strtok(params,Index);
     if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]"); //Check If Player Does Not Added "Reason and the ID"
     new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
     player1 = strval(tmp); // << player1 = ID of The Player
     if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player Not Connected"); //<< Check If Player Connected Or Not
     GetPlayerName(player1, playername, sizeof(playername)); //get Selected Player Name
     GetPlayerName(playerid, adminname, sizeof(adminname)); //get Admin Name Who Use This command
        format(string,sizeof(string),"Admin %s Has Ban %s | Reason ( %s )",adminname,playername,params[2]); //adminname = the player Who Use This command || playername = the Player who Going To Be kicked || params[2] = The Reason Of The Kick
        SendClientMessageToAll(red,string); // Send Message To all Players.
        Ban(player1);
  } else return SendClientMessage(playerid,red,"You Can't Use This Command!"); // This Code return the Player IF he's not Login in as RCON admin
 return 1;
}
Explain:

pawn Code:
if(IsPlayerAdmin(playerid))
Meaning: Check Who Use This command Is Rcon Admin
pawn Code:
if(isnull(params)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]");
Meaning: Check Player If He didn't Type Playerid Or Reason
pawn Code:
if(!IsPlayerConnected(player1)) return SendClientMessage(playerid,red,"Player Not Connected");
Meaning: Check Selected Player Connected or Not

pawn Code:
format(string,sizeof(string),"Admin %s Has Ban %s | Reason ( %s )",adminname,playername,params[2]);
SendClientMessageToAll(red,string);
Meaning: Send Message to All Players
______________________


Example Filter Script

PasteBin
Solid files
______________________

Note:I know This Is Simple but I think its Useful


EDIT : ahh sorry i post in Wrong Section..i though I post "scripting Tutorial" Damn
Reply
#2

Wrong section dude
But nice tutorial!
Reply
#3

who use fucking strtok, and in zcmd?

no point of making these tutorials, tutorials must be good, in word 'good' I mean they must be optimized etc. not using old shit, if you understand me
Reply
#4

This is well in the wrong area...
Reply
#5

Wrong area, please request a move of it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)