[Tutorial] How to lock your gamemode whilst ingame
#1

Hi there. This simple tutorial will show you how to lock your server in-game.

This is handy for 2 easy reasons:

- Maintenance.
- Hack defense.


What this system does is that you type one command, and everybody other than administrators will be kicked. This can be used for maintaining a server, or defending peoples accounts against hackers.

Before you start scripting this tutorial, I must warn you that you will need these plugins/includes:
- Zeex' ZCMD [Click for download]


Okay, now that you've got ZCMD we can get right into creating this script.

For any complete noobs at SA-MP scripting, you can include ZCMD into your script by doing this:
pawn Код:
#include <zcmd>

Make a variable somewhere above the command:
pawn Код:
new serverLocked = 0;
Now, we can create the structure for our LOCK command:
pawn Код:
COMMAND:lockserver(playerid, params[])
{
    return 1;
}
By the way, instead of doing 'COMMAND:' you can also use these methods:

pawn Код:
CMD:lockserver(playerid, params[])
{
    return 1;
}

command(lockserver, playerid, params[])
{
    return 1;
}
Alright, now that the basic structure for the command has been programmed, we can now begin to set some permissions. My script will only have admins be locking the server, as it can be a serious thing for big servers:
pawn Код:
COMMAND:lockserver(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
       
    }
    else return SendClientMessage(playerid, -1, "* This command is prohibited of access to regular players.");
    return 1;
}
An 'else return' statement is in place so the player can be notified the command is prohibited for them.

Now, we must make a loop to check what players are administrators and what players are not administrators:
pawn Код:
COMMAND:lockserver(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(!IsPlayerAdmin(i)) Kick(playerid); // you can use KickWithMessage if you want, I'm just using Kick() for the sake of time.
           
        }
    }
    else return SendClientMessage(playerid, -1, "* This command is prohibited of access to regular players.");
    return 1;
}
Okay, now that players who are not admins are kicked, we can proceed to check whether the server is already locked. This is just to make sure no errors can happen. Wrap your for statement in this.
pawn Код:
COMMAND:lockserver(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        if(serverLocked == 0)
        {
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(!IsPlayerAdmin(i)) Kick(i); // you can use KickWithMessage if you want, I'm just using Kick() for the sake of time.
               
                SendClientMessage(i, -1, "[MESSAGE] The server has just been locked. If you disconnect, you will not be able to reconnect until the server is unlocked.");
            }
        }
        else return SendClientMessage(playerid, -1, "** The server is already locked!");
    }
    else return SendClientMessage(playerid, -1, "* This command is prohibited of access to regular players.");
    return 1;
}
Finally, we'll set the Rcon commands and state the server is locked:
pawn Код:
COMMAND:lockserver(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        if(serverLocked == 0)
        {
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(!IsPlayerAdmin(i)) Kick(playerid); // you can use KickWithMessage if you want, I'm just using Kick() for the sake of time.
               
                SendClientMessage(i, -1, "[MESSAGE] The server has just been locked. If you disconnect, you will not be able to reconnect until the server is unlocked.");
               
                // the rcon commands to set password etc
                SendRconCommand("hostname [LOCKED] Server Name");
                SendRconCommand("password ab!##dmandieAMCUNE3918784MCOAKCNanchedBMIDCL"); // Make the pass difficult
            }
        }
        else return SendClientMessage(playerid, -1, "** The server is already locked!");
    }
    else return SendClientMessage(playerid, -1, "* This command is prohibited of access to regular players.");
    return 1;
}
Here's the /unlockserver command if you want it:
pawn Код:
COMMAND:unlockserver(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
        if(serverLocked == 1)
        {
            serverLocked = 0;
            SendRconCommand("hostname Server Name");
            SendRconCommand("password 0");
        }
    }
}

Note: This was used with the RCON Admin system, you can use your own system if you wish.
Please tell me if I've done something wrong and don't complain about it, thanks.
Reply


Messages In This Thread
How to lock your gamemode whilst ingame - by sammp - 30.06.2014, 23:44
Re: How to lock your gamemode whilst ingame - by SHE790 - 02.07.2014, 23:33
Re: How to lock your gamemode whilst ingame - by NewerthRoleplay - 02.07.2014, 23:37
Re: How to lock your gamemode whilst ingame - by Wilbert - 02.07.2014, 23:47
Re: How to lock your gamemode whilst ingame - by sammp - 04.07.2014, 01:08
Re: How to lock your gamemode whilst ingame - by Snipa - 04.07.2014, 01:19
Re: How to lock your gamemode whilst ingame - by sammp - 04.07.2014, 12:27
Re: How to lock your gamemode whilst ingame - by Inverse - 04.07.2014, 12:37
Re: How to lock your gamemode whilst ingame - by sammp - 11.07.2014, 20:37
Re: How to lock your gamemode whilst ingame - by Kwarde - 14.11.2014, 19:15

Forum Jump:


Users browsing this thread: 2 Guest(s)