Skip to content

Instantly share code, notes, and snippets.

@CodeAlDente
Created January 14, 2018 20:18
Show Gist options
  • Save CodeAlDente/650ee04b0127514032fcec369f91a8a6 to your computer and use it in GitHub Desktop.
Save CodeAlDente/650ee04b0127514032fcec369f91a8a6 to your computer and use it in GitHub Desktop.
PPC Trucking - Close toll gate if player is no longer in range
// This file holds all functions for the toll-system
forward Toll();
public Toll()
{
// Loop through all players
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
// If the player isn't connected, skip to the next player
if(APlayerData[playerid][LoggedIn] == false) continue;
// Check if the player is the driver of a vehicle
if (GetPlayerVehicleSeat(playerid) == 0)
{
// Loop through all toll-gates
for (new TollGate; TollGate < MAX_TOLLGATES; TollGate++)
{
// Check if this toll-gate exists
if (ATollGates[TollGate][GateID] != 0)
{
// Check if the player is in range of the tollgate
if(IsPlayerInRangeOfPoint(playerid, 7.5, ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ]))
{
// Check if the toll-gate is closed
if(ATollGates[TollGate][GateStatus] == 0)
{
// Open the gate
MoveObject(ATollGates[TollGate][GateID], ATollGates[TollGate][OpenX], ATollGates[TollGate][OpenY], ATollGates[TollGate][OpenZ], 3.0);
// Set status to OPEN
ATollGates[TollGate][GateStatus] = 1;
// Let the player pay the toll
RewardPlayer(playerid, -ATollGates[TollGate][TollPrice], 0);
new string[50], GateTimer;
format(string, sizeof(string), TXT_PlayerPaysToll, ATollGates[TollGate][TollPrice]);
GameTextForPlayer(playerid, string, 3000, 4);
// Start a timer that closes the gate after 5 seconds
GateTimer = SetTimerEx("CloseGate", 5000, true, "iii", TollGate, playerid, GateTimer);
}
}
}
}
}
}
}
forward CloseGate(TollGate, playerid, GateTimer);
public CloseGate(TollGate, playerid, GateTimer)
{
if (!IsPlayerInRangeOfPoint(playerid, 7.5, ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ])) {
// Close the gate
MoveObject(ATollGates[TollGate][GateID], ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ], 3.0);
// Set status to CLOSED
ATollGates[TollGate][GateStatus] = 0;
KillTimer(GateTimer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment