SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/04/2012, 05:38 AM   #1
alking282
Big Clucker
 
Join Date: Aug 2011
Posts: 101
Reputation: 1
Default how i can add command /duty for admin only

how i can add command /duty for admin only pls help iam two day sreach for it
alking282 is offline   Reply With Quote
Old 14/04/2012, 05:44 AM   #2
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,076
Reputation: 406
Default Re: how i can add command /duty for admin only

Examples:
http://forum.sa-mp.com/showthread.php?t=311523
http://forum.sa-mp.com/showthread.php?t=290792
http://forum.sa-mp.com/showthread.php?t=300170

LuxAdmin has a duty system: http://forum.sa-mp.com/showthread.php?t=120724
__________________
People seem to enjoy negitive repping me for topics that I made in 2009.
Therefore, if you want to view my releases, you can go here.

Skype: TheKiller@dr.com
I do NOT script for cash. Add me on MSN if you need help with small issues.
[HiC]TheKiller is offline   Reply With Quote
Old 14/04/2012, 06:38 AM   #3
alking282
Big Clucker
 
Join Date: Aug 2011
Posts: 101
Reputation: 1
Default Re: how i can add command /duty for admin only

he get me error if add it pls can one this command and picture how i add it and i will comment it i need it today pls fast
alking282 is offline   Reply With Quote
Old 14/04/2012, 06:45 AM   #4
Phyrunx
Big Clucker
 
Phyrunx's Avatar
 
Join Date: Apr 2012
Location: Locating....
Posts: 112
Reputation: 12
Default Re: how i can add command /duty for admin only

pawn Code:
new bool:IsOnAdminDuty[MAX_PLAYERS] = false;
CMD:aduty(playerid,params[]) // Onduty
{
    if(!IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid,-1,"You are not authorised to use that command.");
        return 1;
    }
    if(IsOnAdminDuty[playerid] == false)
    {
        IsOnAdminDuty[playerid] = true;
        new pname[24],dstring[124];
        GetPlayerName(playerid,pname,sizeof(pname));
        format(dstring,sizeof(dstring),"Administrator %s is now on duty.",pname);
        SendClientMessageToAll(-1,dstring);
        SetPlayerHealth(playerid,99999);
        SetPlayerArmour(playerid,99999);
        SetPlayerSkin(playerid,271);
    }
    return 1;
}
CMD:aoffduty(playerid,params[]) // Off duty
{
    if(!IsPlayerAdmin(playerid))
    {
        SendClientMessage(playerid,-1,"You are not authorised to use that command.");
        return 1;
    }
    if(IsOnAdminDuty[playerid] == true)
    {
        IsOnAdminDuty[playerid] = false;
        new name[24],ostring[124];
        GetPlayerName(playerid,name,sizeof(name));
        format(ostring,sizeof(ostring),"Administrator %s is now off duty.",name);
        SendClientMessageToAll(-1,ostring);
        SetPlayerHealth(playerid,100);
        SetPlayerArmour(playerid,0);
    }
    return 1;
}
CMD:admins(playerid,params[]) // Admins command
{
    SendClientMessage(playerid,-1,"----Current on duty Administrators----");
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if(IsOnAdminDuty[i] == true)
        {
            new aname[24],astring[124];
            GetPlayerName(playerid,aname,sizeof(aname));
            format(astring,sizeof(astring),"%s",aname);
            SendClientMessage(playerid,-1,astring);
         }
    }
    return 1;
}

code isnt mine i Just Copied It from Walsh
credit goes to Walsh
__________________
łŦ ł HΛVΞ ΞVΞЯ HΞŁPΞđ ЏФU PŁΞΛSΞ ϾŁłϾК ФЛ ТHłS


Phyrunx is offline   Reply With Quote
Old 14/04/2012, 06:53 AM   #5
alking282
Big Clucker
 
Join Date: Aug 2011
Posts: 101
Reputation: 1
Default Re: how i can add command /duty for admin only

man how i step it
alking282 is offline   Reply With Quote
Old 14/04/2012, 07:03 AM   #6
Phyrunx
Big Clucker
 
Phyrunx's Avatar
 
Join Date: Apr 2012
Location: Locating....
Posts: 112
Reputation: 12
Default Re: how i can add command /duty for admin only

step? it? ;o
i cannot understand you? what are you trying to say?
please improve your english
__________________
łŦ ł HΛVΞ ΞVΞЯ HΞŁPΞđ ЏФU PŁΞΛSΞ ϾŁłϾК ФЛ ТHłS


Phyrunx is offline   Reply With Quote
Old 14/04/2012, 07:10 AM   #7
alking282
Big Clucker
 
Join Date: Aug 2011
Posts: 101
Reputation: 1
Default Re: how i can add command /duty for admin only

how i can add this command to my server
alking282 is offline   Reply With Quote
Old 14/04/2012, 07:35 AM   #8
Cjgogo
High-roller
 
Cjgogo's Avatar
 
Join Date: Apr 2011
Location: Romania,Brasov,Brasov
Posts: 1,024
Reputation: 86
Default Re: how i can add command /duty for admin only

Alking in the early years of computers advanced science there was something called copy paste,wih during time evoluated really much,AND it allows you to ADD THE command to your server.
__________________
{POWER} + {AGILITY} + {WILL} + {NOBILITY} = "PAWN"


"A question is the key to knoweldege"

My work


Cjgogo is offline   Reply With Quote
Old 14/04/2012, 07:48 AM   #9
alking282
Big Clucker
 
Join Date: Aug 2011
Posts: 101
Reputation: 1
Default Re: how i can add command /duty for admin only

iam add it and start game and i type /aduty he not work why
alking282 is offline   Reply With Quote
Old 14/04/2012, 08:20 AM   #10
Hawkseye
Little Clucker
 
Hawkseye's Avatar
 
Join Date: May 2010
Location: On your fence-post
Posts: 20
Reputation: 0
Default Re: how i can add command /duty for admin only

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:
pawn Code:
new AdminDutyStatus;

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 Code:
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 Code:
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 Code:
AdminDutyStatus(playerid) = 0;
The varriable which is assigned to playerid (The player quitting) equals (which sets the variable to 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 Code:
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 Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

The line:
pawn Code:
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 Code:
{
        // 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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
{
    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.
Hawkseye is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Admin Duty Command State_Trooper Scripting Help 7 06/03/2014 05:17 AM
[HelpPls] iam need make command for admin name /duty alking282 Scripting Help 4 13/04/2012 10:19 PM
Admin Duty help SpiderWalk Help Archive 3 04/04/2011 02:14 AM
Admin On Duty command help darkknight123 Help Archive 2 12/01/2011 03:59 PM


All times are GMT. The time now is 12:33 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.