[Tutorial] How to make RCON control via dialog.
#1

How to make a RCON control via dialog.


What is this?How can it help?
This is a simple tutorial made by me(Necip) on how to make the commands of RCON on dialog.This can be easier to use and faster than the /rcon command.


What is RCON?
RCON, also known as Remote Console, helps you make thing out of the game's commands, it has it's own commands.


Do I need lots of experience to complete this dialog?
Yes, you need to know the basics as I can't explain all of them.


What do I need?
You will need the ZCMD include, which badly I don't have the link now...


What are we waiting now??
I agree, let's get started...


STEP 1.
We shall first start adding the includes and the color defines.
pawn Code:
#include <a_samp>
#include <zcmd>
// Colors
#define CGREY      0xAFAFAFAA
#define CWHITE     0xFFFFFFAA

STEP 2.
We, also, need dialog defines which are total of 16.You don't have to use defines, but they make it easier and faster.Moreover, we need a function called IsNull, which will check if he wrote something on the dialog or not, and send him a message.
pawn Code:
// Dialogs
#define DRCONLIST   1    // RCON commands list dialog
#define DHOSTNAME   2    // Hostname changing dialog
#define DGMTEXT     3    // Gamemode text changing dialog
#define DMAPNAME    4    // Map name changing dialog
#define DKICK       5    // Kicking dialog
#define DBAN        6    // Banning dialog
#define DCMODE      7    // Gamemode changing dialog
#define DSAY        8    // Admin say dialog
#define DBANIP      9    // Ban IP dialog
#define DUNBANIP    10   // Unban IP dialog
#define DGRAVITY    11   // Gravity changing dialog
#define DWEATHER    12   // Weather changing dialog
#define DLOADFS     13   // FS loading dialog
#define DWEBURL     14   // Web URL changing dialog
#define DUNLOADFS   15   // FS unloading dialog
#define DRELOADFS   16   // FS reloading dialog
// IsNull
#define IsNull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))

STEP 3.
Now let's make a Command for only RCON logged in admins.
pawn Code:
CMD:rconmenu(playerid, params[]) // We will call it /rconmenu
{
    if(IsPlayerAdmin(playerid)) // Checks if the player is RCON admin
    {
        ShowPlayerDialog(playerid, DRCONLIST, DIALOG_STYLE_LIST, "RCON Command List", "Exit\nHostname\nGame Mode Text\nMap Name\nKick\nBan\nChange Mode\nGMX\nSay\nBan IP\nUnban IP\nGravity\nWeather\nLoad Filterscript\nWeb URL\nUnload Filterscript\nReload Filterscript", "Select", "Close"); // Dialog with the things we gotta do
    }
    else // If not RCON Admin show this message
    {
        SendClientMessage(playerid, CGREY, "You need to be Logged In as RCON Administrator.");
    }
    return 1;
}

