[Tutorial] how to make simple Admin commands
#1

What do you need?
Zcmd:https://sampforum.blast.hk/showthread.php?tid=91354
sscanf:https://sampforum.blast.hk/showthread.php?tid=120356

ok now let's start : first open your game mode:

Command 1:ban
now if you want to ban a hacker or any player who causes a threat you need to have a ban command:
first of all we time the command name like that using ZCMD:
pawn Code:
CMD:Ban(playerid,params[])//this is the command
{
//down there is the reason of the ban , so other players will know about it
new reason[150];//the reason of the ban
// and this one is the playerid of the player who you want to ban.
new id;// the id of the player
        //here if the admin didn't write the ban command correctly
    if (sscanf(params, "rs[100]", id, reason))
    return SendClientMessage(playerid, 0xFFFF0000, "{FF0000}Error:{FFFFFF}/Ban [playerid] [reason]");//if the player didn't write The command correctly like /ban without the id or the reason
    //this one will check if the player is connected or not
if (!IsPlayerConnected(id))
    return SendClientMessage(playerid, 0xFF0000AA, "Player not found");//if the player is invalid
//to prevent abuse this command will check if you are an admin or not
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFFFF0000,"{FF0000}Error:{FFFFFF}You Are not allowed to use this command");//if the player is not an admin
   
        //this is the admin name                             //this is the message to player
        new admin[MAX_PLAYER_NAME]//adminname, msgtoall1[150]//first message, msgtoall2[150];//second one
        //this will get the name of the admin to post it
GetPlayerName(playerid, admin, sizeof(admin));//get the name of the admin
        format(msgtoall1, sizeof(msgtoall1), "{FFFFFF}Player {FF0000}%s{FFFFFF} was banned from the server by {FF0000}%s", GetName(id), admin);//message to all players
        SendClientMessageToAll(0xFFFF00AA, msgtoall1);//same thing
        format(msgtoall2, sizeof(msgtoall2), "Reason : %s", reason);//reason of the ban
        SendClientMessage(id, 0xFFFF00AA, msgtoall2);//the message
       
        Ban(id);//ban the player
       
    return Kick(id);//then kick him
}
command 2:Kick
if a player insulted spammed or anything and you want to kick him, you have to get kick command:
first of all you write kick command in zcmd like that:
pawn Code:
CMD:kick(playerid, params[])
{
        //the reason of the ban , and the id is the playerid of the one you want to kick
    new reason[150], id;
       //an error message if you didn't write the kick command correctly
    if (sscanf(params, "rs[100]", id, reason))
    return SendClientMessage(playerid, 0xFFFF0000, "{FF0000}Error:{FFFFFF}/Kick [player name/part of name] [reason]");//if the player didn't mention the id or the reason
//if the player is invalid or not connected
    if (!IsPlayerConnected(id))
    return SendClientMessage(playerid, 0xFF0000AA, "Player not found");//if the player is not connected
//this one will check if the player is an admin to prevent bug abuses
    if(IsPlayerAdmin(playerid)))//if this player is an admin
    {
        //the name of the admin, msg to player, and message to all
        new admin[MAX_PLAYER_NAME], msg1[150], msgtoall1[150];
// this will get the name of the admin
        GetPlayerName(playerid, admin, sizeof(admin));
                //message to the kicked player
        format(msg1, sizeof(msg1), "You were kicked from the server by %s |Reason : %s|", admin,reason);
        SendClientMessage(id, 0xFFFF00AA, msg1);//message from the kicked player

                //message to all the players
        format(msgtoall1, sizeof(msgtoall1), "Player %s was kicked from the server by %s | Reason : %s|", GetName(id), admin,reason);
        SendClientMessageToAll(0xFFFF00AA, msgtoall1);//message to everyone
        Kick(id);//kick the player
    }
    else
    {
// if the player is not an admin , this message wil prevent him from typing this command
    SendClientMessage(playerid,-1,"You Are not an admin " );//if the player is not an admin it will show this message
    }
    return 1;

}
Command 3: slap
now , if you want to slap a player to check if he got a hack or something, you need to get slap command,
first of all type slap command in zcmd like that:
pawn Code:
CMD:slap(playerid,params[])
{
    //the name of the slapped player,msgtoplayer,name of the admin, message to the slapped player, the floot x , y and z
    new OtherPlayer, Msg[170], Name4[24], Message[150], OtherPlayerName[24], Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid))) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR]: you are not an admin!");//if the player is not admin
    else if(sscanf(params, "rs[170]", OtherPlayer, Message)) return SendClientMessage(playerid,COLOR_RED, "{FF0000}Error:{FFFFFF}/slap [playerid] [reason]");// if the player didn't write the command correctly
    GetPlayerName(playerid, Name4, sizeof(Name4));//get the name of the admin
    GetPlayerName(OtherPlayer, OtherPlayerName, sizeof(OtherPlayerName));//get the name of player
    format(Msg, sizeof(Msg), "AdmCmd:{FF6600}%s {FFFFFF}slaps {FF6600}%s {FFFFFF}reason: {FF6600}%s", Name4, OtherPlayerName, Message);//the message
    SendClientMessageToAll(0xFFFFFFFF, Msg);//send the above message to all
    GetPlayerPos(OtherPlayer, x, y, z);//get the pos of the player
    SetPlayerPos(OtherPlayer, x, y, z+5);// then set his pos to a higher place
