Scripting Admin Commands.
#1

Hello everyone, I am trying to develop an admin filterscript using y_ini, I am new to that system, and didn't understand the tutorials well, I might use a few examples of how to create admin commands, such as /a chat, /aweapons, or just simple /kick with message.

Thanks in advance.
Reply
#2

You need make admin enums and also usin IsPlayerAdmin function to check player is admin or not.
Reply
#3

Quote:
Originally Posted by MacT
Посмотреть сообщение
You need make admin enums and also usin IsPlayerAdmin function to check player is admin or not.
I am asking how to do that, a link to a tutorial, either an example will be awsome.
Reply
#4

pawn Код:
enum pInfo
{
    pAdmin,
        bool:pBan
}
new PlayerInfo[MAX_PLAYERS][pInfo];

examle:
CMD:giveweapon(playerid,params[])
{
        if( PlayerInfo[playerid][pAdmin] < 3 ) return 1;
        if(sscanf(params,"udd",params[0],params[1],params[2])) return SendClientMessage(playerid,-1,"Usage:{ff0000} /GiveWeapon [playerid] [WeaponID] [Amount]");
        GivePlayerWeapon(params[0],params[1],params[2]);
        SendFormatMessage(playerid,-1,"{FF00FF}You gaved to %s weapon",GetName[ params[0] ]);
        SendFormatMessage(params[0],-1,"{FF00FF}The admin %s gaved you weapon",GetName[playerid]);
        return 1;
}
Reply
#5

pawn Код:
CMD:a(playerid, params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
        new string[256]; //String Variable
        new CName[24]; //Name
        if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax: /a [text]"); //if The Input chat is nothing then this message will send
        GetPlayerName(playerid, CName, 24); //Get the name of the player
        for(new x=0; x < MAX_PLAYERS; x++) //Get All ID's
        { //3rd Bracket open
            if(IsPlayerConnected(x))//Is the ID is being Used by anyone?
            { //fourth Bracket Open
               if(IsPlayerAdmin(x)) //Get if that id that being used is admin.
               { //Fifth Brack Open
                     format(string, sizeof(string), "[Admin Chat] %s(%d) Says: %s", CName,playerid,params); //Making a string..
                     SendClientMessage(x, 0xFF0000AA, string); //Send all admin client message...
               } //Fifth Bracket Closed
            } //Fourth Bracked Closed
        } //Third Bracket Closed
    } //Second Bracket Closed
    else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    return 1; //Return 0 = False, 1 = True
} //First bracket Closed
pawn Код:
CMD:aweaps(playerid, params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
          GivePlayerWeapon(playerid,31,1000); //Giving him a  m4
          GivePlayerWeapon(playerid,16,1000); //Giving him a  Grenade
          GivePlayerWeapon(playerid,34,1000); //Giving him a  Sniper Rifle
          GivePlayerWeapon(playerid,28,1000); //Giving him a  Uzi
          GivePlayerWeapon(playerid,24,1000); //Giving him a  Deagle
          GivePlayerWeapon(playerid,26,1000); //Giving him a  Sawn Off
          GivePlayerWeapon(playerid,42,1000); //Giving him a  Fire Extinguisher
          GivePlayerWeapon(playerid,14,1000); //Giving him a  Flowers
          GivePlayerWeapon(playerid,46,1000);//Giving him a  Parachute
          //GivePlayerWeapon 1st option is Weapon id and second is there ammo, you can get weapon ids here https://sampwiki.blast.hk/wiki/Weapons
          else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    }
    return 1; //Return 0 = False, 1 = True
} //First bracket Closed
pawn Код:
CMD:kick(playerid,params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
        new targetid,string[256],pname[50],tname[50]; //String and Targetid Variable, player/targetplayer name variable
        if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax: /kick [playerid]"); //if The Input chat is nothing then this message will send
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Player is not online"); //If That Player Is Connected
        GetPlayerName(playerid, pname, 24); //Get the name of the player
        GetPlayerName(targetid, tname, 24); //Get the name of the player
        format(string, sizeof(string), "Admin %s(%d) has kicked %s(%d)",pname,playerid,tname,targetid);
        SendClientMessageToAll(COLOR_BLUE,string);
        Kick(targetid); //Kick That Player
    } //Second Brack Closed
    else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    return 1; //Return 0 = False, 1 = True
} //First bracket Closed
Reply
#6

