drivingtest.pwn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. /$$ /$$ /$$$$$$ /$$$$$$$ /$$$$$$$
  3. | $$$ | $$ /$$__ $$ | $$__ $$| $$__ $$
  4. | $$$$| $$| $$ \__/ | $$ \ $$| $$ \ $$
  5. | $$ $$ $$| $$ /$$$$ /$$$$$$| $$$$$$$/| $$$$$$$/
  6. | $$ $$$$| $$|_ $$|______/| $$__ $$| $$____/
  7. | $$\ $$$| $$ \ $$ | $$ \ $$| $$
  8. | $$ \ $$| $$$$$$/ | $$ | $$| $$
  9. |__/ \__/ \______/ |__/ |__/|__/
  10. Driving License System
  11. Next Generation Gaming, LLC
  12. (created by Next Generation Gaming Development Team)
  13. Developers:
  14. (*) Connor
  15. * Copyright (c) 2016, Next Generation Gaming, LLC
  16. *
  17. * All rights reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without modification,
  20. * are not permitted in any case.
  21. *
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. /*
  36. MODULE DESCRIPTION:
  37. This module will control the driving school (LV), and any other's created afterwards.
  38. Module created by Connor.
  39. */
  40. #include <YSI\y_hooks>
  41. #define DIALOG_DSVEH_CAUTION 6941
  42. #define DIALOG_DSVEH_RULES 6942
  43. #define DIALOG_DSVEH_TESTBASE 6943
  44. #define CHECKPOINT_DRIVINGSCHOOL 2539
  45. forward checkTestVehicle(playerid);
  46. new Float:dsPoints[][3] = {
  47. {829.8356,-609.6153,15.9689}, // 50 MPH
  48. {834.2700,-548.9444,15.8153},
  49. {781.6683,-527.6374,15.8153},
  50. {722.0259,-527.9050,15.8117},
  51. {679.1986,-566.1868,15.8153},
  52. {679.1959,-673.4142,15.8153},
  53. {683.9590,-797.7986,35.4485},
  54. {741.2899,-891.5577,42.8651},
  55. {792.9636,-1030.4653,24.8114}, // 100 MPH
  56. {737.3622,-1060.4653,22.8377},
  57. {646.8804,-1192.7010,17.6902},
  58. {625.2151,-1301.7292,14.2485},
  59. {624.0712,-1398.9515,12.9462},
  60. {624.7911,-1523.6074,14.5749},
  61. {627.0731,-1657.8997,15.3599},
  62. {584.9104,-1720.6461,13.1373},
  63. {420.5506,-1700.2816,9.1901},
  64. {216.9152,-1632.4012,13.4200},
  65. {72.1308,-1525.2570,4.4657},
  66. {-97.6246,-1489.8728,2.3231}, // 50 MPH
  67. {-147.4238,-1315.8544,2.3231},
  68. {-107.0146,-1157.5494,1.6611},
  69. {-81.8646,-1045.9396,21.1786},
  70. {-113.1582,-971.5482,24.0782},
  71. {-43.8502,-833.1515,11.9268},
  72. {29.7384,-663.5918,3.1997},
  73. {130.4584,-684.7977,6.0668},
  74. {220.9880,-623.3987,27.2719},
  75. {303.0262,-568.5374,40.2530},
  76. {446.1580,-598.4182,36.5259},
  77. {594.7116,-647.3687,21.3924},
  78. {669.3761,-664.3604,15.8585},
  79. {684.0832,-543.3890,15.8132},
  80. {722.6440,-532.4922,15.8075},
  81. {789.2615,-546.0828,15.8167},
  82. {829.8356,-609.6153,15.9689}
  83. };
  84. //player_get_speed
  85. // PVARS: pDTest (Is the player testing), pTestMarker (The marker the player is on), pTestZone (Roads, Highways), pTestVeh (The vehicle the player is testing with)
  86. new pFindDrive[MAX_PLAYERS];
  87. new pDriveTimer[MAX_PLAYERS];
  88. DrivingTestFinish(playerid)
  89. {
  90. new pTestVeh = GetPVarInt(playerid, "PTestVeh");
  91. DestroyVehicle(pTestVeh);
  92. DeletePVar(playerid, "pTestVeh");
  93. DeletePVar(playerid, "pDTest");
  94. DeletePVar(playerid, "pTestMarker");
  95. DisablePlayerCheckpoint(playerid);
  96. PlayerInfo[playerid][pCarLic] = gettime() + (86400*80);
  97. SendClientMessageEx(playerid, COLOR_WHITE, "Driving Instructor: You have successfully completed driving school and earned your license!");
  98. return 1;
  99. }
  100. DrivingSchoolSpeedMeter(playerid, Float:speed)
  101. {
  102. new
  103. pTestMarker = GetPVarInt(playerid, "pTestMarker"),
  104. maxspeed = 0;
  105. /*if(pTestMarker < 20 || pTestMarker >= 29)
  106. {
  107. if(speed > 50)
  108. {
  109. SetPlayerCheckpoint(playerid, 814.0655,-600.5410,16.0355, 4.0);
  110. SendClientMessageEx(playerid, COLOR_GREY, "You have exceeded the resdiental speed limit of 50MPH, you have failed the test.");
  111. SetPVarInt(playerid, "pDTest", 2);
  112. }
  113. }
  114. else if(speed >= 100)
  115. {
  116. SetPlayerCheckpoint(playerid, 814.0655,-600.5410,16.0355, 4.0);
  117. SendClientMessageEx(playerid, COLOR_GREY, "You have exceeded the freeway speed limit of 100MPH, you have failed the test.");
  118. SetPVarInt(playerid, "pDTest", 2);
  119. }*/
  120. switch(pTestMarker) {
  121. case 0 .. 7: maxspeed = 50;
  122. case 8 .. 19: maxspeed = 75;
  123. case 20 .. 36: maxspeed = 50;
  124. }
  125. if(speed > (maxspeed + 5) && GetPVarInt(playerid, "pDTest") != 2) {
  126. format(szMiscArray, sizeof(szMiscArray), "You have exceeded the max speed limit of %d MPH.", maxspeed);
  127. SendClientMessageEx(playerid, COLOR_GREY, szMiscArray);
  128. SetPlayerCheckpoint(playerid, 814.0655,-600.5410,16.0355, 4.0);
  129. SetPVarInt(playerid, "pDTest", 2);
  130. }
  131. return 1;
  132. }
  133. hook OnGameModeInit()
  134. {
  135. //CreateDynamicPickup(1239, 1, 1173.0698,1348.4688,10.9219);
  136. //CreateDynamic3DTextLabel("/drivingtest to begin the driving test.", 0xFF0000FF, 1173.0698,1348.4688,10.9219,4.0);
  137. return 1;
  138. }
  139. hook OnPlayerStateChange(playerid, newstate, oldstate)
  140. {
  141. if(GetPVarType(playerid, "pDTest") > 0)
  142. {
  143. new pTestVeh = GetPVarInt(playerid, "pTestVeh");
  144. if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
  145. {
  146. pDriveTimer[playerid] = SetTimerEx("checkTestVehicle", 60000, false, "i", playerid);
  147. SendClientMessageEx(playerid, COLOR_YELLOW, "You have 60 seconds to get back in your vehicle or it will be taken back.");
  148. }
  149. else if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && GetPlayerVehicleID(playerid) == pTestVeh)
  150. {
  151. KillTimer(pDriveTimer[playerid]);
  152. }
  153. }
  154. else if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
  155. {
  156. if(PlayerInfo[playerid][pCarLic] < gettime())
  157. {
  158. SendClientMessageEx(playerid, COLOR_YELLOW, "Warning: Your drivers license has expired. Head to the DMV to renew it.");
  159. }
  160. }
  161. return 1;
  162. }
  163. public checkTestVehicle(playerid)
  164. {
  165. if(GetPVarType(playerid, "pDTest") > 0)
  166. {
  167. if(GetPlayerVehicleID(playerid) > 0) return 1;
  168. new pTestVeh = GetPVarInt(playerid, "PTestVeh");
  169. DestroyVehicle(pTestVeh);
  170. DeletePVar(playerid, "pTestVeh");
  171. DeletePVar(playerid, "pDTest");
  172. DeletePVar(playerid, "pTestMarker");
  173. DisablePlayerCheckpoint(playerid);
  174. SendClientMessageEx(playerid, COLOR_YELLOW, "SMS: You have failed your driving test. , Sender: Driving Instructor (555)");
  175. }
  176. return 1;
  177. }
  178. hook OnPlayerDisconnect(playerid)
  179. {
  180. if(GetPVarType(playerid, "PTestVeh"))
  181. {
  182. new pTestVeh = GetPVarInt(playerid, "PTestVeh");
  183. DestroyVehicle(pTestVeh);
  184. }
  185. pFindDrive[playerid] = 0;
  186. pDriveTimer[playerid] = 0;
  187. }
  188. hook OnPlayerEnterCheckpoint(playerid){
  189. if(pFindDrive[playerid] == 1)
  190. {
  191. pFindDrive[playerid] = 0;
  192. DisablePlayerCheckpoint(playerid);
  193. SendClientMessageEx(playerid, COLOR_GREY, "You have arrived at the driving school!");
  194. }
  195. else if(gPlayerCheckpointStatus[playerid] == CHECKPOINT_DRIVINGSCHOOL)
  196. {
  197. new pDTest = GetPVarInt(playerid, "pDTest");
  198. if(pDTest == 1)
  199. {
  200. new pTestMarker = GetPVarInt(playerid, "pTestMarker");
  201. pTestMarker += 1;
  202. if(pTestMarker >= sizeof(dsPoints)) return DrivingTestFinish(playerid);
  203. SetPlayerCheckpoint(playerid, dsPoints[pTestMarker][0], dsPoints[pTestMarker][1], dsPoints[pTestMarker][2], 4.0);
  204. SetPVarInt(playerid, "pTestMarker", pTestMarker);
  205. }
  206. else if(pDTest == 2)
  207. {
  208. new pTestVeh = GetPVarInt(playerid, "PTestVeh");
  209. DestroyVehicle(pTestVeh);
  210. DeletePVar(playerid, "pTestVeh");
  211. DeletePVar(playerid, "pDTest");
  212. DeletePVar(playerid, "pTestMarker");
  213. DisablePlayerCheckpoint(playerid);
  214. }
  215. }
  216. return 1;
  217. }
  218. hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  219. if(arrAntiCheat[playerid][ac_iFlags][AC_DIALOGSPOOFING] > 0) return 1;
  220. switch(dialogid)
  221. {
  222. case DIALOG_DSVEH_CAUTION:
  223. {
  224. if(response)
  225. {
  226. //1138.3353,1375.6553,10.4057
  227. ShowPlayerDialogEx(playerid,
  228. DIALOG_DSVEH_RULES,
  229. DIALOG_STYLE_MSGBOX,
  230. "Driving Rules",
  231. "The rules of the road are as follows..\n1. You must drive on the right side of the road.\n2. You must follow speed limits at all times.\n3. Your seatbelt must be on at all times.\n4. Your vehicle lights must be on at night.\n5. If you get in an accident, you must report it.\n6. You must park correctly at all times.",
  232. "Next",
  233. "Cancel");
  234. }
  235. else return SendClientMessageEx(playerid, COLOR_GREY, "You have cancelled the driving test.");
  236. }
  237. case DIALOG_DSVEH_RULES:
  238. {
  239. if(response)
  240. {
  241. ShowPlayerDialogEx(playerid,
  242. DIALOG_DSVEH_TESTBASE,
  243. DIALOG_STYLE_LIST,
  244. "{FF0000}If you crash into a vehicle, you must...",
  245. "Run away\nDrive away\nReport the accident to your insurance and police.", "Choose", "Cancel");
  246. }
  247. }
  248. case DIALOG_DSVEH_TESTBASE:
  249. {
  250. if(response)
  251. {
  252. if(listitem == 2)
  253. {
  254. ShowPlayerDialogEx(playerid,
  255. DIALOG_DSVEH_TESTBASE+1,
  256. DIALOG_STYLE_LIST,
  257. "{FF0000}You must drive on the LEFT side of the road..",
  258. "True\nFalse", "Choose", "Cancel");
  259. }
  260. else
  261. {
  262. return SendClientMessageEx(playerid, COLOR_GREY, "You have failed the test. Incorrect answer.");
  263. }
  264. }
  265. }
  266. case DIALOG_DSVEH_TESTBASE+1:
  267. {
  268. if(response)
  269. {
  270. if(listitem == 1)
  271. {
  272. ShowPlayerDialogEx(playerid,
  273. DIALOG_DSVEH_TESTBASE+2,
  274. DIALOG_STYLE_LIST,
  275. "{FF0000}If the speed limit is 50mph, you must go..",
  276. "650mph\n120mph\n100mph\n50mph\n300mph\n430mph", "Choose", "Cancel");
  277. }
  278. else
  279. {
  280. return SendClientMessageEx(playerid, COLOR_GREY, "You have failed the test. Incorrect answer.");
  281. }
  282. }
  283. }
  284. case DIALOG_DSVEH_TESTBASE+2:
  285. {
  286. if(response)
  287. {
  288. if(listitem == 3)
  289. {
  290. ShowPlayerDialogEx(playerid,
  291. DIALOG_DSVEH_TESTBASE+3,
  292. DIALOG_STYLE_LIST,
  293. "{FF0000}Your seatbelt must always be on.",
  294. "True\nFalse", "Choose", "Cancel");
  295. }
  296. else
  297. {
  298. return SendClientMessageEx(playerid, COLOR_GREY, "You have failed the test. Incorrect answer.");
  299. }
  300. }
  301. }
  302. case DIALOG_DSVEH_TESTBASE+3:
  303. {
  304. if(response)
  305. {
  306. if(listitem == 0)
  307. {
  308. SetPlayerVirtualWorld(playerid, 0);
  309. SetPlayerInterior(playerid, 0);
  310. SetPVarInt(playerid, "PTestVeh", CreateVehicle(404, 814.0655,-600.5410,16.0355, 90.0, 3, 3, -1));
  311. new pTestVeh = GetPVarInt(playerid, "PTestVeh");
  312. PutPlayerInVehicle(playerid, pTestVeh, 0);
  313. SendClientMessageEx(playerid, COLOR_WHITE, "Driving Instructor: Please make sure you go a max of 50mph in the residential areas. You may now begin.");
  314. if(!PlayerInfo[playerid][pSpeedo])
  315. {
  316. SendClientMessageEx(playerid, COLOR_WHITE, "Your speedometer has been enabled for you.");
  317. PlayerInfo[playerid][pSpeedo] = 1;
  318. ShowVehicleHUDForPlayer(playerid);
  319. }
  320. SetPVarInt(playerid, "PDTest", 1);
  321. DisablePlayerCheckpoint(playerid);
  322. SetPlayerCheckpoint(playerid, dsPoints[0][0], dsPoints[0][1], dsPoints[0][2], 4.0);
  323. SetPVarInt(playerid, "pTestMarker", 0);
  324. gPlayerCheckpointStatus[playerid] = CHECKPOINT_DRIVINGSCHOOL;
  325. }
  326. else
  327. {
  328. return SendClientMessageEx(playerid, COLOR_GREY, "You have failed the test. Incorrect answer.");
  329. }
  330. }
  331. }
  332. }
  333. return 0;
  334. }