[Tutorial] Admin Script (y_ini,sscanf,zcmd)
#1

HOW TO MAKE A ADMIN SCRIPT
Why did i make this?
This is my first turorial and someone asked me to find a good tut on how to make a admin script using y_ini.
I've seen many tutorials that you can just copy and paste, but this will not be like that.

Note to newbies: If you cannot script it yourself, learn it or leave it!!!

We will need this:
sscanf. By ******. Also read the the post to learn sscanf proberbly.
Y_INI. By ******. To save our stats. Read this tut by ******How to use Y_INI
ZCMD. By zeex. This will be our command prossesor.
You can also use Y_Commands. By ******. y_commands and zcmd is the same and works the same but y_commands is faster.

Lets start at the top with including what we need.
pawn Код:
#include <a_samp> //you proberbly know what this is.
#include <sscanf2> // this is the sscanf include you also need to add something in your server.cfg, coming later in the tut.
#include <YSI\y_ini> // this is our saving system you proberbly downloaded the hole YSI libary so the includes is inside the YSI folder
#include <zcmd> // this is our commands prossesor if you want to use y_commands replace #include <zcmd> with #include <YSI\y_commands>
Now we will go inside the server.cfg to add the sscanf plugin
Код:
echo Executing Server Config...
lanmode 0
rcon_password changeme
maxplayers 35
port 7777
hostname hostname
gamemode0 gamemod
filterscripts filterscipts
plugins sscanf //<===== this is the line we need to add
announce 0
query 1
weburl www.sa-mp.com
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
maxnpc 0
logtimeformat [%H:%M:%S]
Now we have our incudes and plugins, lets start scripting.
I will not show you how to make a login register system but you might use this tut made by Kush Login and Register System - Dialogs -Using Y_INI

