PLA_Tolls.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // This file holds all functions for the toll-system
  2. #define MAX_TOLLGATES (10)
  3. #define TXT_PlayerPaysToll "~r~You paid $%i for the toll"
  4. #define TXT_GovtPaysToll "~g~The government has paid\nfor your toll fee"
  5. enum TTollGate
  6. {
  7. GateID, // Holds the object-id of the gate
  8. TollPrice, // Holds the price for passing the gate
  9. GateStatus, // Holds the status of the gate (open = 1, closed = 0)
  10. Float:OpenX, // Holds the coordinates when the gate is opened
  11. Float:OpenY, // Holds the coordinates when the gate is opened
  12. Float:OpenZ, // Holds the coordinates when the gate is opened
  13. Float:CloseX, // Holds the coordinates when the gate is closed
  14. Float:CloseY, // Holds the coordinates when the gate is closed
  15. Float:CloseZ // Holds the coordinates when the gate is closed
  16. }
  17. new ATollGates[MAX_TOLLGATES][TTollGate];
  18. AddTollGate(GateModel, Float:OX, Float:OY, Float:OZ, Float:CX, Float:CY, Float:CZ, Float:RX, Float:RY, Float:RZ, TollMoney)
  19. {
  20. // Loop through all tollgates
  21. for (new TollGate; TollGate < MAX_TOLLGATES; TollGate++)
  22. {
  23. // Check if this is an empty entry
  24. if (ATollGates[TollGate][GateID] == 0)
  25. {
  26. // Create a new object for the toll-gate in it's closed status
  27. ATollGates[TollGate][GateID] = CreateObject(GateModel, CX, CY, CZ, RX, RY, RZ);
  28. // Set data
  29. ATollGates[TollGate][TollPrice] = TollMoney; // Set the price to pay for passing the toll-gate
  30. ATollGates[TollGate][GateStatus] = 0; // Set the status to CLOSED
  31. ATollGates[TollGate][OpenX] = OX; // Save the OpenX coordinates
  32. ATollGates[TollGate][OpenY] = OY; // Save the OpenY coordinates
  33. ATollGates[TollGate][OpenZ] = OZ; // Save the OpenZ coordinates
  34. ATollGates[TollGate][CloseX] = CX; // Save the CloseX coordinates
  35. ATollGates[TollGate][CloseY] = CY; // Save the CloseY coordinates
  36. ATollGates[TollGate][CloseZ] = CZ; // Save the CloseZ coordinates
  37. break; // Stop the for-loop
  38. }
  39. }
  40. }
  41. forward Toll();
  42. public Toll()
  43. {
  44. // Loop through all players
  45. for(new playerid; playerid < MAX_PLAYERS; playerid++)
  46. {
  47. // Check if the player is the driver of a vehicle
  48. if (GetPlayerVehicleSeat(playerid) == 0)
  49. {
  50. // Loop through all toll-gates
  51. for (new TollGate; TollGate < MAX_TOLLGATES; TollGate++)
  52. {
  53. // Check if this toll-gate exists
  54. if (ATollGates[TollGate][GateID] != 0)
  55. {
  56. // Check if the player is in range of the tollgate
  57. if(IsPlayerInRangeOfPoint(playerid, 7.5, ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ]) && !IsAGovernmentFaction(playerid))
  58. {
  59. // Check if the toll-gate is closed
  60. if(ATollGates[TollGate][GateStatus] == 0)
  61. {
  62. // Open the gate
  63. MoveObject(ATollGates[TollGate][GateID], ATollGates[TollGate][OpenX], ATollGates[TollGate][OpenY], ATollGates[TollGate][OpenZ], 3.0);
  64. // Set status to OPEN
  65. ATollGates[TollGate][GateStatus] = 1;
  66. // Let the player pay the toll
  67. GivePlayerCash(playerid, -ATollGates[TollGate][TollPrice]);
  68. new string[50];
  69. format(string, sizeof(string), TXT_PlayerPaysToll, ATollGates[TollGate][TollPrice]);
  70. GameTextForPlayer(playerid, string, 3000, 4);
  71. // Start a timer that closes the gate after 5 seconds
  72. SetTimerEx("CloseGate", 5000, false, "i", TollGate);
  73. }
  74. }
  75. else
  76. if(IsPlayerInRangeOfPoint(playerid, 7.5, ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ]) && IsAGovernmentFaction(playerid))
  77. {
  78. // Check if the toll-gate is closed
  79. if(ATollGates[TollGate][GateStatus] == 0)
  80. {
  81. // Open the gate
  82. MoveObject(ATollGates[TollGate][GateID], ATollGates[TollGate][OpenX], ATollGates[TollGate][OpenY], ATollGates[TollGate][OpenZ], 3.0);
  83. // Set status to OPEN
  84. ATollGates[TollGate][GateStatus] = 1;
  85. new string[50];
  86. format(string, sizeof(string), TXT_GovtPaysToll, ATollGates[TollGate][TollPrice]);
  87. GameTextForPlayer(playerid, string, 3000, 4);
  88. // Start a timer that closes the gate after 5 seconds
  89. SetTimerEx("CloseGate", 5000, false, "i", TollGate);
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. forward CloseGate(TollGate);
  98. public CloseGate(TollGate)
  99. {
  100. // Close the gate
  101. MoveObject(ATollGates[TollGate][GateID], ATollGates[TollGate][CloseX], ATollGates[TollGate][CloseY], ATollGates[TollGate][CloseZ], 3.0);
  102. // Set status to CLOSED
  103. ATollGates[TollGate][GateStatus] = 0;
  104. }