PDA

View Full Version : [Tutorial] Admin Script (y_ini,sscanf,zcmd)



SergiuOfficial
13-06-17, 10:43
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 Y_Less. Also read the the post to learn sscanf proberbly.
Y_INI. By Y_Less. To save our stats. Read this tut by Y_LessHow to use Y_INI
ZCMD. By zeex. This will be our command prossesor.
You can also use Y_Commands. By Y_Less. 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.
Code:
#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
Code:
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.-.-.
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
}
}

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
Code:
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
Code:
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
Code:
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!!!