SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

404 lines
14 KiB

5 years ago
  1. // -----------------------------------------------------------------------------
  2. // Example Filterscript for the LS Prison Walls and Gate Objects
  3. // -------------------------------------------------------------
  4. // By Matite in February 2015
  5. //
  6. //
  7. // This script creates the new LS Prison Walls object, removes the existing
  8. // GTASA object and creates 2 sets of opening gates.
  9. //
  10. // Warning...
  11. // This script uses a total of:
  12. // * 5 objects = 1 for the replacement walls and 4 for the replacement gates
  13. // * 2 3D Text Labels = 1 on each set of gates
  14. // * Enables the /lsp command to teleport the player to the eastern prison gates
  15. // -----------------------------------------------------------------------------
  16. // -----------------------------------------------------------------------------
  17. // -----------------------------------------------------------------------------
  18. // Includes
  19. // --------
  20. // SA-MP include
  21. #include <a_samp>
  22. // For PlaySoundForPlayersInRange()
  23. #include "../include/gl_common.inc"
  24. // -----------------------------------------------------------------------------
  25. // Defines
  26. // -------
  27. // Used for the eastern and southern prison gates status flags
  28. #define GATES_CLOSED 0
  29. #define GATES_CLOSING 1
  30. #define GATES_OPEN 2
  31. #define GATES_OPENING 3
  32. // Used for messages sent to the player
  33. #define COLOR_MESSAGE_YELLOW 0xFFDD00AA
  34. // -----------------------------------------------------------------------------
  35. // Constants
  36. // ---------
  37. // Gate names for the 3D text labels
  38. static GateNames[2][] =
  39. {
  40. "Eastern Gates",
  41. "Southern Gates"
  42. };
  43. // -----------------------------------------------------------------------------
  44. // Variables
  45. // ---------
  46. // Stores the created object number of the replacement prison walls so it can
  47. // be destroyed when the filterscript is unloaded
  48. new LSPrisonWallsObject;
  49. // Stores the created object numbers of the prison walls gates so they can be
  50. // opened or closed and destroyed when the filterscript is unloaded
  51. new LSPrisonGatesObject[4];
  52. // Stores a reference to the 3D text labels used on each set of gates so they
  53. // can be destroyed when the filterscript is unloaded
  54. new Text3D:LabelGates[2];
  55. // Stores the current status of the eastern prison gates
  56. new EasternGatesStatus = GATES_CLOSED;
  57. // Stores the current status of the southern prison gates
  58. new SouthernGatesStatus = GATES_CLOSED;
  59. // -----------------------------------------------------------------------------
  60. // Callbacks
  61. // ---------
  62. public OnPlayerCommandText(playerid, cmdtext[])
  63. {
  64. // Check command text
  65. if (strcmp("/lsp", cmdtext, true, 4) == 0)
  66. {
  67. // Set the interior
  68. SetPlayerInterior(playerid, 0);
  69. // Set player position and facing angle
  70. SetPlayerPos(playerid, 1830.66 + random(2), -1538.46, 14.5);
  71. SetPlayerFacingAngle(playerid, 85);
  72. // Fix camera position after teleporting
  73. SetCameraBehindPlayer(playerid);
  74. // Send a gametext message to the player
  75. GameTextForPlayer(playerid, "~b~~h~LS Prison!", 3000, 3);
  76. // Exit here
  77. return 1;
  78. }
  79. // Exit here (return 0 as the command was not handled in this filterscript)
  80. return 0;
  81. }
  82. public OnFilterScriptInit()
  83. {
  84. // Display information in the Server Console
  85. print("\n");
  86. print(" |---------------------------------------------------");
  87. print(" |--- LS Prison Walls Filterscript");
  88. print(" |-- Script v1.01");
  89. print(" |-- 13th February 2015");
  90. print(" |---------------------------------------------------");
  91. // Create the LS Prison Walls object
  92. LSPrisonWallsObject = CreateObject(19794, 1787.13, -1565.68, 11.9688, 0, 0, 0);
  93. // Display information in the Server Console
  94. print(" |-- LS Prison Walls object created");
  95. // Create the LS Prison Walls Eastern Gates objects
  96. LSPrisonGatesObject[0] = CreateObject(19795, 1824.318481, -1534.731201, 14.296878 - 0.01, 0, 0, 343.0);
  97. LSPrisonGatesObject[1] = CreateObject(19795, 1822.407592, -1540.949951, 14.296878 - 0.01, 0, 0, 163.0);
  98. // Create the LS Prison Walls Southern Gates objects
  99. LSPrisonGatesObject[2] = CreateObject(19796, 1752.004150, -1591.186523, 14.267195 - 0.01, 0, 0, 77.0);
  100. LSPrisonGatesObject[3] = CreateObject(19796, 1756.914062, -1592.316284, 14.267195 - 0.01, 0, 0, 257.0);
  101. // Display information in the Server Console
  102. print(" |-- LS Prison Walls Gates objects created");
  103. // Create variable
  104. new string[192];
  105. // Create 3D Text Label at the prisons eastern gates
  106. format(string, sizeof(string), "{CCCCCC}[%s]\n{CCCCCC}Press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}' to open or close the gates", GateNames[0]);
  107. LabelGates[0] = Create3DTextLabel(string, 0xCCCCCCAA, 1823.78, -1537.98, 13.54, 10.5, 0, 1);
  108. // Create 3D Text Label at the prisons eastern gates
  109. format(string, sizeof(string), "{CCCCCC}[%s]\n{CCCCCC}Press '{FFFFFF}~k~~CONVERSATION_YES~{CCCCCC}' to open or close the gates", GateNames[1]);
  110. LabelGates[1] = Create3DTextLabel(string, 0xCCCCCCAA, 1754.27, -1592.18, 13.54, 10.5, 0, 1);
  111. // Display information in the Server Console
  112. print(" |-- LS Prison Wall Gates 3D Text Labels created");
  113. print(" |---------------------------------------------------");
  114. // Loop
  115. for (new i = 0; i < MAX_PLAYERS; i++)
  116. {
  117. // Check if the player is connected and not a NPC
  118. if (IsPlayerConnected(i) && !IsPlayerNPC(i))
  119. {
  120. // Remove default GTASA LS Prison Walls and LOD map objects for the player
  121. // (so any player currently ingame does not have to rejoin for them
  122. // to be removed when this filterscript is loaded)
  123. RemoveBuildingForPlayer(i, 4000, 1787.13, -1565.68, 11.9688, 250.0); // Walls
  124. RemoveBuildingForPlayer(i, 4080, 1787.13, -1565.68, 11.9688, 250.0); // LOD
  125. }
  126. }
  127. // Exit here
  128. return 1;
  129. }
  130. public OnFilterScriptExit()
  131. {
  132. // Check for valid object
  133. if (IsValidObject(LSPrisonWallsObject))
  134. {
  135. // Destroy the LS Prison Walls object
  136. DestroyObject(LSPrisonWallsObject);
  137. // Display information in the Server Console
  138. print(" |---------------------------------------------------");
  139. print(" |-- LS Prison Walls object destroyed");
  140. }
  141. // Check for valid object
  142. if (IsValidObject(LSPrisonGatesObject[0]))
  143. {
  144. // Destroy the LS Prison Walls Eastern Gates object 1
  145. DestroyObject(LSPrisonGatesObject[0]);
  146. // Display information in the Server Console
  147. print(" |-- LS Prison Walls Eastern Gates object 1 destroyed");
  148. }
  149. // Check for valid object
  150. if (IsValidObject(LSPrisonGatesObject[1]))
  151. {
  152. // Destroy the LS Prison Walls Eastern Gates object 2
  153. DestroyObject(LSPrisonGatesObject[1]);
  154. // Display information in the Server Console
  155. print(" |-- LS Prison Walls Eastern Gates object 2 destroyed");
  156. }
  157. // Check for valid object
  158. if (IsValidObject(LSPrisonGatesObject[2]))
  159. {
  160. // Destroy the LS Prison Walls Southern Gates object 1
  161. DestroyObject(LSPrisonGatesObject[2]);
  162. // Display information in the Server Console
  163. print(" |-- LS Prison Walls Southern Gates object 1 destroyed");
  164. }
  165. // Check for valid object
  166. if (IsValidObject(LSPrisonGatesObject[3]))
  167. {
  168. // Destroy the LS Prison Walls Southern Gates object 2
  169. DestroyObject(LSPrisonGatesObject[3]);
  170. // Display information in the Server Console
  171. print(" |-- LS Prison Walls Southern Gates object 2 destroyed");
  172. }
  173. // Destroy 3D Text Labels on the eastern and southern gates
  174. Delete3DTextLabel(LabelGates[0]);
  175. Delete3DTextLabel(LabelGates[1]);
  176. // Display information in the Server Console
  177. print(" |-- Deleted the 3D Text Labels on the Prison Gates");
  178. // Display information in the Server Console
  179. print(" |---------------------------------------------------");
  180. print(" |-- LS Prison Walls Filterscript Unloaded");
  181. print(" |---------------------------------------------------");
  182. // Exit here
  183. return 1;
  184. }
  185. public OnPlayerConnect(playerid)
  186. {
  187. // Remove default GTASA LS Prison Walls and LOD map objects for the player
  188. RemoveBuildingForPlayer(playerid, 4000, 1787.13, -1565.68, 11.9688, 250.0); // Walls
  189. RemoveBuildingForPlayer(playerid, 4080, 1787.13, -1565.68, 11.9688, 250.0); // LOD
  190. // Exit here (return 1 so this callback is handled in other scripts too)
  191. return 1;
  192. }
  193. public OnObjectMoved(objectid)
  194. {
  195. // Check if the object that moved was one of the eastern gates
  196. if (objectid == LSPrisonGatesObject[0])
  197. {
  198. // Check if the eastern gates were closing
  199. if (EasternGatesStatus == GATES_CLOSING)
  200. {
  201. // Set status flag for eastern gates
  202. EasternGatesStatus = GATES_CLOSED;
  203. }
  204. else
  205. {
  206. // Set status flag for eastern gates
  207. EasternGatesStatus = GATES_OPEN;
  208. }
  209. }
  210. // Check if the object that moved was one of the southern gates
  211. else if (objectid == LSPrisonGatesObject[2])
  212. {
  213. // Check if the southern gates were closing
  214. if (SouthernGatesStatus == GATES_CLOSING)
  215. {
  216. // Set status flag for southern gates
  217. SouthernGatesStatus = GATES_CLOSED;
  218. }
  219. else
  220. {
  221. // Set status flag for southern gates
  222. SouthernGatesStatus = GATES_OPEN;
  223. }
  224. }
  225. // Exit here
  226. return 1;
  227. }
  228. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  229. {
  230. // Check if the player pressed the conversation yes key (normally the Y key)
  231. if (newkeys & KEY_YES)
  232. {
  233. // Check if the player is outside the eastern prison gates
  234. if (IsPlayerInRangeOfPoint(playerid, 10.0, 1823.78, -1537.98, 13.54))
  235. {
  236. // Debug
  237. //printf("-->Player ID %d within 10m of the Eastern Prison Gates", playerid);
  238. // Check if the eastern gates are not currently opening (ie moving)
  239. if (EasternGatesStatus == GATES_OPENING)
  240. {
  241. // Send chat text message and exit here
  242. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Sorry, you must wait for the eastern gates to fully open first.");
  243. return 1;
  244. }
  245. // Check if the eastern gates are not currently closing (ie moving)
  246. else if (EasternGatesStatus == GATES_CLOSING)
  247. {
  248. // Send chat text message and exit here
  249. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Sorry, you must wait for the eastern gates to fully close first.");
  250. return 1;
  251. }
  252. // Play gate opening sound
  253. PlaySoundForPlayersInRange(1035, 50.0, 1823.78, -1537.98, 13.54);
  254. // Check if the eastern gates are currently open or closed
  255. if (EasternGatesStatus == GATES_CLOSED)
  256. {
  257. // Send a gametext message to the player
  258. GameTextForPlayer(playerid, "~b~~h~Eastern Prison~n~~b~~h~Gates Opening!", 3000, 3);
  259. // Animate the eastern gates opening (the small Z offset is required)
  260. MoveObject(LSPrisonGatesObject[0], 1824.318481, -1534.731201, 14.296878 + 0.01, 0.002, 0, 0, 258);
  261. // Animate the eastern gates opening (the small Z offset is required)
  262. MoveObject(LSPrisonGatesObject[1], 1822.407592, -1540.949951, 14.296878 + 0.01, 0.002, 0, 0, 253);
  263. // Set status flag for eastern gates
  264. EasternGatesStatus = GATES_OPENING;
  265. }
  266. else
  267. {
  268. // Send a gametext message to the player
  269. GameTextForPlayer(playerid, "~b~~h~Eastern Prison~n~~b~~h~Gates Closing!", 3000, 3);
  270. // Animate the eastern gates closing (the small Z offset is required)
  271. MoveObject(LSPrisonGatesObject[0], 1824.318481, -1534.731201, 14.296878 - 0.01, 0.002, 0, 0, 343);
  272. // Animate the eastern gates closing (the small Z offset is required)
  273. MoveObject(LSPrisonGatesObject[1], 1822.407592, -1540.949951, 14.296878 - 0.01, 0.002, 0, 0, 163);
  274. // Set status flag for eastern gates
  275. EasternGatesStatus = GATES_CLOSING;
  276. }
  277. }
  278. // Check if the player is outside the southern prison gates
  279. else if (IsPlayerInRangeOfPoint(playerid, 10.0, 1754.27, -1592.18, 13.54))
  280. {
  281. // Debug
  282. //printf("-->Player ID %d within 10m of the Southern Prison Gates", playerid);
  283. // Check if the southern gates are not currently opening (ie moving)
  284. if (SouthernGatesStatus == GATES_OPENING)
  285. {
  286. // Send chat text message and exit here
  287. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Sorry, you must wait for the southern gates to fully open first.");
  288. return 1;
  289. }
  290. // Check if the southern gates are not currently closing (ie moving)
  291. else if (SouthernGatesStatus == GATES_CLOSING)
  292. {
  293. // Send chat text message and exit here
  294. SendClientMessage(playerid, COLOR_MESSAGE_YELLOW, "* Sorry, you must wait for the southern gates to fully close first.");
  295. return 1;
  296. }
  297. // Play gate opening sound
  298. PlaySoundForPlayersInRange(1035, 50.0, 1754.27, -1592.18, 13.54);
  299. // Check if the southern gates are currently open or closed
  300. if (SouthernGatesStatus == GATES_CLOSED)
  301. {
  302. // Send a gametext message to the player
  303. GameTextForPlayer(playerid, "~b~~h~Southern Prison~n~~b~~h~Gates Opening!", 3000, 3);
  304. // Animate the southern gates opening (the small Z offset is required)
  305. MoveObject(LSPrisonGatesObject[2], 1752.004150, -1591.186523, 14.267195 + 0.01, 0.002, 0, 0, 172);
  306. // Animate the southern gates opening (the small Z offset is required)
  307. MoveObject(LSPrisonGatesObject[3], 1756.914062, -1592.316284, 14.267195 + 0.01, 0.002, 0, 0, 187);
  308. // Set status flag for southern gates
  309. SouthernGatesStatus = GATES_OPENING;
  310. }
  311. else
  312. {
  313. // Send a gametext message to the player
  314. GameTextForPlayer(playerid, "~b~~h~Southern Prison~n~~b~~h~Gates Closing!", 3000, 3);
  315. // Animate the southern gates closing (the small Z offset is required)
  316. MoveObject(LSPrisonGatesObject[2], 1752.004150, -1591.186523, 14.267195 - 0.01, 0.002, 0, 0, 77);
  317. // Animate the southern gates closing (the small Z offset is required)
  318. MoveObject(LSPrisonGatesObject[3], 1756.914062, -1592.316284, 14.267195 - 0.01, 0.002, 0, 0, 257);
  319. // Set status flag for southern gates
  320. SouthernGatesStatus = GATES_CLOSING;
  321. }
  322. }
  323. }
  324. // Exit here (return 1 so this callback is handled in other scripts too)
  325. return 1;
  326. }