[Tutorial] Simple Rcon commands!
#1

Hello guys

This is my first tutorial! So...Today I will teach you guys, how to make a simple Rcon commands. If you don't know how to login in Rcon, let me tell you Just type ingame /rcon login [password] (Your password is in server.cfg => rcon_password).

Let's start!

First of all, we will include some includes:
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
Here are the links for sscanf2 and zcmd if you don't already have it.

Now we will define some colors!

pawn Code:
#define COLOR_RED         0xFF0000C8
#define COLOR_WHITE       0xFFFFFFC8
#define COLOR_YELLOW      0xDFF709C8
#define COLOR_GREEN       0x09F709C8
#define COLOR_BLUE        0x0000FFC8
We will also use this stock, to get player's name faster!

pawn Code:
stock GetName(playerid)
{
    new
    name[24];
    GetPlayerName(playerid, name, sizeof(name));
    return name;
}
Now we will make some commands!

NOTE: I will make a command first and then I will explain each line!

Let's start with /kick [palyerid] [reason]

pawn Code:
CMD:kick(playerid, params[]);
{
    new targetid;
    new reason[50];
    new string[200];
    if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
    if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: This player is not Connected!");
    if(sscanf(params, "us[50]", targetid, reason))return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /kick [Playerid] [Reason]");
    format(string, sizeof(string), "[ADMIN]: Administrator %s(ID:%d) has kicked %s(ID:%d)! [Reason: %s]", GetName(playerid), playerid, GetName(targetid), targetid, reason);
    SendClientMessageToAll(COLOR_YELLOW, string);
    Kick(targetid);
    return 1;
}
Let me explain

pawn Code:
new targetid;
new reason[50];
new string[200];
This tells the system to create a new variables "targetid => player which we want to kick", "reason => to write a reason with MAX. 50 characters" and "string => we will use this to send a message to all players that we kicked someone".

pawn Code:
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
This will check, if the player is logged in rcon, if he isn't, it will send him a message "[ERROR]: You aren't an Rcon Admin!"

pawn Code:
if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: This player is not Connected!");
This will check, if the player we want to kick is connected, if he isn't, it will send this message to a player "[ERROR]: This player is not Connected!"

pawn Code:
if(sscanf(params, "us[50]", targetid, reason))return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /kick [Playerid] [Reason]");
This will check, if the player write /kick [playerid] [reason], if he doesn't, he will get this message "[USAGE]: /kick [Playerid] [Reason]"

pawn Code:
format(string, sizeof(string), "[ADMIN]: Administrator %s(ID:%d) has kicked %s(ID:%d)! [Reason: %s]", GetName(playerid), playerid, GetName(targetid), targetid, reason);
This will create a string, that an administrator has kicked a player..

pawn Code:
SendClientMessageToAll(COLOR_YELLOW, string);
This will send a message to all online players that an administrator has kicked a player..

pawn Code:
Kick(targetid);
This will kick a player.

This was a /kick command

Now, let's make an /explode [playerid] command!

pawn Code:
CMD:explode(playerid, params[])
{
    new string[200], targetid, Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
    if(sscanf(params, "u", targetid))return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /explode [Playerid]");
    if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: This player is not connected!");
    GetPlayerPos(targetid, x, y, z);
    CreateExplosion(x, y, z, 12, 10.0);
    format(string,sizeof(string), "[ADMIN]: Administrator %s(ID:%d) has Exploded %s(ID:%d)!", GetName(playerid), playerid GetName(targetid), targetid);
    SendClientMessage(playerid, COLOR_PURPLE, string);
    return 1;
}
Let me explain

pawn Code:
new string[200], targetid, Float:x, Float:y, Float:z;
This tells the system to create a new variables "targetid => player which we want to explode", "Float, Float:y, Float:z => we will use this to get the player's position" and "string => we will use this to send a message to all players that we exploded someone".

pawn Code:
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
This will check, if the player is logged in rcon, if he isn't, it will send him a message "[ERROR]: You aren't an Rcon Admin!"

pawn Code:
if(sscanf(params, "u", targetid))return SendClientMessage(playerid, COLOR_WHITE, "[USAGE]: /explode [Playerid]");
This will check, if the player write /explode [playerid], if he doesn't, he will get this message "[USAGE]: /explode [Playerid]"

