SA-MP Forums Archive
How do I make something open and close with one command? - 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 do I make something open and close with one command? (/showthread.php?tid=360484)



How do I make something open and close with one command? - Rabbayazza - 17.07.2012

pawn Код:
if(!strcmp(cmdtext, "/open", true))
        {
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
                MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
        }
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
                MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
        }
            return 1;
        }
       
    if(!strcmp(cmdtext, "/close", true))
        {
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117,-1650.09997559,13.80000019))
        {
                MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
        }
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.40002441,-49.90000153,1000.09997559))
        {
                MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
        }
            return 1;
        }
I have this at the moment, but I want it so that one command "/" can open and close the door/gate in question. Help please.


Re: How do I make something open and close with one command? - Ironboy - 17.07.2012

Not tested
pawn Код:
if(!strcmp(cmdtext, "/open", true))
    {
        if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
            MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
            SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
        }
        if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
            MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
        }
        else
        {
        if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117,-1650.09997559,13.80000019))
        {
            MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
            SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
        }
        if(IsPlayerInRangeOfPoint(playerid, 10, 955.40002441,-49.90000153,1000.09997559))
        {
                MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
        }}
        return 1;}



Re: How do I make something open and close with one command? - Sandiel - 17.07.2012

Make a GLOBAL variable, like
pawn Код:
new DoorStatus;
then change the command to check if this global variable equals to 1(door open) or 0 (door closed)
then just set the 1 and 0 to this one command, if you don't get it, I can do it for you.
pawn Код:
public OnGameModeInit()
{
     DoorStatus = 0;    
     return 1;
}
pawn Код:
if(!strcmp(cmdtext, "/door", true))
        {
            if(DoorStatus == 0) // checks if it is CLOSED
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
                MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
        }
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
                MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
        }
             else if(DoorStatus == 1) // checks if the door is OPEN
            {
                  // close it here.
            }
             return 1;
        }
You'll get the idea


Re: How do I make something open and close with one command? - ArmandoRamiraz - 17.07.2012

You could always make it open and close on a timer?


Re: How do I make something open and close with one command? - Rabbayazza - 17.07.2012

pawn Код:
if(!strcmp(cmdtext, "/", true))
        {
            if(GateOpenStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 1410.19995117, -1650.09997559, 13.80000019))
        {
                MoveObject(GateOpen, 1410.09997559, -1650.09997559, 10.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have opened the gate.");
        }
                    else if(GateOpenStatus == 1)
        {
                MoveObject(GateOpen, 1410.19995117, -1650.09997559, 13.80000019, 3);
                SendClientMessage(playerid, 0xEF994300, "You have closed the gate.");
        }
            if(DoorStatus == 0)
            if(IsPlayerInRangeOfPoint(playerid, 10, 955.70001221,-50.70000076,1002.00000000))
        {
                MoveObject(Door, 955.70001221,-50.59999847,998.20001221, 3);
        }
                else if(DoorStatus == 1)
        {
                MoveObject(Door, 955.70001221,-50.70000076,1002.00000000, 3);
        }
            return 1;
        }
How do I make it so that when I open the door, it changes the Door/GateOpenStatus to 1?