[Tutorial] /setscore command.
#1

Hello, and welcome :].
Today i will teach you how to create a /setscore command.
First of all, you will need sscanf and zcmd.
sscanf: https://sampforum.blast.hk/showthread.php?tid=120356
zcmd: https://sampforum.blast.hk/showthread.php?tid=91354
...
Now that you've downloaded them, added them into your pawno/include folder and you've added them in your pawno file:
[ #include <a_samp>
#include <sscanf2>
#include <zcmd>
]
You will need these color defines: (Add them under the includes)
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_NAVY 0x000080AA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIME 0x10F441AA
Alright..
Now let's start.
pawn Code:
CMD:setscore(playerid, params[]) {
    new id;
    new score;
    new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
This is the 'beginning' of the command.
setscore is the commands name itself, whilst "new id", "new score" and "new name" are "variables"(not really ..) that will help us set the targets score.
[ id = targets id, score = the score you will want to set, name .... = the string(%s) message for the target ]
GetPlayerName will get the targets name.
Next thing is that we want to make the command to work for RCON admins only.
By that we will add:
pawn Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "You're not allowed to use this command!");
If the player won't be logged in via the RCON, he will get this "error" message.
Under that we will want to add these 3 lines:
pawn Code:
if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid, COLOR_NAVY, "USAGE: /setscore [ID]     [SCORE]");
    if(score < 1) return SendClientMessage(playerid, COLOR_ORANGE, "You need to give more than 1 score.");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is not online.");
1st line: If the player/admin will for an example type "/setscore ID", he will receive the message(as seen above), that will show him how to use the command.
2nd line: The admin will only be able to set the players score to 1 as the minimum.
"You can remove that / change that"..
3rd line: If the target won't be connected/if the targets id wont be "valid", he will receive the message, saying "Target is not online".
Then the last thing we will want to do, is to actually make the target receive his score.
To do so, we will need to add these lines:
pawn Code:
SetPlayerScore(id, score);
    format(string, sizeof(string), "Admin %s has given you some score!", name);
    SendClientMessage(id, COLOR_ORANGE, string);
    return 1;
