[Tutorial] How to make the "/adminduty" command.
#1

Welcome to my first tutorial!

In this tutorial, I am going to show you how to make the "/adminduty" command,
it is very easy, hope you will enjoy.


For this you are gonna need to define some colors, and you are gonna need the sscanf and Y_INI plugins. You can easily find that here on the forum.

It's going to look something like this:
https://prnt.sc/fyzflr

So let's begin.

For this you are going to need this Login/Register system, which includes an admin system that we are gonna use: https://sampforum.blast.hk/showthread.php?tid=273088

Now when you have that, let's begin.

First at the top of our script we add:
Code:
new AdminDuty[MAX_PLAYERS];
When that's done, we are going to start making the actual command.
We go to the bottom of the script, or wherever are your commands are, and type:
Code:
YCMD:adminduty(playerid, params[], help)
{
	if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, RED, "You don't have the right to use this 
        command.");
NOTE:You don't have to type YCMD:adminduty, you can type whatever you want the command to be,
like YCMD:aduty or whatever
That is going to check is the player that's typing the command an admin.
If he's not, it's going to send him the message saying that he doesn't have the right to use that command.
Now this part is all about formatting, I won't explain that to you, you have plenty of tutorials about that, I'm just going to add the code:
Code:
	new string[256], name1[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name1, sizeof(name1));
	if(AdminDuty[playerid] == 0)
	{
	    format(string, sizeof(string), "Admin {FF0000}%s {FFFFFF} is on the duty, for help type 
            /help", name1);
	    SCMTA(-1, string);
	    AdminDuty[playerid] = 1;
            SetPlayerArmour(playerid, 100);
	    SetPlayerColor(playerid, GREEN);
	    SetPlayerSkin(playerid, 294);
          }
So basically this checks is player already on admin duty, if not, it's gonna send a message to everyone on the server saying that he is now on duty.
And it's also gonna set his skin to 294 and set his name color to green.
If you know at least a little bit about formatting you can edit this.
Let's move on.

Code:
	else if(AdminDuty[playerid] == 1)
        {
		SetPlayerHealth(playerid, 0);
		SetPlayerColor(playerid, -1);
		SetPlayerSkin(playerid, 1);
		format(string, sizeof(string), "Admin {FF0000}%s {FFFFFF}is no longer on duty.", name1);
		SCMTA(-1, string);
		AdminDuty[playerid] = 0;
	}
	return 1;
}
Now, this is just reversed, if the player is on duty, it's gonna kill him, set his name color to white, set his skin to default, and tell everyone that he is no longer on duty.

That was my first tutorial, it might be a bit confusing, but it's actually not.
If you have any problems, just send me a message! If I helped you +rep me. Thank you!
Reply
#2

Why did you use a string this large? string[256]
take a moment and review this


Source: https://sampwiki.blast.hk/wiki/Limits
Reply
#3

Please don't share you personal information on these forums.
Reply
#4

Or,

Code:
bool:Admin_duty[MAX_PLAYERS char] = false;
And in the command :

Code:
switch(Admin_duty{playerid})
{
     case false:
     {
	  Admin_duty{playerid} = true;
     }
     case true:
     {
         Admin_duty{playerid} = false;
     }
}
Reply
#5

Quote:
Originally Posted by Henson
View Post
Or,

And in the command :

Code:
switch(Admin_duty{playerid})
{
     case false:
     {
	  Admin_duty{playerid} = true;
     }
     case true:
     {
         Admin_duty{playerid} = false;
     }
}
Admin_duty{playerid} = !Admin_duty{playerid};
Reply
#6

Even you guys we're not proffessional coders in past, he is a beginner and any assistance he receive from you will be good for himself in future! 1 star
Reply
#7

Quote:
Originally Posted by Bolex_
View Post
Even you guys we're not proffessional coders in past, he is a beginner and any assistance he receive from you will be good for himself in future! 1 star
For the same reason he should focus on learning instead of trying to teach others something he doesn't know.
Reply
#8

Quote:
Originally Posted by AmarPlayer
View Post
Now, this is just reversed, if the player is on duty, it's gonna kill him, set his name color to white, set his skin to default, and tell everyone that he is no longer on duty.
You shuold store his health, color and skin in a variable and restore these things when off duty.
Reply
#9

I think he can submit his code, but you can help him in his learning, no ? He is happy & proud of him, can you encourage him ?

&

Quote:
Originally Posted by SyS
View Post
Admin_duty{playerid} = !Admin_duty{playerid};
My command is functional without "!" because I define case true & case false, so "if it's false" == "set true".
Reply
#10

Quote:
Originally Posted by Henson
View Post
My command is functional without "!" because I define case true & case false, so "if it's false" == "set true".
SyS was not pointing to non functionality but your optimization.Op's code in toggling will also work without bool values.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)