Openbay(gate) 2 commands into 1
#1

I've got two commands, one to open the bay (openbay) and one to close 'm (closebay)
How would I go about merging these two commands into one?
Thanks in advance.

PHP код:
CMD:openbay(playerid,params[])
{
        if((
PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3))
        return 
SCM(playeridCOLOR_LIGHTRED"You're not a Faction member.");
        if(
IsPlayerInRangeOfPoint(playerid8.0,-2534.179442347.453615.94538))
        {
             
MoveObject(fdgate1,-2534.17942348.41367.8590,0.50,0.0000090.000090.0000);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2526.271732347.453615.94540))
        {
            
MoveObject(fdgate2,-2526.27172348.41367.8590,0.50,09090);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2518.360842347.453615.94540))
        {
            
MoveObject(fdgate3,-2518.36082348.41367.8590,0.50,09090);
        }
        return 
1;

PHP код:
CMD:closebay(playerid,params[])
{
        if((
PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3))
        return 
SCM(playeridCOLOR_LIGHTRED"You're not a Faction member.");
        if(
IsPlayerInRangeOfPoint(playerid8.0,-2534.179442347.453615.94538))
        {
             
MoveObject(fdgate1,-2534.179442347.453615.94538,0.50,0.000000.000090.0000);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2526.271732347.453615.94540))
        {
            
MoveObject(fdgate2,-2526.271732347.453615.94540,0.50,0090);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2518.360842347.453615.94540))
        {
            
MoveObject(fdgate3,-2518.360842347.453615.94540,0.50,0090);
        }
        return 
1;

Reply
#2

With something like:
PHP код:
CMD:bay(playerid,params[])
{
if((
PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3))
return 
SCM(playeridCOLOR_LIGHTRED"You're not a Faction member.");
if(!
strcmp(params,"open",true)) //the true means that OpEn will be the same with OPEn etc. (ignore uppercase:true)
{
        if(
IsPlayerInRangeOfPoint(playerid8.0,-2534.179442347.453615.94538))
        {
             
MoveObject(fdgate1,-2534.17942348.41367.8590,0.50,0.0000090.000090.0000);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2526.271732347.453615.94540))
        {
            
MoveObject(fdgate2,-2526.27172348.41367.8590,0.50,09090);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2518.360842347.453615.94540))
        {
            
MoveObject(fdgate3,-2518.36082348.41367.8590,0.50,09090);
        }
        return 
1
}
else if(!
strcmp(params,"close",true))
{
        if(
IsPlayerInRangeOfPoint(playerid8.0,-2534.179442347.453615.94538))
        {
             
MoveObject(fdgate1,-2534.179442347.453615.94538,0.50,0.000000.000090.0000);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2526.271732347.453615.94540))
        {
            
MoveObject(fdgate2,-2526.271732347.453615.94540,0.50,0090);
        }
        else if(
IsPlayerInRangeOfPoint(playerid7.0,-2518.360842347.453615.94540))
        {
            
MoveObject(fdgate3,-2518.360842347.453615.94540,0.50,0090);
        }
        return 
1
}
else return 
SCM(playerid,-1,"Use the command /bay like: /bay open or /bay close");

PS: Sorry for the identation.
Reply
#3

Simple but there are many ways but this is one way, use sscanf of ******

Код:
CMD:bay(playerid,params[]) 
{ 
    if((PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3)) 
    	return SCM(playerid, COLOR_LIGHTRED, "You're not a Faction member."); 
    new szType[5];
    if(sscanf(params, "s[5]", szType)) return SCM(playerid, -1, "USAGE: /bay [open/close]");
    if(strcmp(szType, "open", true) == 0)
    {

        if(IsPlayerInRangeOfPoint(playerid, 8.0,-2534.17944, 2347.45361, 5.94538)) 
        	MoveObject(fdgate1,-2534.1794, 2348.4136, 7.8590,0.50,0.00000, 90.0000, 90.0000); 
   
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2526.27173, 2347.45361, 5.94540)) 
        	MoveObject(fdgate2,-2526.2717, 2348.4136, 7.8590,0.50,0, 90, 90); 
        
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2518.36084, 2347.45361, 5.94540)) 
        	MoveObject(fdgate3,-2518.3608, 2348.4136, 7.8590,0.50,0, 90, 90); 
        
    }
    else if(strcmp(szType, "close", true) == 0)
    {
    	if(IsPlayerInRangeOfPoint(playerid, 8.0,-2534.17944, 2347.45361, 5.94538)) 
    		MoveObject(fdgate1,-2534.17944, 2347.45361, 5.94538,0.50,0.00000, 0.0000, 90.0000); 
        
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2526.27173, 2347.45361, 5.94540)) 
        	MoveObject(fdgate2,-2526.27173, 2347.45361, 5.94540,0.50,0, 0, 90); 
         
        else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2518.36084, 2347.45361, 5.94540)) 
        	MoveObject(fdgate3,-2518.36084, 2347.45361, 5.94540,0.50,0, 0, 90); 
        
    }
    else SCM(playerid, -1, "Invalid Choice!");
    return 1; 
}
@EDIT: use ^ much simplier lol.
Reply
#4

