SA-MP Forums Archive
Gate only opens for one player - 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: Gate only opens for one player (/showthread.php?tid=550908)



Gate only opens for one player - FunnyBear - 15.12.2014

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


Re: Gate only opens for one player - PinkFloydLover - 15.12.2014

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


Re: Gate only opens for one player - FunnyBear - 15.12.2014

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);



Re: Gate only opens for one player - Raweresh - 15.12.2014

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]);



Re: Gate only opens for one player - FunnyBear - 15.12.2014

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