command 4:mute
at the top of the script:
pawn Code:
new muted[MAX_PLAYERS];
pawn Code:
CMD:mute(playerid, params[])
{
    new
        cmdid,
        reason[80],
        minutes,
        string[128];

    if(!IsPlayerAdmin(playerid)))
        return 0;//if this player is not connected
    if(sscanf(params, "uis[80]", cmdid, minutes,reason))
        return SendClientMessage(playerid,0xFFFF0000,"Usage: /mute [id/name] [minutes] [reason]");//if the player didn't write the command correctly
    if(!IsPlayerConnected(cmdid) || cmdid == INVALID_PLAYER_ID)
        return SendClientMessage(playerid,0xFFFF0000,"Player not found!");//if the player is not connected it will show an error
    {
    new oname[MAX_PLAYER_NAME];//the name of the player
    GetPlayerName(cmdid, oname, sizeof(oname));
    format(string, sizeof(string), "AdmCmd:~ %s has been muted for %i minutes. Reason: '%s' by %s ", oname, minutes,reason,GetName(playerid));//The message to players that this player is muted
    SetTimerEx("unmuteTimer", 60*1000*minutes, false, "i", cmdid);//set timer for the player
   muted[cmdid] = 1;//mute the player
    }
    SendClientMessageToAll(0xFFFF0000, string);//send message to everyone
   
    return 1;
}
forward unmuteTimer(playerid);
public unmuteTimer(playerid)
{
    muted[playerid]= 0;//unmute the player
    return SendClientMessage(playerid,0x00FF0000,"You're no longer muted!");//notify the player
}
onplayertext:
pawn Code:
public OnPlayerText(playerid,text[])
{
if(muted[playerid] == 1)//if the player is muted
{
SendClientMessage(playerid,COLOR_BLUE,"You are muted! you can't talk");
return 0;//prevent him from talking
}
return 1;
}
Command 5: unmute
pawn Code:
CMD:unmute(playerid,params[])
{
    new
        cmdid,
        string[128];
        if(!IsPlayerAdmin(playerid))
        return 0;//if the player is not an admin
    if(sscanf(params, "uis[80]", cmdid))
        return SendClientMessage(playerid,0xFFFF0000,"Usage: /unmute [playerid]");//if the player didn't type this command
    if(!IsPlayerConnected(cmdid) || cmdid == INVALID_PLAYER_ID)
        return SendClientMessage(playerid,COLOR_RED,"Player not found!");//if the player is invalid
    {
    new oname[MAX_PLAYER_NAME];//player name
    GetPlayerName(cmdid, oname, sizeof(oname));//get the player name by getting his id
    format(string, sizeof(string), "AdmCmd:~ %s has been un muted by %s", oname,GetName(playerid));//message
    muted[cmdid] = 0;//unmute the player
    }
   SendClientMessageToAll(0xFFFF0000, string);
    return 1;
}
Reply
#2

Good tutorial but expecting more info , u need to give full explaination .
Reply
#3

need more explaination
Reply
#4

ty for checking my post, i am going to edit it with more explanation
Reply
#5

So you are going to give RCON password to everyone those who are willing to join administrator team?
Reply
#6

This is good for Slap CMD use CreateExplosionForPlayer()
Reply
#7

Quote:
Originally Posted by Bingo
View Post
So you are going to give RCON password to everyone those who are willing to join administrator team?
It is a SIMPLE commands to help you to protect your server that's all.
and ty mrviolince check me out again i am going to make new commands
Reply
#8

Now ur tutorial looks good for those who are learning pawno or beginners, it will help them , and now ur tutorial is well explained.
Reply
#9

ty @princekumar
Reply
#10

Great tutorial but you're missing some things. Please refer to this: https://sampwiki.blast.hk/wiki/Kick

The people you are banning/kicking actually don't see the reason, you need to add a timer that delays the kick in order for them to see it.

Great job nevertheless!
Reply
#11

Its nice but you can explain a bit More Or Instead Of Rcon admin cmds U can make a admin System sort of thing
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)