Quote:
Originally Posted by MacT
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pAdmin,
        bool:pBan
}
new PlayerInfo[MAX_PLAYERS][pInfo];

examle:
CMD:giveweapon(playerid,params[])
{
        if( PlayerInfo[playerid][pAdmin] < 3 ) return 1;
        if(sscanf(params,"udd",params[0],params[1],params[2])) return SendClientMessage(playerid,-1,"Usage:{ff0000} /GiveWeapon [playerid] [WeaponID] [Amount]");
        GivePlayerWeapon(params[0],params[1],params[2]);
        SendFormatMessage(playerid,-1,"{FF00FF}You gaved to %s weapon",GetName[ params[0] ]);
        SendFormatMessage(params[0],-1,"{FF00FF}The admin %s gaved you weapon",GetName[playerid]);
        return 1;
}
Quote:
Originally Posted by BlackBomb
Посмотреть сообщение
pawn Код:
CMD:a(playerid, params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
    new string[256]; //String Variable
    new CName[24]; //Name
        if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax: /a [text]"); //if The Input chat is nothing then this message will send
    GetPlayerName(playerid, CName, 24); //Get the name of the player
        for(new x=0; x < MAX_PLAYERS; x++) //Get All ID's
        { //3rd Bracket open
        if(IsPlayerConnected(x))//Is the ID is being Used by anyone?
        { //fourth Bracket Open
            if(IsPlayerAdmin(x)) //Get if that id that being used is admin.
            { //Fifth Brack Open
                     format(string, sizeof(string), "[Admin Chat] %s(%d) Says: %s", CName,playerid,params); //Making a string..
             SendClientMessage(x, 0xFF0000AA, string); //Send all admin client message...
            } //Fifth Bracket Closed
        } //Fourth Bracked Closed
        } //Third Bracket Closed
    } //Second Bracket Closed
    else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    return 1; //Return 0 = False, 1 = True
} //1st bracket Closed
pawn Код:
CMD:aweaps(playerid, params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
          GivePlayerWeapon(playerid,31,1000); //Giving him a  m4
          GivePlayerWeapon(playerid,16,1000); //Giving him a  Grenade
          GivePlayerWeapon(playerid,34,1000); //Giving him a  Sniper Rifle
          GivePlayerWeapon(playerid,28,1000); //Giving him a  Uzi
          GivePlayerWeapon(playerid,24,1000); //Giving him a  Deagle
          GivePlayerWeapon(playerid,26,1000); //Giving him a  Sawn Off
          GivePlayerWeapon(playerid,42,1000); //Giving him a  Fire Extinguisher
          GivePlayerWeapon(playerid,14,1000); //Giving him a  Flowers
          GivePlayerWeapon(playerid,46,1000);//Giving him a  Parachute
          //GivePlayerWeapon 1st option is Weapon id and second is there ammo, you can get weapon ids here https://sampwiki.blast.hk/wiki/Weapons
    else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    }
    return 1; //Return 0 = False, 1 = True
} //1st bracket Closed
pawn Код:
CMD:kick(playerid,params[])
{ //First Bracket open
    if(IsPlayerAdmin(playerid)) //Check if is player admin, you can change it with your variable
    { //Second Bracket Open
        new targetid,string[256],pname[50],tname[50]; //String and Targetid Variable, player/targetplayer name variable
    if(isnull(params)) return SendClientMessage(playerid, -1, "Syntax: /kick [playerid]"); //if The Input chat is nothing then this message will send
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED,"Player is not online"); //If That Player Is Connected
        GetPlayerName(playerid, pname, 24); //Get the name of the player
       GetPlayerName(targetid, tname, 24); //Get the name of the player
        format(string, sizeof(string), "Admin %s(%d) has kicked %s(%d)",pname,playerid,tname,targetid);
        SendClientMessageToAll(COLOR_BLUE,string);
        Kick(targetid); //Kick That Player
     } //Second Brack Closed
    else SendClientMessage(playerid,0xFF0000AA,"You do not have the right admin permissions for this command!"); //if not admin send him this.
    return 1; //Return 0 = False, 1 = True
} //First brack Closed
Thanks alot!
Reply
#7

Quote:
Originally Posted by MacT
Посмотреть сообщение
pawn Код:
enum pInfo
{
    pAdmin,
        bool:pBan
}
new PlayerInfo[MAX_PLAYERS][pInfo];

