SA-MP Forums Archive
How to make when player type command one time to enable, second time to disable ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make when player type command one time to enable, second time to disable ? (/showthread.php?tid=461910)



How to make when player type command one time to enable, second time to disable ? - bustern - 04.09.2013

I want when player type /duty ,to go on duty and when type /duty again to go off duty..Is there a way to do that ?


Re: How to make when player type command one time to enable, second time to disable ? - QatarKnight - 04.09.2013

Quote:
Originally Posted by bustern
View Post
I want when player type /duty ,to go on duty and when type /duty again to go off duty..Is there a way to do that ?
You can use "if" statements and set 1 to enable and 0 to disable if the variable is 1 it would set it to 0 and disable it. If it's 0 it would set it to 1 and enable it.


Re: How to make when player type command one time to enable, second time to disable ? - Tamer - 04.09.2013

It's for ZCMD, I don't know what command processor you are using, but here's the main idea.

pawn Code:
new Enabled[MAX_PLAYERS];

CMD:duty(playerid,params[])
{
    if(Enabled[playerid] == 0)
    {
    Enabled[playerid] = 1;
    SendClientMessage(playerid,-1,"You are on duty now!");
    // rest of the code
    return 0; // return 0, so the code will ignore the other lines, allowing you to go on duty.
    }
    if(Enabled[playerid] == 1)
    {
    Enabled[playerid] = 0;
    SendClientMessage(playerid,-1,"You are now off duty!");
    //rest of code
    }
    return 1;
}



Re: How to make when player type command one time to enable, second time to disable ? - QatarKnight - 04.09.2013

Quote:
Originally Posted by bustern
View Post
I want when player type /duty ,to go on duty and when type /duty again to go off duty..Is there a way to do that ?
You can do it like this btw don't copy my example command it's just an example.
At the top of your script:
Code:
new AdminDuty[MAX_PLAYERS];
Example Command:
Code:
CMD:duty(playerid, params[])
{
	if(AdminDuty[playerid] == 0)
	{
             //whatever you want it to do when enabled
             AdminDuty[playerid] = 1;
	}
	else if(AdminDuty[playerid] == 1)
	{
              //whatever you want it to do when disabled
              AdminDuty[playerid] = 0;
	}
	return 1;
}