Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] [SA-MP] Admin Commands.

Newbie Spellweaver
Joined
Jul 20, 2008
Messages
30
Reaction score
1
Hey everyone. Today I will teach you something on how to make admin commands. (RCON ADMIN REQUIRED).

Note:
You will need the RCON password you've set in the server.cfg
To login as an admin use: /rcon login PASS.

First I want you to download sscanf and zcmd.
You have to find them yourself. It's easy by just search them on google. Show some effort.
If you downloaded them and putted them in your pawno include folder I want you to put this on top of your script UNDER a_samp

#include <zcmd>
#include <sscanf>
#define COLOR_WHITE 0xFFFFFFAA
new name1[MAX_PLAYER_NAME];
new name2[MAX_PLAYER_NAME];
new String[286];
new id;
Part 1: Kick command.
I decided to begin with a simple /kick command.
Let's make a list of what we want and need to be in the command.

- The admin his name
- The player his name
- A kicking reason
- Authentation of using the command
- The message/string that will be sended to everyone

- Kicking the person
We will use ZCMD because it's way faster then strcmp.
Put the command anywhere in your script but NOT in callback.
We'll start with making the command. A zcmd command is easily made like this:

COMMAND:kick(playerid,params[])
{

return 1; // Stops the command.
}

That's the command without any effect.

We will first need to make it only available for a RCON admin.
COMMAND:kick(playerid,params[])
{
new reason[80]; // The 80 cells are there because that is the maximum ammount of characters you can fill in.
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_WHITE,"You're not allowed to use this command.");
return 1; // Stops the command.
}
You can see we've added one more line. This line checks if a player is an admin or not.
Let's translate the line in an English sentence

If the player is NOT an admin, he will get the message: You're not allowed to use this command.
Take a look at the ! infront of IsPlayerAdmin. The ! will make it that it looks if you are NOT an admin.
I hope you understand.

Now we will make a bigger step. We want to see if you typed in the command on a good manner. It must be:
/kick playerid reason.
If you don't use it correctly like:
/kick playerid, it will return a message.
You have to tell everything to your script to make it work.
You have to be precisly.
We also want to show a message when the target isn't connected

COMMAND:kick(playerid,params[])
{
new reason[80];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_WHITE,"You're not allowed to use this command.");
if (sscanf(params, "us[80]", id,reason)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /kick [playerid] [reason]"); //If you didn't fill in the command correctly.
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_WHITE,"This player is not connected."); // Obvious why.
return 1; // Stops the command.
}

Alright. That were all our checks. Let's go to the real business now.
We want to let everything work.
We want the effect now. We want to kick this person and show him the reason.
We're going to use a few functions.

- format String
- Kick();
- GetPlayerName();

COMMAND:kick(playerid,params[])
{
new reason[80];
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_WHITE,"You're not allowed to use this command.");
if (sscanf(params, "us[80]", id,reason)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /kick [playerid] [reason]"); //If you didn't fill in the command correctly.
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_WHITE,"This player is not connected."); // Obvious why.
GetPlayerName(playerid, name1, sizeof(name1)); // Getting the name of the playerid
GetPlayerName(id, name2, sizeof(name2)); // Getting the name of the target.
format(String,sizeof(String),"%s has been kicked by admin %s Reason: %s",name2,name1,reason); //We're defining the message here. with it's information
SendClientMessageToAll(COLOR_WHITE,String); // Sends the message to everyone.
Kick(id); //Will kick the player. Make sure it is id and not playerid because playerid will kick yourself.
return 1; // Stops the command.

}



This was the first part of the tutorial. More will come soon.
I didn't use a compiler for this because my own PC doesn't work anymore and on this laptop I'm not allowed to download anything.
If any errors are found please post them here so I can fix them ASAP.

There will come more soon. I hope I can get my PC back quickly so I can update this alot faster.
For now you only have the /kick command and you can figure out something more with it.

In the next part of the tutorial I will show you the following:

- Ban command
- NOS command
- Carrepair command
- Vehiclespawn command
- Announce command

Please leave a comment.
I will see you in the next part soon.
 
Back
Top