You can always optionally download administrative filter scripts and such, but if you're looking into actually learning to code and branching out on your own - It's best you script it yourself so you know how the script is setup and what you can expect of the results. It'll save you time and possibly the frustration of trying to figure a completely different system out. But don't get me wrong, simply looking at other released gamemodes and experimenting on your own while you're getting started will do you good.
I'd like to note that I only just started scripting a couple months ago, so if I appear to be wrong in some aspect, feel free to correct me as needed.
So to start you off and answer the original question, we're going to create a new variable to store the said admins admin duty status. A variable in this case (Assuming that you're new to Pawn) is going to be a memory 'plot' so-to-speak, as previously mentioned to store the status. That said, we'll want to create this variable above 'OnGameInIt', or if your creating this as a filterscript, 'OnFilterScriptInit'.
To create a new variable, you may use:
However, if you're planning on having anymore than a single administrator, you'll want to create a variable for every possible player who might be an admin. To do this, we'll make use of the "MAX_PLAYERS" tag, which will create a new variable for every player slot your server is set to allow.
To do this, change the previous variable to:
pawn Код:
new AdminDutyStatus[MAX_PLAYERS];
Ok, so now that we've got that covered, we'll need to make sure that when an administrator quits, his player id isn't still set as an admin for when a non-admin joins with the same playerid. To do this, we'll go down to 'OnPlayerDisconnect'..
It should look something similar to this:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
return 1;
}
..and use this to set the variable to 0 (Which will later represent Off-duty, whereas 1 will represent on-duty).
pawn Код:
AdminDutyStatus(playerid) = 0;
The varriable which is assigned to playerid (The player quitting) equals (which sets the variable to
![Smiley](images/smilies/smile.png)
0. We use a semicolon to close variables, meaning we've got nothing else to define/set that variable as. Wonder why there's a 'return 1' inside the brackets? Every time we run a function, you need to return something back to the main callback so it is informed that the command was executed, otherwise the compiler will give you an error message. (I'm not exactly clear on the reasons as of yet to go about preaching in detail. If I should appear wrong, please do correct me.)
You should have something like this.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
AdminDutyStatus(playerid) = 0;
return 1;
}
Alright, so now let's create the command and the result of what this command will be. Right then, let's scroll on down to the callback 'OnPlayerCommandText'. It should look something similar to this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
The line:
pawn Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
will take anything presented as a command starting with a backslash (/), compare the text command and check if it matches with "/mycommand". If it does (true), it'll preform the list of orders given below within the brackets:
pawn Код:
{
// Do something here
return 1;
}
Alright then, let's move on and get you started coding. First thing's first, let's check to see if the player (playerid) already has /aduty enabled or disabled. Based on this result, we can tell the script to do multiple thing's which I'll explain later. For now, we'll do something like we did earlier, setting the AdminDutyStatus variable to 0 on playerdisconnect, only instead this time we'll set the variable to 1, which will represent 'On-duty'.
You should now have something like this:
pawn Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
AdminDutyStatus = 1;
return 1;
}
return 0;
Ok then, let's setup the ability to toggle the status by checking the AdminDutyStatus variable and tell it do do something based on the results. To do this, we'll use an 'if' statement which will check if the variable equals a set paramiter (which in this case is 0). We'll create and set this inside our code and end up with something like this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0) /* <-- Checking IF this variable 'AdminDutyStatus' equals 0. So technically, it's checking if the player is off duty when (s)he types the command.*/
{ /* Since we called a new function "IF", we also create a new set of brackets. Anything done within these brackets will be conditional of the IF statement*/
/* You can place additional admin goodies here, such as enabled god mode, etc. */
return 1; // Returns the result
}
}
return 0;
}
Ok, we're almost done, although not quite. Next, we're going to use an else statement, which will be called if the "IF" statement returns negative. To do this, we'll place it directly under the entire "IF" statement, including it's brackets. If you did it correctly, you should have somethinglike this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
return 1;
}
else
}
return 0;
}
Great, but since we're creating a new statement ('else'), we also need to begin it with a forward bracket. Once you've done that, drop down a line below it, hit your tab key once to indent a new line and set the 'AdminDutyStatus' variable to 0 and place 'return 1;' below it. Then close it with a backwards bracket, making sure it's in allignment with the bracket above it. If you did it correctly, you should now have something like this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
return 1;
}
else
{
AdminDutyStatus = 0;
return 1;
}
}
return 0;
}
Now go back to the top of our command and just above the return 1; inside the empty "IF" statement, set the variable 'AdminDutyStatus' to 1 just as we did below it. Go ahead and change '/MyCommand' in the command check to '/aduty' or whatever it is you prefer. You should have something like this now:
pawn Код:
{
if (strcmp("/Aduty", cmdtext, true, 10) == 0)
{
if(AdminDutyStatus == 0)
{
AdminDutyStatus = 1;
return 1;
}
else
{
AdminDutyStatus = 0;
return 1;
}
}
return 0;
}
You wont be able to see anything in your server, but providing you picked up on some of this, you'll be able to do allot with what you've learned here. Just explore with various functions, such as those in the tree on the right of Pawno and you'll be on your way to having a community of your own in only a little effort away.
Good luck. If you've got any questions or would like to hear more, feel free to send me a forum PM or hit me up on skype/MSN.
MSN:
redgamefreaks_staff@ymail.com
Skype: hawkseye95
ps. Wrote this up @ 3am, expect grammar fails.