pawn Code:
if(!IsPlayerConnected(targetid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: This player is not connected!");
This will check, if the player we want to kick is connected, if he isn't, it will send this message to a player "[ERROR]: This player is not Connected!"

pawn Code:
GetPlayerPos(targetid, x, y, z);
This will get the player's position.

pawn Code:
CreateExplosion(x, y, z, 12, 10.0);
This will create an explosion on the player's position.

pawn Code:
format(string,sizeof(string), "[ADMIN]: Administrator %s(ID:%d) has Exploded %s(ID:%d)!", GetName(playerid), playerid GetName(targetid), targetid);
This will create a string, that an administrator has exploded a player..

pawn Code:
SendClientMessageToAll(playerid, COLOR_YELLOW, string);
This will send a message to all online players that an administrator has exploded a player..

This was an /explode command

Now, let's make the last command for this tutorial /announce [text]

pawn Code:
CMD:announce(playerid, params[])
{
    new text[60];
    if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
    if(sscanf(params,"s[60]",text))return SendClientMessage(playerid, COLOR_GREY, "[USAGE]: /announce [Text]");
    GameTextForAll(text, 3000, 5);
    return 1;
}
Let me explain again

pawn Code:
new text[60];
This tells the system to create a new variable "text => this will be the text, we want to write

pawn Code:
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Rcon Admin!");
This will check, if the player is logged in rcon, if he isn't, it will send him a message "[ERROR]: You aren't an Rcon Admin!"

pawn Code:
if(sscanf(params,"s[60]",text))return SendClientMessage(playerid, COLOR_GREY, "[USAGE]: /announce [Text]");
This will check, if the player write /announce [text], if he doesn't, he will get this message "[USAGE]: /announce [Text]"

pawn Code:
GameTextForAll(text, 3000, 5);
This will create a game text for all online players with the text, you typed in

That is all for today I hope you guys like this tutorial

Sorry for my bad english!
Reply
#2

Nice tutorial.
You Explained these things very detail and easy to understand

Keep it up
Reply
#3

Quote:
Originally Posted by qazwsx
View Post
Nice tutorial.
You Explained these things very detail and easy to understand

Keep it up
Thanks
Reply
#4

Guys, please tell me if is good
Reply
#5

Really nice, Keep it up.
Reply
#6

I don't see anything related to remote console, except those stuff can only applied by users logged in through the remote console.
Reply
#7

-rep because fake one
Reason: Rcon Have Already Commands
here : https://sampwiki.blast.hk/wiki/RCON#RCON_Commands
that will show all cmds
or go In Game and do /rcon login (your rcon pass)
then
/rcon cmdlist
Done!
will show u a list of cmds
Reply
#8

Quote:
Originally Posted by Napster101
View Post
-rep because fake one
Reason: Rcon Have Already Commands
here : https://sampwiki.blast.hk/wiki/RCON#RCON_Commands
that will show all cmds
or go In Game and do /rcon login (your rcon pass)
then
/rcon cmdlist
Done!
will show u a list of cmds
What's fake? It's no need to use IsPlayerAdmin. What about, if person already have login/register system? Then they can use his way to check if player is an admin! Ex:
pawn Code:
if(pInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: You aren't an Admin level 1");
And this tutorial is still useful.
Reply
#9

Quote:
Originally Posted by Napster101
View Post
-rep because fake one
Reason: Rcon Have Already Commands
here : https://sampwiki.blast.hk/wiki/RCON#RCON_Commands
that will show all cmds
or go In Game and do /rcon login (your rcon pass)
then
/rcon cmdlist
Done!
will show u a list of cmds
lol... whats so FAKE?


Mr. Private Server LOL
Reply
#10

Good tutorial its nice for newbie scripter
Reply
#11

nice tutorial, thanks :)
but i still don't understand what /explode does ?? ???
Reply
#12

Quote:
Originally Posted by AnonScripter
Посмотреть сообщение
nice tutorial, thanks
but i still don't understand what /explode does ??
It explode a player, to see if he using Health Hack for an example.. :
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)