#1

I want to make like,
If i type the command again,
The gate will close,
For example, I type /gate, (It opens) and then i type /gate again, (it closes).

Код:
COMMAND:gateopen(playerid, params[])
{
    if(PlayerStat[playerid][Dead] == 1 || PlayerStat[playerid][InHospital] == 1) return SendClientMessage(playerid, GREY, "You are unconscious.");
	if(PlayerStat[playerid][FactionID] < 1) return SendClientMessage(playerid, GREY, "You are not a Prison Guard/Doctor.");
	if(IsPlayerInRangeOfPoint(playerid, 5, -21.93213, -338.94623, 7.83163) && gatestatus == 0)
    {
		new str[128];
		gatestatus = 1;
		MoveObject(gate, -21.93213, -338.94623, -4.83163, 1);
		format(str, sizeof(str), "* %s opens the prison gate.", GetICName(playerid));
  		SendNearByMessage(playerid, ACTION_COLOR, str, 3);

	}
	return 1;
}
COMMAND:gateclose(playerid, params[])
{
    if(PlayerStat[playerid][Dead] == 1 || PlayerStat[playerid][InHospital] == 1) return SendClientMessage(playerid, GREY, "You are unconscious.");
	if(PlayerStat[playerid][FactionID] < 1) return SendClientMessage(playerid, GREY, "You are not a Prison Guard/Doctor.");
	if(IsPlayerInRangeOfPoint(playerid, 5, -21.93213, -338.94623, 7.83163) && gatestatus == 1)
    {
		new str[128];
		gatestatus = 0;
		MoveObject(gate, -21.93213, -338.94623, 7.83163, 1);
		format(str, sizeof(str), "* %s closes the prison gate.", GetICName(playerid));
  		SendNearByMessage(playerid, ACTION_COLOR, str, 3);

	}

	return 1;
}
Reply
#2

Make a variable and let it be 0 in default.

For example: new GateOpened = 0; Type the GateOpened up the OnGameModeInit callback.

When you do /gate, it checks if GateOpened is 0, if it is 0 then open the gate and set GateOpened to 1.

Then type "else if(GateOpened == 1)" then close the gate and set GateOpened to 0:
Reply
#3

I don't think i get you,
Can you be more spesific?
Reply
#4

here you go sir you just had to check gatestatus value on the command, for that you can use if or switch

PHP код:
COMMAND:gate(playeridparams[])
{
    if(
PlayerStat[playerid][Dead] == || PlayerStat[playerid][InHospital] == 1) return SendClientMessage(playeridGREY"You are unconscious.");
    if(
PlayerStat[playerid][FactionID] < 1) return SendClientMessage(playeridGREY"You are not a Prison Guard/Doctor.");
    if(
IsPlayerInRangeOfPoint(playerid5, -21.93213, -338.946237.83163))
    {
        switch(
gatestatus)
        {
            case 
0:
            {
                new 
str[128];
                
gatestatus 1;
                
MoveObject(gate, -21.93213, -338.94623, -4.831631);
                
format(strsizeof(str), "* %s opens the prison gate."GetICName(playerid));
                  
SendNearByMessage(playeridACTION_COLORstr3);
            }
            case 
1:
            {
                new 
str[128];
                
gatestatus 0;
                
MoveObject(gate, -21.93213, -338.946237.831631);
                
format(strsizeof(str), "* %s closes the prison gate."GetICName(playerid));
                  
SendNearByMessage(playeridACTION_COLORstr3);
            }
        }
    }
    return 
1;

What is if?
What is switch?
Reply
#5

Thank you so much!
+Rep
Reply
#6

Write this up the OnGameModeInit:
PHP код:
new GateOpened 0
Remove the two commands and add this:

PHP код:
COMMAND:gate(playeridparams[])
{
    if(
PlayerStat[playerid][Dead] == || PlayerStat[playerid][InHospital] == 1) return SendClientMessage(playeridGREY"You are unconscious.");
    if(
PlayerStat[playerid][FactionID] < 1) return SendClientMessage(playeridGREY"You are not a Prison Guard/Doctor.");
if(
GateOpened == 0)
{
             if(
IsPlayerInRangeOfPoint(playerid5, -21.93213, -338.946237.83163) && gatestatus == 0)
                 {
                 new 
str[128];
                 
gatestatus 1;
                 
MoveObject(gate, -21.93213, -338.94623, -4.831631);
                 
format(strsizeof(str), "* %s opens the prison gate."GetICName(playerid));
                  
SendNearByMessage(playeridACTION_COLORstr3);
GateOpened 1;
                }
    }
else if(
GateOpened == 1)

          
// Closing gate functions
GateOpened 0;
}
    return 
1;

Reply
#7

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
Write this up the OnGameModeInit:
PHP код:
new GateOpened 0
Remove the two commands and add this:

PHP код:
COMMAND:gate(playeridparams[])
{
    if(
PlayerStat[playerid][Dead] == || PlayerStat[playerid][InHospital] == 1) return SendClientMessage(playeridGREY"You are unconscious.");
    if(
PlayerStat[playerid][FactionID] < 1) return SendClientMessage(playeridGREY"You are not a Prison Guard/Doctor.");
if(
GateOpened == 0)
{
             if(
IsPlayerInRangeOfPoint(playerid5, -21.93213, -338.946237.83163) && gatestatus == 0)
                 {
                 new 
str[128];
                 
gatestatus 1;
                 
MoveObject(gate, -21.93213, -338.94623, -4.831631);
                 
format(strsizeof(str), "* %s opens the prison gate."GetICName(playerid));
                  
SendNearByMessage(playeridACTION_COLORstr3);
GateOpened 1;
                }
    }
else if(
GateOpened == 1)

          ....
GateOpened 0;
}
    return 
1;

Hey,
Thank you for helping,
jlalt found a solution for me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)