STEP 4.
This step is a bit harder, you have to know about the OnDialogResponse function.Here I will post the DRCONLIST dialog's response, which means if someone Clicks on Change/Select/Choose or whatever, it will call other dialog.
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DRCONLIST)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    SendClientMessage(playerid, CWHITE, " You have exited the Console."); // If he chose the Exit
                    SendRconCommand("exit");
                }
                case 1:
                {
                    ShowPlayerDialog(playerid, DHOSTNAME, DIALOG_STYLE_INPUT, "Hostname", " Please enter a new Name for your server:", "Change", "Cancel"); // If he chose the Hostname, it will show him a dialog which he will have to write a new hostname
                }
                case 2:
                {
                    ShowPlayerDialog(playerid, DGMTEXT, DIALOG_STYLE_INPUT, "Gamemode text", " Please enter a new gamemode text:", "Change", "Cancel"); // If he chose the Game Mode Text, it will show him a dialog which he will have to write a new Gamemode Text
                }
                case 3:
                {
                    ShowPlayerDialog(playerid, DMAPNAME, DIALOG_STYLE_INPUT, "Map Name", " Please enter a new Map Name for your server:", "Change", "Cancel"); // If he chose the Map Name, it will show him a dialog which he will have to write a new mapname
                }
                case 4:
                {
                    ShowPlayerDialog(playerid, DKICK, DIALOG_STYLE_INPUT, "Kick ID", " Please enter the ID you want to kick:", "Kick", "Cancel"); // If he chose the Kick, it will show him a dialog which he will have to write an ID he wants to get kicked.
                }
                case 5:
                {
                    ShowPlayerDialog(playerid, DBAN, DIALOG_STYLE_INPUT, "Ban ID", " Please enter the ID you want to ban:", "Ban", "Cancel"); // If he chose the Ban, it will show him a dialog which he will have to write an ID he wants to get banned
                }
                case 6:
                {
                    ShowPlayerDialog(playerid, DCMODE, DIALOG_STYLE_INPUT, "Change Mode", " Please enter a new GameMode for your server:", "Change", "Cancel"); // If he chose the Change Mode, it will show him a dialog which he will have to write a new Gamemode to load
                }
                case 7:
                {
                    SendClientMessageToAll(CWHITE, " Server Restarting in 10 seconds!");
                    SetTimerEx("SRestart", 10000, 1, "i", playerid); // If he pressed the GMX, it will make him a timer which will restart the server
                }
                case 8:
                {
                    ShowPlayerDialog(playerid, DSAY, DIALOG_STYLE_INPUT, "Admin Say", " Please enter something you want to say:", "Say", "Cancel"); // If he chose the Say, it will show him a dialog which he will have to write an admin message to send
                }
                case 9:
                {
                    ShowPlayerDialog(playerid, DBANIP, DIALOG_STYLE_INPUT, "Ban IP", " Please enter an IP that you want to ban:", "Ban IP", "Cancel"); // If he chose the Ban IP, it will show him a dialog which he will have to write an IP he wants to get banned
                }
                case 10:
                {
                    ShowPlayerDialog(playerid, DUNBANIP, DIALOG_STYLE_INPUT, "Unban IP", " Please enter an IP that you want to unban:", "Unban IP", "Cancel"); // If he chose the Unban IP, it will show him a dialog which he will have to write an IP he wants to get unbanned
                }
                case 11:
                {
                    ShowPlayerDialog(playerid, DGRAVITY, DIALOG_STYLE_INPUT, "Gravity", " Please enter the amount of Gravity you want to be:", "Set Gravity", "Cancel"); // If he chose the Gravity, it will show him a dialog which he will have to write a new gravity for the server
                }
                case 12:
                {
                    ShowPlayerDialog(playerid, DWEATHER, DIALOG_STYLE_INPUT, "Weather", " Please enter a weather ID to change Weather:", "Set Weather", "Cancel"); // If he chose the Weather, it will show him a dialog which he will have to write a new Weather for the server
                }
                case 13:
                {
                    ShowPlayerDialog(playerid, DLOADFS, DIALOG_STYLE_INPUT, "Load Filterscript", " Please enter a Filterscript name to Load:", "Load FS", "Cancel"); // If he chose the Load Filterscript, it will show him a dialog which he will have to write a FS to load
                }
                case 14:
                {
                    ShowPlayerDialog(playerid, DWEBURL, DIALOG_STYLE_INPUT, "Web URL", " Please enter a Web URL to set:", "Set Web URL", "Cancel"); // If he chose the Web URL, it will show him a dialog which he will have to write a new WEB URL
                }
                case 15:
                {
                    ShowPlayerDialog(playerid, DUNLOADFS, DIALOG_STYLE_INPUT, "Unload Filterscript", " Please enter a Filterscript name to Unload:", "Unload FS", "Cancel");// If he chose the Unload Filterscript, it will show him a dialog which he will have to write a FS to unload
                }
                case 16:
                {
                    ShowPlayerDialog(playerid, DRELOADFS, DIALOG_STYLE_INPUT, "Reload Filterscript", " Please enter a Filterscript name to Unload:", "Reload FS", "Cancel");// If he chose the Reload Filterscript, it will show him a dialog which he will have to write a FS to reload
                }
            }
        }
    }
    if(dialogid == DHOSTNAME) // If he responsed on the Hostname change it will send him a message and change the Hostname
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "hostname %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Hostname changed!");
        }
    }
    if(dialogid == DGMTEXT) // If he responsed on the Gamemode text change it will send him a message and change the GM text
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "gamemodetext %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Gamemode text changed!");
        }
    }
    if(dialogid == DMAPNAME) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
            return 1;
            }
            new string[256];
            format(string,sizeof(string), "mapname %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Mapname changed!");
        }
    }
    if(dialogid == DKICK) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "kick %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " You have kicked the player!");
        }
    }
    if(dialogid == DBAN) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "ban %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " You have kicked the player!");
        }
    }
    if(dialogid == DCMODE) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "changemode %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Gamemode text changed!");
        }
    }
    if(dialogid == DSAY) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "say %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Admin message sent!");
        }
    }
    if(dialogid == DBANIP) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "banip %s", inputtext);
            SendRconCommand(string);
            format(string,sizeof(string), "You have banned IP %s", inputtext);
            SendClientMessage(playerid, CWHITE, string);
        }
    }
    if(dialogid == DUNBANIP) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "unbanip %s", inputtext);
            SendRconCommand(string);
            format(string,sizeof(string), "You have unbanned IP %s", inputtext);
            SendClientMessage(playerid, CWHITE, string);
        }
    }
    if(dialogid == DGRAVITY) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "gravity %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Gravity changed!");
            }
    }
    if(dialogid == DWEATHER) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "weather %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Weather changed!");
        }
    }
    if(dialogid == DLOADFS) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "loadfs %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Filterscript loaded!");
        }
    }
    if(dialogid == DWEBURL) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "weburl %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Server Web URL changed!");
        }
    }
    if(dialogid == DUNLOADFS) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "unloadfs %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Filterscript unloaded!");
        }
    }
    if(dialogid == DRELOADFS) // SAME AS ABOVE DIALOGS^^
    {
        if(response)
        {
            if(IsNull(inputtext))
            {
                SendClientMessage(playerid, CGREY, "You did not enter anything" );
                return 1;
            }
            new string[256];
            format(string,sizeof(string), "reloadfs %s", inputtext);
            SendRconCommand(string);
            SendClientMessage(playerid, CWHITE, " Filterscript reloaded!");
        }
    }
    return 1;
}

STEP 5.
Finally, we will need a function for the Timer of GMX to restart the server.This will send players a message and Send the command "gmx" to the RCON.
pawn Code:
forward SRestart();
public SRestart()
{
    SendClientMessageToAll(CWHITE, "Server restarts!");
    SendRconCommand("gmx");
}
This is the end of the tutorial.Please note that this is first time that I make a tutorial, and it may be a little bit bad.I tried my best.Leave comments, feedback and questions below.

Credits:
Zeex ~ ZCMD,
Necip ~ Tutorial.
Reply
#2

....
Reply
#3

NEVER MIND. You're right.
Reply
#4

....
Reply
#5

I just made it for those who would like to do it via Dialog.Thanks for the feedback guys.
Reply
#6

Awesome work dude, this is really useful and handy!
Reply
#7

Thanks Jimmy, hope it helps
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)