30.06.2014, 23:44
(
Последний раз редактировалось sammp; 17.07.2014 в 21:45.
Причина: Bugfix "if(!isPlayerAdmin(i)) Kick(playerid)" would kick people who are admins too, just changed to Kick(i)
)
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:
Make a variable somewhere above the command:
Now, we can create the structure for our LOCK command:
By the way, instead of doing 'COMMAND:' you can also use these methods:
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:
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:
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.
Finally, we'll set the Rcon commands and state the server is locked:
Here's the /unlockserver command if you want it:
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.
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;
pawn Код:
COMMAND:lockserver(playerid, params[])
{
return 1;
}
pawn Код:
CMD:lockserver(playerid, params[])
{
return 1;
}
command(lockserver, playerid, params[])
{
return 1;
}
pawn Код:
COMMAND:lockserver(playerid, params[])
{
if(IsPlayerAdmin(playerid))
{
}
else return SendClientMessage(playerid, -1, "* This command is prohibited of access to regular players.");
return 1;
}
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;
}
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;
}
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;
}
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.