Gate only opens for one player
#1

Hey,

I have a problem with my Gate for my Swat Base. The gate opens fine automatically, but it only opens the gate for one player in the Swat team. And that player is usually the first to spawn as a swat player.

So instead of opening it for any Swat Player that goes nearby, it only opens for one of the swat player.

pawn Код:
forward GateCheck( playerid );
public GateCheck( playerid )
{
    if ( gTeam[ playerid ] == TEAM_SWAT )
    {
        if(IsPlayerInRangeOfPoint(playerid, 22.0, 1415.0000000, -1649.9000244, 16.2999992))
        {
            if(SwatOpen == false)
            {
                MoveDynamicObject(SwatGate, 1415.0999756, -1639.5000000, 16.2999992, 2.3);
                SwatOpen = true;
            }
            return;
        }
    }
    if(SwatOpen == true)
    {
        MoveDynamicObject(SwatGate, 1415.0000000, -1649.9000244, 16.2999992, 2.3); // Change the '8.0, 3.0, 10.0' to the coordinates of your gate when it's closed.    gateopen = false; //This indicates the gate is closed again. Or at least, closing.
        SwatOpen = false;
    }
}
Thanks,

FunnyBear
Reply
#2

The problem is most likely the place that you called that function from, if the playerid value hasn't been set it will return 0 by default and will mean it will only work for playerid 0
Reply
#3

Quote:
Originally Posted by PinkFloydLover
Посмотреть сообщение
The problem is most likely the place that you called that function from, if the playerid value hasn't been set it will return 0 by default and will mean it will only work for playerid 0
I've got this under OnGameModeInit,

pawn Код:
SetTimer("GateCheck", 600, true);
Reply
#4

Loop that code or change SetTimer("GateCheck", 600, true); to SetTimerEx("GateCheck", 600 , true, "i", playerid); and put it in OnPlayerConnect, and ofc delete it from OnGameModeInit. But for more optimalization do like this:
Global variable:
Код:
new pGateCheck[MAX_PLAYERS];
OnPlayerConnect:
Код:
pGateCheck[playerid] = SetTimerEx("GateCheck", 600 , true, "i", playerid);
OnPlayerDisconnect:
Код:
KillTimer(pGateCheck[playerid]);
Reply
#5

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
Loop that code or change SetTimer("GateCheck", 600, true); to SetTimerEx("GateCheck", 600 , true, "i", playerid); and put it in OnPlayerConnect, and ofc delete it from OnGameModeInit. But for more optimalization do like this:
Global variable:
Код:
new pGateCheck[MAX_PLAYERS];
OnPlayerConnect:
Код:
pGateCheck[playerid] = SetTimerEx("GateCheck", 600 , true, "i", playerid);
OnPlayerDisconnect:
Код:
KillTimer(pGateCheck[playerid]);
EDIT: I just tried it, and it doesn't work. It just keeps opening and closing it doesn't open fully
Reply


Forum Jump:


Users browsing this thread: