How to make simple admin commands using sscanf and ZCMD. -
Odyssey - 29.07.2011
How to make simple admin commands!
**This is my first tutorial, please dont hate.
Well, just a couple of days ago, I had no idea on how to make a admin command. But, I just learned how to use "Sscanf" by ******, and it all came really simple to me! So, I thought I would show you some basics on how to use it.
This is surely %100 beter than using "Strtok".
So, we will use SA-MP's defualt admin system, called "RCON". Which uses the function
IsPlayerAdmin(playerid);.
Lets start of with the basic command, lets do a "Kick" command.
So, we make the start of the command. I dont really need to explain this, most people know how to do it.
pawn Код:
CMD:kick(playerid, params[])
{
First, wee need to check if they are a admin. We will do this by using
IsPlayerAdmin.
pawn Код:
CMD:kick(playerid, params[])
{
new id, reason[128];
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_WHITE, "You need to be a admin to use that command!");
The "new id" is making a new variable for the user ID to kick. The "reason[128]" is creating a variable to store the reason in.
The "!" in the code is checking if they are NOT a admin, so therefore sending the error message, and returning.
It can be used in all sorts. Here is a quick example.
pawn Код:
CMD:lol(playerid, params)
{
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, COLOR_WHITE, "u need to be in teh car 2 use teh lol command!");
else {
SendClientMessage(playerid, COLOR_WHITE, "LOL! U IZ IN CAR!");
}
return 1;
}
Now this is the part where we use sscanf. So, I will try and explain my best.
pawn Код:
CMD:kick(playerid, params[])
{
new id, reason[128];
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_WHITE, "You need to be a admin to use that command!");
else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
Ok ill start with the MOST basic thing of this line. Whics is the "else if", basicaly all that means if the above line is false, and the player is a admin, it wil skip that line and go to the sscanf line.
The next most basic thing is sending the message. If the paramters in the command the user entered are false. It will send the "Usage" message, telling them how to use it.
e.g. If I do /kick techkid100, it will send the usage message.
Now, the tricky bit for me to explain.
Now, the "US" is the the type of paramter we are typing.
We can change theese for many things.
U = Playerid/Name
S = String (e.g. Ban reason)
I = Interger (e.g. Set Money, a number)
D = Interger (e.g. Set Money, a number)
F = Float (e.g. Co-ordinate)
Those are the basic paramters which you will MOSTLY use.
pawn Код:
(sscanf(params, "us", id, reason))
The "id, reason" part of it is are variables, remember when we created them? If it were to be "(sscanf(params, "su", id, reason))" it wouldnt work becuase it is checking the string as the the ID, and the ID as the string/reason. So it needs to be in order.
Yeh, I did my best at explaining that. Sorry if it sucked. :P
Now, we want to prevent errors, e.g. Kicking yourself, or Kicking a player what is not connected, or kicking another admin, so we will overcome theese.
First we will stop the abilty to kick our self.
pawn Код:
else if(id==playerid)SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick yourself!");
So, this is checking that the id we entered isnt the playerid, (playerid is the ID of the player who used the command).
Now, you will probably know how to make the others.
Not kicking another admin.
pawn Код:
else if(IsPlayerAdmin(id))SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick another admin!");
You cant put (id=IsPlayerAdmin(playerid)) becuase it will check if we are admin, so we put "id" to check if the player we entered was admin.
And finaly checking if the player is not connected.
pawn Код:
else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid,COLOR_WHITE,"Error: Player is not connected!");
Now we just put them into our code.
pawn Код:
CMD:kick(playerid, params[])
{
new id, reason[128];
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_WHITE, "You need to be a admin to use that command!");
else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
else if(id==playerid)SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick yourself!");
else if(id==IsPlayerAdmin(id))SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick another admin!");
else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid,COLOR_WHITE,"Error: Player is not connected!");
At long last we can make the thing what kicks them!
pawn Код:
else {
new Name[MAX_PLAYER_NAME], KickMessage[128];
new Name2[MAX_PLAYER_NAME];
We add this to the bottom of the code.
We create new variables to store the names in, and the KickMessage.
Next we need to get the names. The kicking admins name, and the person who was kicked name. We do this with GetPlayerName.
pawn Код:
else {
new Name[MAX_PLAYER_NAME], KickMessage[128];
new Name2[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
GetPlayerName(id, Name2, sizeof(Name2));
So, we getting the players name, we do this by getting the ID of the player, we get the kickers name with "playerid" he used the command so he must be the person who kicks. And were getting the person who is being kicked, the ID we typed in.
We now make the kick message.
pawn Код:
format(KickMessage, sizeof(KickMessage), "%s(%d) has kicked player %s(%d). Reason: %s", Name, playerid, Name2, id);
It is basically formating a string, but we just renamed the string to KickMessage.
Next thing to do is Send the message to all players, and kick the player.
pawn Код:
SendClientMessageToAll(COLOR_WHITE, KickMessage);
Kick(id);
So, here is the final product.
pawn Код:
CMD:kick(playerid, params[])
{
new id, reason[128];
if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid, COLOR_WHITE, "You need to be a admin to use that command!");
else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
else if(id==playerid)SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick yourself!");
else if(IsPlayerAdmin(id))SendClientMessage(playerid,COLOR_WHITE,"Error: You can not kick another admin!");
else if (id==INVALID_PLAYER_ID)SendClientMessage(playerid,COLOR_WHITE,"Error: Player is not connected!");
else {
new Name[MAX_PLAYER_NAME], KickMessage[128];
new Name2[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
GetPlayerName(id, Name2, sizeof(Name2));
format(KickMessage, sizeof(KickMessage), "%s(%d) has kicked player %s(%d). Reason: %s", Name, playerid, Name2, id);
SendClientMessageToAll(COLOR_WHITE, KickMessage);
Kick(id);
}
return 1;
}
Now you can make your own commands!
Ban - with Ban();
Freeze - With TogglePlayerControlable
Get and Goto - with GetPlayerPos and SetPlayerPos
And many more!
I hope I did my best as it is my first tutorial.
-TechKid100
Re: How to make simple admin commands using sscanf and ZCMD. -
Lorenc_ - 29.07.2011
pawn Код:
else if(sscanf(params, "us(No Reason)[128]", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
If you're using sscanf2 then it shall be like that ^
Nice tutorial anyway.
Re: How to make simple admin commands using sscanf and ZCMD. -
GangsTa_ - 29.07.2011
Good job, at least something new.
Re: How to make simple admin commands using sscanf and ZCMD. -
Odyssey - 29.07.2011
Quote:
Originally Posted by Lorenc_
Nice tutorial anyway.
|
Thanks :P. To prevent myself looking like a real dick I even tested that /lol command. :P
Quote:
Originally Posted by GangsTa_
Good job, at least something new.
|
Thank You, yeh, you are right, I havent seen many detailed tutorials on how to make admin commands with sscanf.
Re: How to make simple admin commands using sscanf and ZCMD. -
HyperZ - 29.07.2011
Quote:
Originally Posted by Lorenc_
pawn Код:
else if(sscanf(params, "us(No Reason)[128]", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
If you're using sscanf2 then it shall be like that ^
Nice tutorial anyway.
|
It should be:
pawn Код:
if(sscanf(params, "uS(No Reason)[128]", id, reason))
S(string)[length] Optional string.
Nice tut btw.
Re: How to make simple admin commands using sscanf and ZCMD. -
System64 - 29.07.2011
wrong
pawn Код:
else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
u is just for id, you need r for name and id
and you need s[size], the beast s[128], othervise it won't send whole message
anyway nice tutorial
Re: How to make simple admin commands using sscanf and ZCMD. -
Lorenc_ - 30.07.2011
Quote:
Originally Posted by System64
wrong
pawn Код:
else if(sscanf(params, "us", id, reason))SendClientMessage(playerid, COLOR_WHITE, "Usage: /kick [id/name][reason]");
u is just for id, you need r for name and id
and you need s[size], the beast s[128], othervise it won't send whole message
anyway nice tutorial
|
u = player; s = string (text); S(Text) = String with text input already...
Neither are you making any sense...
Re: How to make simple admin commands using sscanf and ZCMD. - Max_Coldheart - 30.07.2011
It's not good to make tutorials with bad indentation.
You should fix the indentation of your tutorial.
Else, Good one.
Re: How to make simple admin commands using sscanf and ZCMD. -
Odyssey - 30.07.2011
I tried to fix the indentation, but it wouldnt work.
Re: How to make simple admin commands using sscanf and ZCMD. -
Alexy_Dramon - 10.03.2012
huh i'm Getting 5 errors can you Tell me how Fix it Thanks
the Is my ScreenShot Of the ERROR
http://i.imgur.com/Rh1j1.jpg
(Sorry for my bad english)
Re: How to make simple admin commands using sscanf and ZCMD. -
new121 - 11.03.2012
format(KickMessage, sizeof(KickMessage), "%s(%d) has kicked player %s(%d). Reason: %s", Name, playerid, Name2, id);
should be
format(KickMessage, sizeof(KickMessage), "%s(%d) has kicked player %s(%d). Reason: %s", Name, playerid, Name2, id, reason);
Re: How to make simple admin commands using sscanf and ZCMD. -
RieTzz - 24.05.2012
Im getting these.
Code:
C:\Users\Rietz\Desktop\SAMP\gamemodes\hora.pwn(180) : error 029: invalid expression, assumed zero
C:\Users\Rietz\Desktop\SAMP\gamemodes\hora.pwn(180) : error 017: undefined symbol "cmd_kick"
C:\Users\Rietz\Desktop\SAMP\gamemodes\hora.pwn(180) : error 029: invalid expression, assumed zero
C:\Users\Rietz\Desktop\SAMP\gamemodes\hora.pwn(180) : fatal error 107: too many error messages on one line
with the
Code:
CMD:kick(playerid, params[])
code
Help someone?
Re: How to make simple admin commands using sscanf and ZCMD. -
SkL_MD - 24.05.2012
GG,is pretty simple but it works
Re: How to make simple admin commands using sscanf and ZCMD. -
qazwsx - 24.07.2013
Please help, i got error here.
There are no error message when i compile it
But when i test it on Game, and type /kick, it said, Unkown command
Please help
Re: How to make simple admin commands using sscanf and ZCMD. -
Necip - 24.07.2013
You who have errors, be sure that you have ZCMD and sscanf included:
pawn Code:
#include <a_samp>
#include <zcmd>
#include <sscanf> // or #include <sscanf2>
Re: How to make simple admin commands using sscanf and ZCMD. -
qazwsx - 24.07.2013
Btw, i got a question here...
How can i make these commands become true, so when we typed /kick, we can kick player