We will need to promote the player to admin so we need this command.
If you do not read this you will be fucked.-.-.
pawn Код:
CMD:promote(playerid,params[])
{
        new id,level;
    if(IsPlayerAdmin(playerid)) //this will check if the player is logged into RCON
    {
        if(sscanf(params,"ud",id,level) return //add the sendclientmessage usage: /promote name/id level or something "u" checks the if the player wrote a id or name "d" checks what level you wrote
        else
        {
            if(level > 5) return //if the player writes a level thats over 5 he will get a error, write the error here
            else
            {
                new INI:File = INI_Open(UserPath(id));//this is the example used in Kush's tut link above, make it fit in your system, note that i've changed the UserPath(playerid) to UserPath(id) to promote the chosen player not yourself
                INI_WriteInt(File,"Admin",level); // writes the admin level in the ini file and makes the player admin.
                INI_Close(File); //closes the ini file
            }
        }
    }
    else
    {
        //send a message that the player is not logged in as RCON
    }
}
Now we have the promote command but we need some other commands too.
We will make the /kick and /ban commands

This is the kick command the ban command will be almost the same
pawn Код:
CMD:kick(playerid,params[])
{
    new id,reason[128],name[MAX_PLAYER_NAME];
    if(PlayerInfo[playerid][pAdmin] > 1) //this is also taken from the tut by Kush
    {
        if(sscanf(params,"us[128]",id,reason); return //your error message
        else
        {
            format(string1,sizeof(string1),"%s have been kicked from the server: reason: %s",GetPlayerName(id,name,sizeof(name)),reason); //this will format the kick message that is being sent to all player connected
            SendClientMessageToAll(0xFFFFFF,string1);
            Kick(id);//kicks the player
        }
    }
    else
    {
        //your error message about that the player is not a admin
    }
}
This is the Ban command, this will also work even if the player is not connected by banning him by the name
pawn Код:
CMD:ban(playerid,params[])
{
    new id,reason[128],name[MAX_PLAYER_NAME];
    if(PlayerInfo[playerid][pAdmin] > 1) //this is also taken from the tut by Kush
    {
        if(sscanf(params,"us[128]",id,reason); return //your error message
        else
        {
            if(IsPlayerConnected(id))
            {
                format(string1,sizeof(string1),"%s have been banned from the server: reason: %s",GetPlayerName(id,name,sizeof(name)),reason); //this will format the kick message that is being sent to all player connected
                SendClientMessageToAll(0xFFFFFF,string1);
                Ban(id);//bans the player
            }
            else
            {
                new INI:File = INI_Open(UserPath(id));//this will just ban the name not the ip.
                INI_WriteString(File,"Banned",1);//this is not written in the tut by Kush so we need to make it ourselves
                INI_Close(File);
            }//we will also add something OnPlayerConnect to make him really banned
        }
    }
    else
    {
        //your error message about that the player is not a admin
    }
}
We need to continue with OnPlayerConnect to ban the account.
If you do not read this you will be very fucked!
You will also need to read for example Kush's tut to add a new enum to save the ban thing
pawn Код:
public OnPlayerConnect(playerid)
{//you will need to put the fexist to check if the player have registered before this
    new INI:File = INI_Open(UserPath(playerid));//and put the shit below when the dialog shows instead checking a something that does not exist
    if(PlayerInfo[playerid][pBanned] == 1) return Ban(playerid); //now he's REALLY banned!
    else
    {
        //show your login dialog
    }
    return 1;
}
If you have read this tutorial well you should be able to create other commands and stuff to finish you admin system. This have not been tested so tell me if you find any bugs or something.
IMPORTANT NOTE AGAIN IF YOU CANNOT SCRIPT IT YOURSELF, LEARN IT OR LEAVE IT!!!
Reply
#2

It looks pretty cool.
Reply
#3

Cool thank you bro +rep for you man
Reply
#4

Awesome mate! Thanks for this awesome tutorial.
+Reputation from me.
Reply
#5

Nice This is really good for your first tut
Reply
#6

Quote:
Originally Posted by HDFord
Посмотреть сообщение
pawn Код:
public OnPlayerConnect(playerid)
{//you will need to put the fexist to check if the player have registered before this
    new INI:File = INI_Open(UserPath(playerid));//and put the shit below when the dialog shows instead checking a something that does not exist
    if(PlayerInfo[playerid][pBanned] == 1) return Ban(playerid); //now he's REALLY banned!
    else
    {
        //show your login dialog
    }
    return 1;
}
I noticed now that this part does not really explain so well so i'll add this change if someone did not understand it.
pawn Код:
public OnPlayerConnect(playerid)
{
    new INI:File = INI_Open(UserPath(playerid));
    if(fexist(UserPath(playerid))
    {
        //show login dialog and make a ban if he's banned
        if(PlayerInfo[playerid][pBanned] == 1) return Ban(playerid); //now he's REALLY banned!
        else
        {
            //show your login dialog
        }
    }
    else return //register dialog
   
    return 1;
}
Reply
#7

Helped me a lot. I will use it to make my admin system. How to make a VIP system with this?
Reply
#8

Nice job + Rep.
Reply
#9

nice but kick and ban wont show message for player, when Banned/kicked.
Reply
#10

Because you need to use THIS
Reply
#11

Can someone help me? I used this tutorial to get the promote command and I got these errors:

(199) error 029: invalid expression, assumed zero
(202) error 029: invalid expression, assumed zero

Both 199 and 202 are: else

and also a warning:

warning 209: function "cmd_promote" should return a value
Reply
#12

Quote:
Originally Posted by Strummer
View Post
Can someone help me? I used this tutorial to get the promote command and I got these errors:

(199) error 029: invalid expression, assumed zero
(202) error 029: invalid expression, assumed zero

Both 199 and 202 are: else

and also a warning:

warning 209: function "cmd_promote" should return a value
Post the exact line of code that the error is on.
Reply
#13

Sorry, I just realised what a dumb idiot I am. It's like I'm not even thinking lol xD. I managed to do it myself (the "else" that I didn't even notice was needing something to be else for (SendClientMessage).

EDIT: Altough, now that I test it, the SendClientMessage works, but the command itself responds with Unknown command.

Here it is:

Code:
CMD:promote(playerid,params[])
{
	new id,level;
    if(IsPlayerAdmin(playerid)) //this will check if the player is logged into RCON
    {
        if(sscanf(params,"ud",id,level))return SendClientMessage(playerid, -1,""COL_LIGHTBLUE"Koristi: /promote [ID] [LVL]");
        else
        {
            if(level > 5) return SendClientMessage(playerid, -1,""COL_LIGHTBLUE"Ne smijete ici iznad 5!");
            else
            {
                new INI:File = INI_Open(UserPath(id));//this is the example used in Kush's tut link above, make it fit in your system, note that i've changed the UserPath(playerid) to UserPath(id) to promote the chosen player not yourself
                INI_WriteInt(File,"Admin",level); // writes the admin level in the ini file and makes the player admin.
                INI_Close(File); //closes the ini file
            }
        }
    }
}
There's a warning: 212) : warning 209: function "cmd_promote" should return a value

212 is the last bracket in the code.
Reply
#14

pawn Code:
CMD:promote(playerid,params[])
{
    new id,level;
    if(IsPlayerAdmin(playerid)) //this will check if the player is logged into RCON
    {
        if(sscanf(params,"ud",id,level))return SendClientMessage(playerid, -1,""COL_LIGHTBLUE"Koristi: /promote [ID] [LVL]");
        if(level > 5) return SendClientMessage(playerid, -1,""COL_LIGHTBLUE"Ne smijete ici iznad 5!");
       
        new INI:File = INI_Open(UserPath(id));//this is the example used in Kush's tut link above, make it fit in your system, note that i've changed the UserPath(playerid) to UserPath(id) to promote the chosen player not yourself
        INI_WriteInt(File,"Admin",level); // writes the admin level in the ini file and makes the player admin.
        INI_Close(File); //closes the ini file
    }
    return 1;
}
Reply
#15

Great, thanks!
Reply
#16

Thank you. Much appreciated.
Reply
#17

I hate it when someone does a tutorial and doesn't fully test it. First of all, your admin command /promote does not save.

Code:
CMD:promote(playerid,params[])
{
        new id,level;
	if(IsPlayerAdmin(playerid)) //this will check if the player is logged into RCON
	{
	    if(sscanf(params,"ud",id,level) return //add the sendclientmessage usage: /promote name/id level or something "u" checks the if the player wrote a id or name "d" checks what level you wrote
		else
		{
	        if(level > 5) return //if the player writes a level thats over 5 he will get a error, write the error here
			else
			{
	        	new INI:File = INI_Open(UserPath(id));//this is the example used in Kush's tut link above, make it fit in your system, note that i've changed the UserPath(playerid) to UserPath(id) to promote the chosen player not yourself
	        	INI_WriteInt(File,"Admin",level); // writes the admin level in the ini file and makes the player admin.
	        	INI_Close(File); //closes the ini file
			}
		}
	}
	else
	{
	    //send a message that the player is not logged in as RCON
	}
}
needs to be changed to


Code:
CMD:promote(playerid,params[])
{
        new id,level;
	if(IsPlayerAdmin(playerid)) //this will check if the player is logged into RCON
	{
	    if(sscanf(params,"ud",id,level) return //add the sendclientmessage usage: /promote name/id level or something "u" checks the if the player wrote a id or name "d" checks what level you wrote
		else
		{
	        if(level > 5) return //if the player writes a level thats over 5 he will get a error, write the error here
			else
			{
	        	    PlayerInfo[id][pAdmin] = level;
			}
		}
	}
	else
	{
	    //send a message that the player is not logged in as RCON
	}
}
otherwise it doesn't save. Kush's system already has a save thing for when you disconnect, so there's no need to open or close the file, you just change the variable and it saves when the player disconnects.

In the kick/ban command, there are no timers, so the player getting kicked/banned won't receive the text on his screen. He will only get: Server closed the connection, so add timers. Also for the ban command, you need to redefine the parameters when the player registers/logins because the pBanned won't save.


Sorry for bumping a really old thread, but yeah It's in the useful tutorials sections and the tutorials need to be maintained regularly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)