Thanks guys this'll work.
However is there also a way to make it like this:
/bay
>When the bay is closed it opens
/bay
>When the bay is open it closes
Reply
#5

first you must define iif gate is open or close
fdgate1 < dis one make another global variable fdgatestatus. much better if enum I guess?

after that if fdgatestatus= 0 > meaning it's close
if(!fdgatestatus)
{
// open the gate
fdgatestatus = 1; //set it to open
}
else
{
//close the gate
fdgatestatus = 0; // set it to close
}
Reply
#6

Quote:
Originally Posted by ToiletDuck
Посмотреть сообщение
first you must define iif gate is open or close
fdgate1 < dis one make another global variable fdgatestatus. much better if enum I guess?

after that if fdgatestatus= 0 > meaning it's close
if(!fdgatestatus)
{
// open the gate
fdgatestatus = 1; //set it to open
}
else
{
//close the gate
fdgatestatus = 0; // set it to close
}
I get what you mean but I have no clue on how to execute it. Could you maybe give a example?
Reply
#7

Quote:
Originally Posted by Cubie
Посмотреть сообщение
I get what you mean but I have no clue on how to execute it. Could you maybe give a example?
This below code should give you an idea of how it can be done, keep in mind this is a somewhat basic piece of code for what you're trying to do, there are many optimizations that could be done.

Код:
new fdgate1_status = 0; // 0 = closed, 1 = open
new fdgate2_status = 0; // 0 = closed, 1 = open
new fdgate3_status = 0; // 0 = closed, 1 = open


CMD:bay(playerid,params[])
{
    if((PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3))
    	return SCM(playerid, COLOR_LIGHTRED, "You're not a Faction member.");
	else if(IsPlayerInRangeOfPoint(playerid, 8.0,-2534.17944, 2347.45361, 5.94538)) // fdgate1
	{
	    if(fdgate1_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate1,-2534.1794, 2348.4136, 7.8590,0.50,0.00000, 90.0000, 90.0000);
			fdgate1_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate1,-2534.17944, 2347.45361, 5.94538,0.50,0.00000, 0.0000, 90.0000);
			fdgate1_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2526.27173, 2347.45361, 5.94540)) // fdgate2
	{
	    if(fdgate2_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate2,-2526.2717, 2348.4136, 7.8590,0.50,0, 90, 90);
			fdgate2_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate2,-2526.27173, 2347.45361, 5.94540,0.50,0, 0, 90);
			fdgate2_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2518.36084, 2347.45361, 5.94540)) // fdgate3
	{
	    if(fdgate3_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate3,-2518.3608, 2348.4136, 7.8590,0.50,0, 90, 90);
			fdgate3_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate3,-2518.36084, 2347.45361, 5.94540,0.50,0, 0, 90);
			fdgate3_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else SCM(playerid, -1, "Invalid Choice - you aren't close to any gate!");
	return 1;
}
Reply
#8

Quote:
Originally Posted by MEW273
Посмотреть сообщение
This below code should give you an idea of how it can be done, keep in mind this is a somewhat basic piece of code for what you're trying to do, there are many optimizations that could be done.

Код:
new fdgate1_status = 0; // 0 = closed, 1 = open
new fdgate2_status = 0; // 0 = closed, 1 = open
new fdgate3_status = 0; // 0 = closed, 1 = open


CMD:bay(playerid,params[])
{
    if((PlayerInfo[playerid][pFaction] != 2) && (PlayerInfo[playerid][pFaction] != 3))
    	return SCM(playerid, COLOR_LIGHTRED, "You're not a Faction member.");
	else if(IsPlayerInRangeOfPoint(playerid, 8.0,-2534.17944, 2347.45361, 5.94538)) // fdgate1
	{
	    if(fdgate1_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate1,-2534.1794, 2348.4136, 7.8590,0.50,0.00000, 90.0000, 90.0000);
			fdgate1_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate1,-2534.17944, 2347.45361, 5.94538,0.50,0.00000, 0.0000, 90.0000);
			fdgate1_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2526.27173, 2347.45361, 5.94540)) // fdgate2
	{
	    if(fdgate2_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate2,-2526.2717, 2348.4136, 7.8590,0.50,0, 90, 90);
			fdgate2_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate2,-2526.27173, 2347.45361, 5.94540,0.50,0, 0, 90);
			fdgate2_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else if(IsPlayerInRangeOfPoint(playerid, 7.0,-2518.36084, 2347.45361, 5.94540)) // fdgate3
	{
	    if(fdgate3_status == 0) // gate is closed, so let's open it
	    {
	    	MoveObject(fdgate3,-2518.3608, 2348.4136, 7.8590,0.50,0, 90, 90);
			fdgate3_status = 1; // we just opened the gate so let's update our variable
		}
		else // gate is not closed so it must be open, so let's close it
		{
			MoveObject(fdgate3,-2518.36084, 2347.45361, 5.94540,0.50,0, 0, 90);
			fdgate3_status = 0; // we just closed the gate so let's update our variable
		}
	}
	else SCM(playerid, -1, "Invalid Choice - you aren't close to any gate!");
	return 1;
}
You're amazing. Thanks bud +Rep'd
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)