SetPlayerScore(id, score); will set the targets score, to the score that was written in the "/setscore ID SCORE" command.
Last 2 lines are for the message.
(You can again, remove those lines if you want to..)
This is so the player can know that an admin has set/changed his score.
Well, now you're pretty much done.
The full code:
pawn Code:
CMD:setscore(playerid, params[]) {
    new id; // "defines" the targets id.
    new score; // Gets the targets score ( was added to prevent an error.)
    new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
    GetPlayerName(playerid, name, sizeof(name));
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "You're not allowed to use this command!"); //If the player who typed the command isn't logged in via the RCON, he will receive this "error" message.
    if(sscanf(params, "ui", id, score)) return SendClientMessage(playerid, COLOR_NAVY, "USAGE: /setscore [ID] [SCORE]"); //If there aren't enough params typed in(ex - /setscore ID)
    if(score < 1) return SendClientMessage(playerid, COLOR_ORANGE, "You need to give more than 1 score."); //This isn't really needed, but it "forces" the admin to give the player more than 1 score.
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_ORANGE, "Target is not online."); //If the targets id isn't "valid", the admin will receive this "error" message, cause there was no ID found.
    SetPlayerScore(id, score);  //Sets the targets score.
    format(string, sizeof(string), "Administrator %s has given you some score!", name); //Target receives this message.
    SendClientMessage(id, COLOR_ORANGE, string);
    return 1;
}
EXTRA INFO:
You can change the "if(score < 1)" to anything.
For an example ->
if(score < 100) return SendClientMessage(playerid, COLOR_ORANGE, "You need to give more than 100 score.");
-------------
/kick command.
"This was 'based' on a /warn command made by DanishHaq(Big thanks to you!)"
Basically, you will need everything that i've mentioned before
(color defines, zcmd and sscanf.)
Alright, let's go.
First MOST important thing we will need to add is this:
pawn Code:
forward KickTimer(playerid);
This is so the target can actually see his kick reason.
Next thing that we will need, is adding this:
pawn Code:
public KickTimer(playerid)
{
    Kick(playerid);
    return 1;
}
This will 'trigger' the kick-timer, so he will be able to see his own kick message.
[add this anywhere in the "public" "section".
Alright.. now, let's start by making the basic again.
[pawn] CMD:kick(playerid, params[]) {
new id;
new reason[50];[/[pawn]
"...CMD:kick..." is the command it self.
It will 'trigger' when an RCON admin has typed /kick.
"... new id..." will "allow" you to use the command on a target(ID) // sscanf comes here.
"... new reason[50]..." As i've mentioned before, it's "based" on a /warn script.
Well, this will set a 'string' for the Reason message.


Now that the first things are done, we want to make the command work for admins only.
By that, we will add this line:
pawn Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "You're not allowed to use this command!");
This will make sure that an RCON admin can use the command.
If the player won't be logged in via RCON(/rcon login *password), he will get this "error" message..

Then, we will want to make sure that the admin who uses the command, is using it correctly.
By that we will add this line:
pawn Code:
if(sscanf(params, "us[50]", id, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /kick [ID] [Reason]");
This is where the id / reason comes in handy.
If the sscanf include doesn't detect the "id" and the "reason", it will send the Admin the usage line.
Alright, now we want to make sure that the id / target is actually online.
By that, we will add this following line:

pawn Code:
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ORANGE, "Player not found.");
If the target ID won't be found(won't be "valid"), the admin will receive the message, saying that the player is not found.

Alright, now we go into the harder 'zone'.
Now we need to make the kick, kick 'text'(Admins name/id, targets name/id, reason.), which might be more confusing.

pawn Code:
GetPlayerName(playerid, sender, sizeof(sender));
    GetPlayerName(id, receiver, sizeof(receiver));
    format(string, sizeof(string), "%s(%d) has been kicked by %s(%d)", receiver, id, sender, playerid);
    SendClientMessageToAll(COLOR_RED, string);
    format(string, sizeof(string), "Reason: %s", reason);
    SendClientMessageToAll(COLOR_RED, string);
    SetTimerEx("KickTimer", 1000, false, "i", id);
    SendClientMessage(id, COLOR_ORANGE, "You've been kicked");
    SendClientMessage(id, COLOR_ORANGE, "For more info read the chat.");
1st line: Will get the admins name/id, for the kick message(Line 3)
2nd line: Will get the targets name/id, for the kick message(line 3)
3rd line: This is a format, of how the message will look, when it will be sent to EVERY player on the server, saying that "TargetsName(TargetsID)has been kicked by AdminsName(AdminsID)".
4th line: Actually 'sends' the line, in the red color(can be changed.)
5th line: This will be the 'format' of the Reason.
And as you know, we added "new reason[50];" in the start, and in the sscanf line.
6th line: Sends every player the Reason why the target was kicked.
7th line: Sets the KickTimer to 1 second(After 1 second he will be kicked) CAN BE CHANGED.
8th and 9th line: Will send a message to the target, saying that he was kicked.
Full code:
pawn Code:
CMD:kick(playerid, params[]) {
    new id; //'defines' the targets id.
    new reason[50]; //'defines' the reason.
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "You're not allowed to use this command!"); //if player isn't a rcon admin, he will receive this "error" message.
    if(sscanf(params, "us[50]", id, reason)) return SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /kick [ID] [Reason]"); //if there are missing parameters, the admin will receive the usage of this command.
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_ORANGE, "Player not found."); //If the targets id isnt found, the admin will receive this message (Player Not found).
    new string[150], sender[MAX_PLAYER_NAME], receiver[MAX_PLAYER_NAME]; //thanks to this, everyone will be able to see who was kicked, and by who.
    GetPlayerName(playerid, sender, sizeof(sender)); //Gets the senders(admins) name/id.
    GetPlayerName(id, receiver, sizeof(receiver)); //Gets the receivers(targets) name/id.
    format(string, sizeof(string), "%s(%d) has been kicked by %s(%d)", receiver, id, sender, playerid);
    SendClientMessageToAll(COLOR_RED, string); //Sends the kick message, as seen above ^.
    format(string, sizeof(string), "Reason: %s", reason);
    SendClientMessageToAll(COLOR_RED, string); //Sends the kick reasons message, as seen above ^
    SetTimerEx("KickTimer", 1000, false, "i", id); //Sets KickTimer to 1 seond(will be kicked after 1 second)
    SendClientMessage(id, COLOR_ORANGE, "You've been kicked"); //Sends Target a message, saying that he was kicked.
    SendClientMessage(id, COLOR_ORANGE, "For more info read the chat.");
    return 1;
}
NOTES ABOUT KICK: You can modify the messages saying like
pawn Code:
SendClientMessage(id, COLOR_ORANGE, "If you think that an admin abused his powers");
        SendClientMessage(id, COLOR_ORANGE, "Report him at the forums!");
        SendClientMessage(id, COLOR_ORANGE, "*FORUMS LINK HERE*");
        return 1;
}
Or..
pawn Code:
SendClientMessage(id, COLOR_ORANGE, "You've been kicked");
        format(string, sizeof(string), "Kick reason: %s", reason);
    SendClientMessage(id, COLOR_RED, string);
You can also send make it send a message to the RCON admins.
(Add this at the end of the :kick command)
pawn Code:
format(string,sizeof(string),"[ADMIN KICK] %s(%d) used the command KICK on %s(%d)", receiver, id, sender, playerid);
    SendMessageToAdmins(string);
^ That will send the message to all the logged-in RCON Admins.
It will look something like this(With all the stuff added together):

BUT. If you've added the "SendMessageToAdmins", you will need to at this at the bottom of your scripting:
pawn Code:
stock SendMessageToAdmins(text[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerAdmin(i))
        {
            SendClientMessage(i, COLOR_LIME, text);
        }
    }
}
This will actually send the message to the RCON admins.


NOTES ABOUT COMMANDS: These commands were tested on the 'localhost' server, which means that it wasn't tested with 2 players, but hopefully it should work.
Reply
#2

Nice add the color defines
and whats up mate remember me prostriker
Reply
#3

Thank you for the Tutorial !
Reply
#4

Nice tutorial
Reply
#5

Hmmm It's easy to make but this tutorial is good for newbies.
Reply
#6

seems basic, but, if you do more cmds would be better than this
try to edit the post and add more things like, more cmds or /ban /kick cmd /report /pm
good luck !
Reply
#7

Thanks everyone :]
@Rafel: Will try to make those, since you "suggested/requested" them, when i have free time.
:]
Reply
#8

Sorry for double-posting.
Well, updated the thread.
Added /kick.
It has the Kicker(Admin), Kicked player, reason AND it sends the message to the logged-in RCON admins.
IMPORTANT:
Please add the new color #defines (COLOR_RED, COLOR_LIME).
Also read the kick part carefully!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)