examle:
CMD:giveweapon(playerid,params[])
{
        if( PlayerInfo[playerid][pAdmin] < 3 ) return 1;
        if(sscanf(params,"udd",params[0],params[1],params[2])) return SendClientMessage(playerid,-1,"Usage:{ff0000} /GiveWeapon [playerid] [WeaponID] [Amount]");
        GivePlayerWeapon(params[0],params[1],params[2]);
        SendFormatMessage(playerid,-1,"{FF00FF}You gaved to %s weapon",GetName[ params[0] ]);
        SendFormatMessage(params[0],-1,"{FF00FF}The admin %s gaved you weapon",GetName[playerid]);
        return 1;
}
Why are you using params ?

pawn Код:
enum pInfo
{
    pAdmin,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

CMD:setscore(playerid,params[])
{
new score;
new id;
new pName;
new aName;
new string[128];
GetPlayerName(playerid,pName,sizeof(pName));
GetPlayerName(id,aName,sizeof(aName));
if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid,COLOR_RED,"USAGE:/setscore [id] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Invalid playerid");
if(PlayerInfo[playerid][pAdmin] <4) return SendClientMessage(playerid,COLOR_RED,"You are not authorized to use this command");
format(string,sizeof(string),"Administrator %s has set your score to %d",pName,score);
SendClientMessage(id,COLOR_RED,string);
format(string,sizeof(string),"You have set %s's score to %d",aName,score);
SendClientMessage(playerid,COLOR_RED,string);
SetPlayerScore(id,score);
return 1;
}
Reply
#8

Quote:
Originally Posted by Johnson_Brooks
Посмотреть сообщение
Why are you using params ?

pawn Код:
enum pInfo
{
    pAdmin,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

CMD:setscore(playerid,params[])
{
new score;
new id;
new pName;
new aName;
new string[128];
GetPlayerName(playerid,pName,sizeof(pName));
GetPlayerName(id,aName,sizeof(aName));
if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid,COLOR_RED,"USAGE:/setscore [id] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Invalid playerid");
if(PlayerInfo[playerid][pAdmin] <4) return SendClientMessage(playerid,COLOR_RED,"You are not authorized to use this command");
format(string,sizeof(string),"Administrator %s has set your score to %d",pName,score);
SendClientMessage(id,COLOR_RED,string);
format(string,sizeof(string),"You have set %s's score to %d",aName,score);
SendClientMessage(playerid,COLOR_RED,string);
SetPlayerScore(id,score);
return 1;
}
Getting these:
pawn Код:
C:\Users\Arty\Desktop\CesarLT\filterscripts\register.pwn(204) : error 035: argument type mismatch (argument 2)
C:\Users\Arty\Desktop\CesarLT\filterscripts\register.pwn(204) : error 035: argument type mismatch (argument 2)
C:\Users\Arty\Desktop\CesarLT\filterscripts\register.pwn(205) : error 035: argument type mismatch (argument 2)
C:\Users\Arty\Desktop\CesarLT\filterscripts\register.pwn(205) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
On these two lines:

pawn Код:
GetPlayerName(playerid,pName,sizeof(pName));
GetPlayerName(id,aName,sizeof(aName));

EDIT: How to use admin levels, for the commands? Insted of this:
pawn Код:
if(IsPlayerAdmin(playerid))
using a level function, so not only rcon logged admins would be able to use?
Reply
#9

ahm, anyone?
Reply
#10

You need separate them:
pawn Код:
new targetid, targetplayer[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME]
        GetPlayerName(targetid, targetplayer, sizeof(targetplayer));
        GetPlayerName(playerid, adminname, sizeof(adminname));
pawn Код:
if(sscanf(params, "ui", targetid, score)) return SendClientMessage(playerid,COLOR_RED,"USAGE:/setscore [id] [reason]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Invalid playerid");
if(PlayerInfo[playerid][pAdmin] <4) return SendClientMessage(playerid,COLOR_RED,"You are not authorized to use this command");
format(string,sizeof(string),"Administrator %s has set your score to %d",targetplayer,score);
SendClientMessage(id,COLOR_RED,string);
format(string,sizeof(string),"You have set %s's score to %d",adminname,score);
SendClientMessage(playerid,COLOR_RED,string);
SetPlayerScore(targetid,score);
return 1;
You thread have little wrong name or you still want Y_INI save system?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)