Advertisement
Guest User

kogu praegune gm

a guest
Nov 22nd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 66.98 KB | None | 0 0
  1. // Make sure you don't get warnings about tabsize
  2. #pragma tabsize 0
  3.  
  4.  
  5.  
  6. // ********************************************************************************************************************
  7. // Set default gamemode name
  8. // ********************************************************************************************************************
  9.  
  10. #define GameModeName "PowerPC603's Trucking Server"
  11.  
  12. // ********************************************************************************************************************
  13. // Limit the amount of cops with a value greater than 0
  14. // Setting this to "3" would mean:
  15. // - having 3 normal players (non-cop players) before the first cop can join the server
  16. // - having 6 normal players before 2 cops can be active
  17. // - having 9 normal players before the third cop can join and so on
  18. // Leaving this at 0 disables the police-limitation, so anyone can choose the police class anytime
  19. // ********************************************************************************************************************
  20.  
  21. new PlayersBeforePolice = 0;
  22.  
  23. // ********************************************************************************************************************
  24. // ********************************************************************************************************************
  25.  
  26.  
  27.  
  28. // Include default files
  29. #include <a_samp>
  30. #include <zcmd>
  31. #include <dutils>
  32. #include <sscanf2>
  33. #include <streamer>
  34.  
  35. // Include all define-statements and custom-type declarations and the arrays which use them
  36. // These files need to be included before the functions get included, because the functions use the defines, custom types and the arrays
  37. // Also include the defined loads (for truckers, military, mafia, ...) and locations arrays
  38. #include <PPC_DefTexts>
  39. #include <PPC_ServerSettings>
  40. #include <PPC_Defines>
  41. #include <PPC_DefLocations>
  42. #include <PPC_DefLoads>
  43. #include <PPC_DefCars>
  44. #include <PPC_DefPlanes>
  45. #include <PPC_DefTrailers>
  46. #include <PPC_DefBuyableVehicles>
  47. // Include functions for this gamemode
  48. #include <PPC_GlobalTimer>
  49. #include <PPC_Common>
  50. #include <PPC_Housing>
  51. #include <PPC_Business>
  52. #include <PPC_GameModeInit>
  53. #include <PPC_FileOperations>
  54. #include <PPC_Speedometer>
  55. #include <PPC_MissionsTrucking>
  56. #include <PPC_MissionsBus>
  57. #include <PPC_MissionsPilot>
  58. #include <PPC_MissionsPolice>
  59. #include <PPC_MissionsMafia>
  60. #include <PPC_MissionsAssistance>
  61. #include <PPC_MissionsCourier>
  62. #include <PPC_MissionsRoadworker>
  63. #include <PPC_Convoys>
  64. #include <PPC_Dialogs>
  65. #include <PPC_PlayerCommands>
  66. #include <PPC_Toll>
  67.  
  68.  
  69.  
  70. // The main function (used only once when the server loads)
  71. main()
  72. {
  73. // Print some standard lines to the server's console
  74. print("\n----------------------------------");
  75. print(GameModeName);
  76. print("----------------------------------\n");
  77.  
  78.  
  79. // This is a comment
  80. // uncomment the line below if you want to write a filterscript
  81. }
  82.  
  83. // Objektid kinnises olekus (need on siin lihtsalt kommentaarid)
  84. /*
  85. CreateObjectCreateDynamicObject((969, -833.41528, 1430.92126, 12.90100, 0.00000, 0.00000, 90.30000); // Värav kinni
  86. */
  87. // Objektid lahtises olekus
  88. /*
  89. CreateObject(969, -833.41528, 1438.88135, 12.90100, 0.00000, 0.00000, 90.30000); // Värav lahti
  90. */
  91.  
  92. // Muutujad
  93. new V2ravadAvatud = 0; // Seda kasutame käskluses et saaks teha väravad ühe käsklusega kinni ja lahti
  94.  
  95. new V2rav1, // Lisame uued niiüelda objektid/muutujad millele paneme tähendused järgi ja hakkame liigutama
  96. #define Kiirus 10.0 // Defineerime ära ka kiiruse, kui kiiresti väravad avanevad/sulgevad (ei pea seda tegema aga endal lihtsam, näiteks valida sobivat kiirust ja et ei pea eraldi neid muutma pärast)
  97.  
  98. #if defined FILTERSCRIPT
  99.  
  100.  
  101.  
  102.  
  103. // This callback gets called when the server initializes the gamemode
  104. public OnGameModeInit()
  105. {
  106. new HostCommand[128];
  107. // Change the hostname
  108. format(HostCommand, 128, "hostname %s", GameModeName);
  109. SendRconCommand(HostCommand);
  110. SetGameModeText(GameModeName); // Set the Mode of the gamemode, which appears in the list of servers
  111.  
  112. GameModeInit_VehiclesPickups(); // Add all static vehicles and pickups when the server starts that are required (also load the houses)
  113. GameModeInit_Classes(); // Add character models to the class-selection (without weapons)
  114.  
  115. Convoys_Init(); // Setup textdraws and default data for convoys
  116.  
  117. ShowPlayerMarkers(1); // Show players on the entire map (and on the radar)
  118. ShowNameTags(1); // Show player names (and health) above their head
  119. ManualVehicleEngineAndLights(); // Let the server control the vehicle's engine and lights
  120. EnableStuntBonusForAll(0); // Disable stunt bonus for all players
  121. DisableInteriorEnterExits(); // Removes all building-entrances in the game
  122. UsePlayerPedAnims(); // Use CJ's walking animation
  123.  
  124. // Start the timer that will show timed messages every 2 minutes
  125. SetTimer("Timer_TimedMessages", 1000 * 60 * 2, true);
  126. // Start the timer that will show a random bonus mission for truckers every 5 minutes
  127. SetTimer("ShowRandomBonusMission", 1000 * 60 * 5, true);
  128. // Start the timer that checks the toll-gates
  129. SetTimer("Toll", 1000, true);
  130.  
  131. // Fix the bugged houses (after fixing the houses, you can remove this line, as it's not needed anymore)
  132. FixHouses();
  133.  
  134. // While the gamemode starts, start the global timer, and run it every second
  135. SetTimer("GlobalTimer", 1000, true);
  136.  
  137.  
  138.  
  139. V2rav1 = CreateObject(969, -833.41528, 1430.92126, 12.90100, 0.00000, 0.00000, 90.30000); // Kahene värav 1 kinni
  140. return 1;
  141. }
  142.  
  143. CMD:v2ravad(playerid, params[])
  144. {
  145. // Kui värav on kinni siis muutuja on 0 aga kui värav on avatud siis on muutuja 1.
  146. // Ehk siis muutuja järgi ta vaatab kas vaja väravat liigutada kinni või lahti
  147. if (V2ravadAvatud == 0) // Muutuja on 0, ehk on värav kinni ja vaja väravat liigutada lahti
  148. {
  149. // MoveObject(objecti id mida liigutada tahame, positsioon X, positsioon Y, positsioon Z, Liikumis kiirus);
  150. MoveObject(V2rav1, 969, -833.41528, 1438.88135, 12.90100, 0.00000, 0.00000, 90.30000, Kiirus); // Liigutab värava kordinaatidele lahti
  151.  
  152. V2ravadAvatud = 1; // Muudab muutuja 1 peale. Ehk kui järgime kord käsklust kasutada näitab ta V2ravadAvatud == 1 ja sulgeb väravad
  153. }
  154. else if(V2ravadAvatud == 1) // Aga kui muutuja on 1 ehk värav on lahti, siis ta sulgeb väravad.
  155. {
  156. MoveObject(V2rav1, 969, -833.41528, 1430.92126, 12.90100, 0.00000, 0.00000, 90.30000, Kiirus); // Liigutab värava originaal asendisse (samadele kordinaatidele mis OnGameModeInit() alla lisasime
  157. V2ravadAvatud = 0; // Muudab muutuja tagasi 0 peale. Ehk kui järgime kord käsklust kasutada, näitab et värav on suletud ehk muutuja V2ravadAvatud == 1
  158. }
  159. return 1;
  160. CMD:v2ravad(playerid, params[])
  161. {
  162. // Kui värav on kinni siis muutuja on 0 aga kui värav on avatud siis on muutuja 1.
  163. // Ehk siis muutuja järgi ta vaatab kas vaja väravat liigutada kinni või lahti
  164. if (V2ravadAvatud == 0) // Muutuja on 0, ehk on värav kinni ja vaja väravat liigutada lahti
  165. {
  166. // MoveObject(objecti id mida liigutada tahame, positsioon X, positsioon Y, positsioon Z, Liikumis kiirus);
  167. MoveObject(V2rav1, 969, -833.41528, 1438.88135, 12.90100, 0.00000, 0.00000, 90.30000, Kiirus); // Liigutab värava kordinaatidele lahti
  168.  
  169. V2ravadAvatud = 1; // Muudab muutuja 1 peale. Ehk kui järgime kord käsklust kasutada näitab ta V2ravadAvatud == 1 ja sulgeb väravad
  170. }
  171. else if(V2ravadAvatud == 1) // Aga kui muutuja on 1 ehk värav on lahti, siis ta sulgeb väravad.
  172. {
  173. MoveObject(V2rav1, 969, -833.41528, 1430.92126, 12.90100, 0.00000, 0.00000, 90.30000, Kiirus); // Liigutab värava originaal asendisse (samadele kordinaatidele mis OnGameModeInit() alla lisasime
  174. V2ravadAvatud = 0; // Muudab muutuja tagasi 0 peale. Ehk kui järgime kord käsklust kasutada, näitab et värav on suletud ehk muutuja V2ravadAvatud == 1
  175. }
  176. return 1;
  177.  
  178. }
  179.  
  180.  
  181.  
  182. // This callback gets called when a player connects to the server
  183. public OnPlayerConnect(playerid)
  184. {
  185. // Always allow NPC's to login without password or account
  186. if (IsPlayerNPC(playerid))
  187. return 1;
  188.  
  189. // Setup local variables
  190. new Name[MAX_PLAYER_NAME], NewPlayerMsg[128], HouseID;
  191.  
  192. // Setup a PVar to allow cross-script money-transfers (only from filterscript to this mainscript) and scorepoints
  193. SetPVarInt(playerid, "PVarMoney", 0);
  194. SetPVarInt(playerid, "PVarScore", 0);
  195.  
  196. // Get the playername
  197. GetPlayerName(playerid, Name, sizeof(Name));
  198. // Also store this name for the player
  199. GetPlayerName(playerid, APlayerData[playerid][PlayerName], 24);
  200.  
  201. // Send a message to all players to let them know somebody else joined the server
  202. format(NewPlayerMsg, 128, TXT_PlayerJoinedServer, Name, playerid);
  203. SendClientMessageToAll(0xFFFFFFFF, NewPlayerMsg);
  204.  
  205. // Try to load the player's datafile ("PlayerFile_Load" returns "1" is the file has been read, "0" when the file cannot be read)
  206. if (PlayerFile_Load(playerid) == 1)
  207. {
  208. // Check if the player is still banned
  209. if (APlayerData[playerid][BanTime] < gettime()) // Player ban-time is passed
  210. ShowPlayerDialog(playerid, DialogLogin, DIALOG_STYLE_INPUT, TXT_DialogLoginTitle, TXT_DialogLoginMsg, TXT_DialogLoginButton1, TXT_DialogButtonCancel);
  211. else // Player is still banned
  212. {
  213. ShowRemainingBanTime(playerid); // Show the remaining ban-time to the player is days, hours, minutes, seconds
  214. Kick(playerid); // Kick the player
  215. }
  216. }
  217. else
  218. ShowPlayerDialog(playerid, DialogRegister, DIALOG_STYLE_INPUT, TXT_DialogRegisterTitle, TXT_DialogRegisterMsg, TXT_DialogRegisterButton1, TXT_DialogButtonCancel);
  219.  
  220. // The houses have been loaded but not the cars, so load all vehicles assigned to the player's houses
  221. for (new HouseSlot; HouseSlot < MAX_HOUSESPERPLAYER; HouseSlot++)
  222. {
  223. // Get the HouseID from this slot
  224. HouseID = APlayerData[playerid][Houses][HouseSlot];
  225. // Check if there is a house in this slot
  226. if (HouseID != 0)
  227. HouseFile_Load(HouseID, true); // Load the cars of the house
  228. }
  229.  
  230. // Speedometer setup
  231. Speedometer_Setup(playerid);
  232.  
  233. // MissionText TextDraw setup
  234. APlayerData[playerid][MissionText] = TextDrawCreate(320.0, 430.0, " "); // Setup the missiontext at the bottom of the screen
  235. TextDrawAlignment(APlayerData[playerid][MissionText], 2); // Align the missiontext to the center
  236. TextDrawUseBox(APlayerData[playerid][MissionText], 1); // Set the missiontext to display inside a box
  237. TextDrawBoxColor(APlayerData[playerid][MissionText], 0x00000066); // Set the box color of the missiontext
  238.  
  239. // Display a message if the player hasn't accepted the rules yet
  240. if (APlayerData[playerid][RulesRead] == false)
  241. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You haven't accepted the {FFFF00}/rules{FF0000} yet");
  242.  
  243. return 1;
  244. }
  245.  
  246.  
  247.  
  248. // This function shows the player how long his ban still is when he tries to login (in days, hours, minutes, seconds)
  249. ShowRemainingBanTime(playerid)
  250. {
  251. // Setup local variables
  252. new TotalBanTime, Days, Hours, Minutes, Seconds, Msg[128];
  253.  
  254. // Get the total ban-time
  255. TotalBanTime = APlayerData[playerid][BanTime] - gettime();
  256.  
  257. // Calculate days
  258. if (TotalBanTime >= 86400)
  259. {
  260. Days = TotalBanTime / 86400;
  261. TotalBanTime = TotalBanTime - (Days * 86400);
  262. }
  263. // Calculate hours
  264. if (TotalBanTime >= 3600)
  265. {
  266. Hours = TotalBanTime / 3600;
  267. TotalBanTime = TotalBanTime - (Hours * 3600);
  268. }
  269. // Calculate minutes
  270. if (TotalBanTime >= 60)
  271. {
  272. Minutes = TotalBanTime / 60;
  273. TotalBanTime = TotalBanTime - (Minutes * 60);
  274. }
  275. // Calculate seconds
  276. Seconds = TotalBanTime;
  277.  
  278. // Display the remaining ban-time for this player
  279. SendClientMessage(playerid, 0xFFFFFFFF, TXT_StillBanned);
  280. format(Msg, 128, TXT_BannedDuration, Days, Hours, Minutes, Seconds);
  281. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  282. }
  283.  
  284.  
  285.  
  286. // This callback gets called when a player disconnects from the server
  287. public OnPlayerDisconnect(playerid, reason)
  288. {
  289. // Always allow NPC's to logout without password or account
  290. if (IsPlayerNPC(playerid))
  291. return 1;
  292.  
  293. // Setup local variables
  294. new Name[24], Msg[128], HouseID;
  295.  
  296. // Get the playername
  297. GetPlayerName(playerid, Name, sizeof(Name));
  298.  
  299. // Stop spectate mode for all players who are spectating this player
  300. for (new i; i < MAX_PLAYERS; i++)
  301. if (IsPlayerConnected(i)) // Check if the player is connected
  302. if (GetPlayerState(i) == PLAYER_STATE_SPECTATING) // Check if this player is spectating somebody
  303. if (APlayerData[i][SpectateID] == playerid) // Check if this player is spectating me
  304. {
  305. TogglePlayerSpectating(i, 0); // Turn off spectate-mode
  306. APlayerData[i][SpectateID] = INVALID_PLAYER_ID;
  307. APlayerData[i][SpectateType] = ADMIN_SPEC_TYPE_NONE;
  308. SendClientMessage(i, 0xFFFFFFFF, "{FF0000}Target player has logged off, ending spectate mode");
  309. }
  310.  
  311. // Send a message to all players to let them know somebody left the server
  312. format(Msg, 128, TXT_PlayerLeftServer, Name, playerid);
  313. SendClientMessageToAll(0xFFFFFFFF, Msg);
  314.  
  315. // If the player entered a proper password (the player has an account)
  316. if (strlen(APlayerData[playerid][PlayerPassword]) != 0)
  317. {
  318. // Save the player data and his houses
  319. PlayerFile_Save(playerid);
  320. }
  321.  
  322. // Stop any job that may have started (this also clears all mission data)
  323. switch (APlayerData[playerid][PlayerClass])
  324. {
  325. case ClassTruckDriver: Trucker_EndJob(playerid); // Stop any trucker job
  326. case ClassBusDriver: BusDriver_EndJob(playerid); // Stop any busdriver job
  327. case ClassPilot: Pilot_EndJob(playerid); // Stop any pilot job
  328. case ClassPolice: Police_EndJob(playerid); // Stop any police job
  329. case ClassMafia: Mafia_EndJob(playerid); // Stop any mafia job
  330. case ClassAssistance: Assistance_EndJob(playerid);
  331. case ClassRoadWorker: Roadworker_EndJob(playerid);
  332. }
  333.  
  334. // If the player is part of a convoy, kick him from it
  335. Convoy_Leave(playerid);
  336.  
  337. // Unload all the player's house-vehicles to make room for other player's vehicles
  338. for (new HouseSlot; HouseSlot < MAX_HOUSESPERPLAYER; HouseSlot++)
  339. {
  340. // Get the HouseID from this slot
  341. HouseID = APlayerData[playerid][Houses][HouseSlot];
  342. // Check if there is a house in this slot
  343. if (HouseID != 0)
  344. {
  345. // Unload the cars of the house
  346. House_RemoveVehicles(HouseID);
  347. // Set the house so it cannot be entered by anyone (close the house)
  348. AHouseData[HouseID][HouseOpened] = false;
  349. }
  350. }
  351.  
  352. // Clear the data in the APlayerData array to make sure the next player with the same id doesn't hold wrong data
  353. APlayerData[playerid][SpectateID] = -1;
  354. APlayerData[playerid][SpectateVehicle] = -1;
  355. APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_NONE;
  356. APlayerData[playerid][LoggedIn] = false;
  357. APlayerData[playerid][AssistanceNeeded] = false;
  358. APlayerData[playerid][PlayerPassword] = 0;
  359. APlayerData[playerid][PlayerLevel] = 0;
  360. APlayerData[playerid][PlayerJailed] = 0;
  361. APlayerData[playerid][PlayerFrozen] = 0; // Clearing this variable automatically kills the frozentimer
  362. APlayerData[playerid][Bans] = 0;
  363. APlayerData[playerid][BanTime] = 0;
  364. APlayerData[playerid][Muted] = false;
  365. APlayerData[playerid][RulesRead] = false;
  366. APlayerData[playerid][AutoReportTime] = 0;
  367. APlayerData[playerid][TruckerLicense] = 0;
  368. APlayerData[playerid][BusLicense] = 0;
  369. APlayerData[playerid][PlayerClass] = 0;
  370. APlayerData[playerid][Warnings] = 0;
  371. APlayerData[playerid][PlayerMoney] = 0;
  372. APlayerData[playerid][PlayerScore] = 0;
  373. for (new HouseSlot; HouseSlot < MAX_HOUSESPERPLAYER; HouseSlot++)
  374. APlayerData[playerid][Houses][HouseSlot] = 0;
  375. for (new BusSlot; BusSlot < MAX_BUSINESSPERPLAYER; BusSlot++)
  376. APlayerData[playerid][Business][BusSlot] = 0;
  377. APlayerData[playerid][CurrentHouse] = 0;
  378.  
  379. // Clear bank account info
  380. APlayerData[playerid][BankPassword] = 0;
  381. APlayerData[playerid][BankLoggedIn] = false;
  382. APlayerData[playerid][BankMoney] = 0;
  383.  
  384. // Clear stats
  385. APlayerData[playerid][StatsTruckerJobs] = 0;
  386. APlayerData[playerid][StatsConvoyJobs] = 0;
  387. APlayerData[playerid][StatsBusDriverJobs] = 0;
  388. APlayerData[playerid][StatsPilotJobs] = 0;
  389. APlayerData[playerid][StatsMafiaJobs] = 0;
  390. APlayerData[playerid][StatsMafiaStolen] = 0;
  391. APlayerData[playerid][StatsPoliceFined] = 0;
  392. APlayerData[playerid][StatsPoliceJailed] = 0;
  393. APlayerData[playerid][StatsCourierJobs] = 0;
  394. APlayerData[playerid][StatsRoadworkerJobs] = 0;
  395. APlayerData[playerid][StatsAssistance] = 0;
  396. APlayerData[playerid][StatsMetersDriven] = 0.0;
  397.  
  398. // Clear police warnings
  399. APlayerData[playerid][PoliceCanJailMe] = false;
  400. APlayerData[playerid][PoliceWarnedMe] = false;
  401. APlayerData[playerid][Value_PoliceCanJailMe] = 0;
  402.  
  403. // Make sure the jailtimer has been destroyed
  404. KillTimer(APlayerData[playerid][PlayerJailedTimer]);
  405. KillTimer(APlayerData[playerid][Timer_PoliceCanJailMe]);
  406.  
  407. // Destroy the speedometer TextDraw for this player and the timer, also set the speed to 0
  408. Speedometer_Cleanup(playerid);
  409.  
  410. // Also destroy the missiontext TextDraw for this player
  411. TextDrawDestroy(APlayerData[playerid][MissionText]);
  412.  
  413. // Destroy a rented vehicle is the player had any
  414. if (APlayerData[playerid][RentedVehicleID] != 0)
  415. {
  416. // Clear the data for the already rented vehicle
  417. AVehicleData[APlayerData[playerid][RentedVehicleID]][Model] = 0;
  418. AVehicleData[APlayerData[playerid][RentedVehicleID]][Fuel] = 0;
  419. AVehicleData[APlayerData[playerid][RentedVehicleID]][Owned] = false;
  420. AVehicleData[APlayerData[playerid][RentedVehicleID]][Owner] = 0;
  421. AVehicleData[APlayerData[playerid][RentedVehicleID]][PaintJob] = 0;
  422. for (new j; j < 14; j++)
  423. {
  424. AVehicleData[APlayerData[playerid][RentedVehicleID]][Components][j] = 0;
  425. }
  426. // Destroy the vehicle
  427. DestroyVehicle(APlayerData[playerid][RentedVehicleID]);
  428. // Clear the RentedVehicleID
  429. APlayerData[playerid][RentedVehicleID] = 0;
  430. }
  431.  
  432. return 1;
  433. }
  434.  
  435.  
  436.  
  437. // This callback gets called whenever a player uses the chat-box
  438. public OnPlayerText(playerid, text[])
  439. {
  440. // Block the player's text if he has been muted
  441. if (APlayerData[playerid][Muted] == true)
  442. {
  443. // Let the player know he's still muted
  444. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You are still muted");
  445.  
  446. // Don't allow his text to be sent to the chatbox
  447. return 0;
  448. }
  449.  
  450. return 1;
  451. }
  452.  
  453.  
  454. // This callback gets called when a player interacts with a dialog
  455. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  456. {
  457. // Select the proper dialog to process
  458. switch (dialogid)
  459. {
  460. case DialogRegister: Dialog_Register(playerid, response, inputtext); // The "Register"-dialog
  461. case DialogLogin: Dialog_Login(playerid, response, inputtext); // The "Login"-dialog
  462.  
  463. case DialogStatsOtherPlayer: Dialog_StatsOtherPlayer(playerid, response, listitem);
  464. case DialogStatsHouse: Dialog_StatsHouse(playerid, response, listitem);
  465. case DialogStatsGoHouse: Dialog_StatsGoHouse(playerid, response, listitem);
  466. case DialogStatsGoBusiness: Dialog_StatsGoBusiness(playerid, response, listitem);
  467.  
  468. case DialogRescue: Dialog_Rescue(playerid, response, listitem); // The rescue-dialog
  469.  
  470. case DialogBuyLicenses: Dialog_BuyLicenses(playerid, response, listitem); // The license-dialog (allows the player to buy trucker/busdriver licenses)
  471.  
  472. case DialogRules: Dialog_Rules(playerid, response);
  473.  
  474. case DialogTruckerJobMethod: Dialog_TruckerSelectJobMethod(playerid, response, listitem); // The work-dialog for truckers (shows the loads he can carry and lets the player choose the load)
  475. case DialogTruckerSelectLoad: Dialog_TruckerSelectLoad(playerid, response, listitem); // The load-selection dialog for truckers (shows the startlocations for the selected load and let the player choose his startlocation)
  476. case DialogTruckerStartLoc: Dialog_TruckerSelectStartLoc(playerid, response, listitem); // The start-location dialog for truckers (shows the endlocations for the selected load and let the player choose his endlocation)
  477. case DialogTruckerEndLoc: Dialog_TruckerSelectEndLoc(playerid, response, listitem); // The end-location dialog for truckers (processes the selected endlocation and starts the job)
  478.  
  479. case DialogBusJobMethod: Dialog_BusSelectJobMethod(playerid, response, listitem); // The work-dialog for busdrivers (process the options to choose own busroute or auto-assigned busroute)
  480. case DialogBusSelectRoute: Dialog_BusSelectRoute(playerid, response, listitem); // Choose the busroute and start the job
  481.  
  482. case DialogCourierSelectQuant: Dialog_CourierSelectQuant(playerid, response, listitem);
  483.  
  484. case DialogBike: Dialog_Bike(playerid, response, listitem); // The bike-dialog
  485. case DialogCar: Dialog_Car(playerid, response, listitem); // The car-dialog (which uses a split dialog structure)
  486. case DialogPlane: Dialog_Plane(playerid, response, listitem); // The plane-dialog (which uses a split dialog structure)
  487. case DialogTrailer: Dialog_Trailer(playerid, response, listitem); // The trailer-dialog (which uses a split dialog structure)
  488. case DialogBoat: Dialog_Boat(playerid, response, listitem); // The boat-dialog
  489. case DialogNeon: Dialog_Neon(playerid, response, listitem); // The neon-dialog
  490.  
  491. case DialogRentCarClass: Dialog_RentProcessClass(playerid, response, listitem); // The player chose a vehicleclass from where he can rent a vehicle
  492. case DialogRentCar: Dialog_RentCar(playerid, response, listitem); // The player chose a vehicle from the list of vehicles from the vehicleclass he chose before
  493.  
  494. case DialogPlayerCommands: Dialog_PlayerCommands(playerid, response, listitem); // Displays all commands in a split-dialog structure
  495. case DialogPrimaryCarColor: Dialog_PrimaryCarColor(playerid, response, listitem);
  496. case DialogSedundaryCarColor: Dialog_SedundaryCarColor(playerid, response, listitem);
  497.  
  498. case DialogWeather: Dialog_Weather(playerid, response, listitem); // The weather dialog
  499. case DialogCarOption: Dialog_CarOption(playerid, response, listitem); // The caroption dialog
  500.  
  501. case DialogSelectConvoy: Dialog_SelectConvoy(playerid, response, listitem);
  502.  
  503. case DialogHouseMenu: Dialog_HouseMenu(playerid, response, listitem); // Process the main housemenu
  504. //case DialogUpgradeHouse: Dialog_UpgradeHouse(playerid, response, listitem); // Process the house-upgrade menu
  505. case DialogGoHome: Dialog_GoHome(playerid, response, listitem); // Port to one of your houses
  506. case DialogHouseNameChange: Dialog_ChangeHouseName(playerid, response, inputtext); // Change the name of your house
  507. case DialogSellHouse: Dialog_SellHouse(playerid, response); // Sell the house
  508. case DialogBuyCarClass: Dialog_BuyCarClass(playerid, response, listitem); // The player chose a vehicleclass from where he can buy a vehicle
  509. case DialogBuyCar: Dialog_BuyCar(playerid, response, listitem); // The player chose a vehicle from the list of vehicles from the vehicleclass he chose before
  510. case DialogSellCar: Dialog_SellCar(playerid, response, listitem);
  511. case DialogBuyInsurance: Dialog_BuyInsurance(playerid, response);
  512. case DialogGetCarSelectHouse: Dialog_GetCarSelectHouse(playerid, response, listitem);
  513. case DialogGetCarSelectCar: Dialog_GetCarSelectCar(playerid, response, listitem);
  514. case DialogUnclampVehicles: Dialog_UnclampVehicles(playerid, response);
  515.  
  516. case DialogCreateBusSelType: Dialog_CreateBusSelType(playerid, response, listitem);
  517. case DialogBusinessMenu: Dialog_BusinessMenu(playerid, response, listitem);
  518. case DialogGoBusiness: Dialog_GoBusiness(playerid, response, listitem);
  519. case DialogBusinessNameChange: Dialog_ChangeBusinessName(playerid, response, inputtext); // Change the name of your business
  520. case DialogSellBusiness: Dialog_SellBusiness(playerid, response); // Sell the business
  521.  
  522. case DialogBankPasswordRegister: Dialog_BankPasswordRegister(playerid, response, inputtext);
  523. case DialogBankPasswordLogin: Dialog_BankPasswordLogin(playerid, response, inputtext);
  524. case DialogBankOptions: Dialog_BankOptions(playerid, response, listitem);
  525. case DialogBankDeposit: Dialog_BankDeposit(playerid, response, inputtext);
  526. case DialogBankWithdraw: Dialog_BankWithdraw(playerid, response, inputtext);
  527. case DialogBankTransferMoney: Dialog_BankTransferMoney(playerid, response, inputtext);
  528. case DialogBankTransferName: Dialog_BankTransferName(playerid, response, inputtext);
  529. case DialogBankCancel: Dialog_BankCancel(playerid, response);
  530.  
  531. case DialogHelpItemChosen: Dialog_HelpItemChosen(playerid, response, listitem);
  532. case DialogHelpItem: Dialog_HelpItem(playerid, response);
  533.  
  534. case DialogOldPassword: Dialog_OldPassword(playerid, response, inputtext);
  535. case DialogNewPassword: Dialog_NewPassword(playerid, response, inputtext);
  536. case DialogConfirmPassword: Dialog_ConfirmPassword(playerid, response);
  537. }
  538.  
  539. return 1;
  540. }
  541.  
  542. // this callback gets called when a player clicks on another player on the scoreboard
  543. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  544. {
  545. // Check if the player is an admin of at least level 1
  546. if (APlayerData[playerid][PlayerLevel] >= 1)
  547. {
  548. // Setup local variables
  549. new Name[24], DialogTitle[128], PlayerStatList[3000], PlayerIP[16], NumHouses, NumBusinesses;
  550.  
  551. // Construct the dialog-title
  552. GetPlayerName(clickedplayerid, Name, sizeof(Name));
  553. format(DialogTitle, 128, "Statistics of player: %s", Name);
  554.  
  555. // Add the IP of the player to the list
  556. GetPlayerIp(clickedplayerid, PlayerIP, sizeof(PlayerIP));
  557. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Player-IP: {00FF00}%s\n", PlayerStatList, PlayerIP);
  558. // Add the level of the player to the list
  559. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Admin-level: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][PlayerLevel]);
  560. // Add the class of the player to the list
  561. switch(APlayerData[clickedplayerid][PlayerClass])
  562. {
  563. case ClassTruckDriver: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Trucker\n", PlayerStatList);
  564. case ClassBusDriver: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Bus driver\n", PlayerStatList);
  565. case ClassPilot: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Pilot\n", PlayerStatList);
  566. case ClassPolice: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Police\n", PlayerStatList);
  567. case ClassMafia: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Mafia\n", PlayerStatList);
  568. case ClassCourier: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Courier\n", PlayerStatList);
  569. case ClassAssistance: format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Class: {00FF00}Assistance\n", PlayerStatList);
  570. }
  571. // Add money and score of the player to the list
  572. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Money: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][PlayerMoney]);
  573. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Score: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][PlayerScore]);
  574. // Add wanted-level of the player to the list
  575. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Wanted-level: {00FF00}%i\n", PlayerStatList, GetPlayerWantedLevel(clickedplayerid));
  576. // Add truckerlicense and busdriver license of the player to the list
  577. if (APlayerData[clickedplayerid][TruckerLicense] == 1)
  578. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Trucker License: {00FF00}Yes\n", PlayerStatList);
  579. else
  580. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Trucker License: {00FF00}No\n", PlayerStatList);
  581.  
  582. if (APlayerData[clickedplayerid][BusLicense] == 1)
  583. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Bus License: {00FF00}Yes\n", PlayerStatList);
  584. else
  585. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Bus License: {00FF00}No\n", PlayerStatList);
  586.  
  587. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed trucker jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsTruckerJobs]);
  588. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed convoy jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsConvoyJobs]);
  589. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed busdriver jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsBusDriverJobs]);
  590. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed pilot jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsPilotJobs]);
  591. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed mafia jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsMafiaJobs]);
  592. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Stolen mafia-loads: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsMafiaStolen]);
  593. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Fined players: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsPoliceFined]);
  594. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Jailed players: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsPoliceJailed]);
  595. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed courier jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsCourierJobs]);
  596. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Completed roadworker jobs: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsRoadworkerJobs]);
  597. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Assisted players: {00FF00}%i\n", PlayerStatList, APlayerData[clickedplayerid][StatsAssistance]);
  598. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Meters driven: {00FF00}%f\n", PlayerStatList, APlayerData[clickedplayerid][StatsMetersDriven]);
  599.  
  600. // Count the number of houses/businesses that the player has and add them to the list
  601. for (new i; i < MAX_HOUSESPERPLAYER; i++)
  602. if (APlayerData[clickedplayerid][Houses][i] != 0)
  603. NumHouses++;
  604.  
  605. for (new i; i < MAX_BUSINESSPERPLAYER; i++)
  606. if (APlayerData[clickedplayerid][Business][i] != 0)
  607. NumBusinesses++;
  608.  
  609. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Houses: {00FF00}%i (double-click for stats)\n", PlayerStatList, NumHouses);
  610. format(PlayerStatList, sizeof(PlayerStatList), "%s{FFFFFF}Businesses: {00FF00}%i (double-click for stats)\n", PlayerStatList, NumBusinesses);
  611.  
  612. // Store the player-id of the other player so the other dialogs can display his statistics further (houses, businesses, cars)
  613. APlayerData[playerid][DialogOtherPlayer] = clickedplayerid;
  614.  
  615. // Show the statistics of the other player
  616. ShowPlayerDialog(playerid, DialogStatsOtherPlayer, DIALOG_STYLE_LIST, DialogTitle, PlayerStatList, TXT_DialogButtonSelect, TXT_DialogButtonCancel); // Let the player buy a license
  617. }
  618.  
  619. return 1;
  620. }
  621.  
  622.  
  623.  
  624. // This callback gets called when a player picks up any pickup
  625. public OnPlayerPickUpPickup(playerid, pickupid)
  626. {
  627. // If the player picks up the Buy_License pickup at the driving school in Doherty
  628. if (pickupid == Pickup_License)
  629. // Ask the player which license he wants to buy
  630. ShowPlayerDialog(playerid, DialogBuyLicenses, DIALOG_STYLE_LIST, TXT_DialogLicenseTitle, TXT_DialogLicenseList, TXT_DialogButtonBuy, TXT_DialogButtonCancel); // Let the player buy a license
  631.  
  632. return 1;
  633. }
  634.  
  635.  
  636.  
  637. // This callback gets called when a player spawns somewhere
  638. public OnPlayerSpawn(playerid)
  639. {
  640. // Always allow NPC's to spawn without logging in
  641. if (IsPlayerNPC(playerid))
  642. return 1;
  643.  
  644. // Check if the player properly logged in by typing his password
  645. if (APlayerData[playerid][LoggedIn] == false)
  646. {
  647. SendClientMessage(playerid, 0xFFFFFFFF, TXT_FailedLoginProperly);
  648. Kick(playerid); // Kick the player if he didn't log in properly
  649. }
  650.  
  651. // Setup local variables
  652. new missiontext[200];
  653.  
  654. // Spawn the player in the global world (where everybody plays the game)
  655. SetPlayerVirtualWorld(playerid, 0);
  656. SetPlayerInterior(playerid, 0);
  657. // Also set a variable that tracks in which house the player currently is
  658. APlayerData[playerid][CurrentHouse] = 0;
  659.  
  660. // Disable the clock
  661. TogglePlayerClock(playerid, 0);
  662.  
  663. // Delete all weapons from the player
  664. ResetPlayerWeapons(playerid);
  665.  
  666. // Set the missiontext based on the chosen class
  667. switch (APlayerData[playerid][PlayerClass])
  668. {
  669. case ClassTruckDriver: // Truck-driver class
  670. {
  671. format(missiontext, sizeof(missiontext), Trucker_NoJobText); // Preset the missiontext
  672. SetPlayerColor(playerid, ColorClassTruckDriver); // Set the playercolor (chatcolor for the player and color on the map)
  673. }
  674. case ClassBusDriver: // Bus-driver class
  675. {
  676. format(missiontext, sizeof(missiontext), BusDriver_NoJobText); // Preset the missiontext
  677. SetPlayerColor(playerid, ColorClassBusDriver); // Set the playercolor (chatcolor for the player and color on the map)
  678. }
  679. case ClassPilot: // Pilot class
  680. {
  681. format(missiontext, sizeof(missiontext), Pilot_NoJobText); // Preset the missiontext
  682. SetPlayerColor(playerid, ColorClassPilot); // Set the playercolor (chatcolor for the player and color on the map)
  683. }
  684. case ClassPolice: // Police class
  685. {
  686. format(missiontext, sizeof(missiontext), Police_NoJobText); // Preset the missiontext
  687. SetPlayerColor(playerid, ColorClassPolice); // Set the playercolor (chatcolor for the player and color on the map)
  688. // Start the PlayerCheckTimer to scan for wanted players (be sure the timer has been destroyed first)
  689. KillTimer(APlayerData[playerid][PlayerCheckTimer]);
  690. APlayerData[playerid][PlayerCheckTimer] = SetTimerEx("Police_CheckWantedPlayers", 1000, true, "i", playerid);
  691. // Check if the police player can get weapons
  692. if (PoliceGetsWeapons == true)
  693. {
  694. // Give up to 12 weapons to the player
  695. for (new i; i < 12; i++)
  696. GivePlayerWeapon(playerid, APoliceWeapons[i], PoliceWeaponsAmmo);
  697. }
  698. }
  699. case ClassMafia: // Mafia class
  700. {
  701. format(missiontext, sizeof(missiontext), Mafia_NoJobText); // Preset the missiontext
  702. SetPlayerColor(playerid, ColorClassMafia); // Set the playercolor (chatcolor for the player and color on the map)
  703. // Start the PlayerCheckTimer to scan for players that carry mafia-loads (be sure the timer has been destroyed first)
  704. KillTimer(APlayerData[playerid][PlayerCheckTimer]);
  705. APlayerData[playerid][PlayerCheckTimer] = SetTimerEx("Mafia_CheckMafiaLoads", 1000, true, "i", playerid);
  706. }
  707. case ClassCourier: // Courier class
  708. {
  709. format(missiontext, sizeof(missiontext), Courier_NoJobText); // Preset the missiontext
  710. SetPlayerColor(playerid, ColorClassCourier); // Set the playercolor (chatcolor for the player and color on the map)
  711. }
  712. case ClassAssistance: // Assistance class
  713. {
  714. format(missiontext, sizeof(missiontext), Assistance_NoJobText); // Preset the missiontext
  715. SetPlayerColor(playerid, ColorClassAssistance); // Set the playercolor (chatcolor for the player and color on the map)
  716. // Start the PlayerCheckTimer to scan for players who need assistance (be sure the timer has been destroyed first)
  717. KillTimer(APlayerData[playerid][PlayerCheckTimer]);
  718. APlayerData[playerid][PlayerCheckTimer] = SetTimerEx("Assistance_CheckPlayers", 1000, true, "i", playerid);
  719. }
  720. case ClassRoadWorker: // Roadworker class
  721. {
  722. format(missiontext, sizeof(missiontext), RoadWorker_NoJobText); // Preset the missiontext
  723. SetPlayerColor(playerid, ColorClassRoadWorker); // Set the playercolor (chatcolor for the player and color on the map)
  724. }
  725. }
  726.  
  727. // Set the missiontext
  728. TextDrawSetString(APlayerData[playerid][MissionText], missiontext);
  729. // Show the missiontext for this player
  730. TextDrawShowForPlayer(playerid, APlayerData[playerid][MissionText]);
  731.  
  732. // If the player spawns and his jailtime hasn't passed yet, put him back in jail
  733. if (APlayerData[playerid][PlayerJailed] != 0)
  734. Police_JailPlayer(playerid, APlayerData[playerid][PlayerJailed]);
  735.  
  736. return 1;
  737. }
  738.  
  739.  
  740.  
  741. // This callback gets called whenever a player enters a checkpoint
  742. public OnPlayerEnterCheckpoint(playerid)
  743. {
  744. // Check the player's class
  745. switch (APlayerData[playerid][PlayerClass])
  746. {
  747. case ClassTruckDriver: // Truckdriver class
  748. Trucker_OnPlayerEnterCheckpoint(playerid); // Process the checkpoint (load or unload goods)
  749. case ClassBusDriver: // BusDriver class
  750. {
  751. GameTextForPlayer(playerid, TXT_BusDriverMissionPassed, 3000, 4); // Show a message to let the player know he finished his job
  752. BusDriver_EndJob(playerid); // End the current mission
  753. }
  754. case ClassPilot: // Pilot class
  755. Pilot_OnPlayerEnterCheckpoint(playerid); // Process the checkpoint (load or unload)
  756. case ClassMafia: // Mafia class
  757. Mafia_OnPlayerEnterCheckpoint(playerid);
  758. case ClassCourier: // Courier class
  759. Courier_OnPlayerEnterCheckpoint(playerid);
  760. case ClassRoadWorker: // Roadworker class
  761. {
  762. // Only end the mission when doing "repair-speedcamera" jobtype (checkpoint is the base of the roadworker)
  763. if (APlayerData[playerid][JobID] == 1) // Repairing speedcamera's
  764. {
  765. GameTextForPlayer(playerid, TXT_RoadworkerMissionPassed, 3000, 4); // Show a message to let the player know he finished his job
  766. Roadworker_EndJob(playerid); // End the current mission
  767. }
  768. if (APlayerData[playerid][JobID] == 2) // Towing broken vehicle to shredder
  769. Roadworker_EnterCheckpoint(playerid);
  770. }
  771. }
  772.  
  773. return 1;
  774. }
  775.  
  776.  
  777.  
  778. // This callback gets called when a player enters a race-checkpoint
  779. public OnPlayerEnterRaceCheckpoint(playerid)
  780. {
  781. // Check the player's class
  782. switch (APlayerData[playerid][PlayerClass])
  783. {
  784. case ClassBusDriver: // BusDriver class
  785. Bus_EnterRaceCheckpoint(playerid); // Process the checkpoint
  786. case ClassRoadWorker: // Roadworker class
  787. Roadworker_EnterRaceCheckpoint(playerid);
  788. }
  789.  
  790. return 1;
  791. }
  792.  
  793.  
  794.  
  795. // This callback gets called whenever a player dies
  796. public OnPlayerDeath(playerid, killerid, reason)
  797. {
  798. // Setup local variables
  799. new VictimName[24], KillerName[24], Msg[128];
  800.  
  801. // Clear the missiontext
  802. TextDrawSetString(APlayerData[playerid][MissionText], " ");
  803. // Hide the missiontext for this player (when the player is choosing a class, it's not required to show any mission-text)
  804. TextDrawHideForPlayer(playerid, APlayerData[playerid][MissionText]);
  805.  
  806. // Stop any job that may have started
  807. switch (APlayerData[playerid][PlayerClass])
  808. {
  809. case ClassTruckDriver: Trucker_EndJob(playerid);
  810. case ClassBusDriver: BusDriver_EndJob(playerid);
  811. case ClassPilot: Pilot_EndJob(playerid);
  812. case ClassPolice: Police_EndJob(playerid);
  813. case ClassMafia: Mafia_EndJob(playerid);
  814. case ClassCourier: Courier_EndJob(playerid);
  815. case ClassAssistance: Assistance_EndJob(playerid);
  816. case ClassRoadWorker: Roadworker_EndJob(playerid);
  817. }
  818.  
  819. // If the player is part of a convoy, kick him from it
  820. Convoy_Leave(playerid);
  821.  
  822. // If another player kills you, he'll get an extra star of his wanted level
  823. if (killerid != INVALID_PLAYER_ID)
  824. {
  825. // Increase the wanted level of the killer by one star
  826. SetPlayerWantedLevel(killerid, GetPlayerWantedLevel(killerid) + 1);
  827. // Get the name of the killed player and the killer
  828. GetPlayerName(playerid, VictimName, sizeof(VictimName));
  829. GetPlayerName(killerid, KillerName, sizeof(KillerName));
  830. // Let the killed know the police are informed about the kill
  831. format(Msg, 128, "{FF0000}You've killed {FFFF00}%s{FF0000}, you're wanted by the police now", VictimName);
  832. SendClientMessage(killerid, 0xFFFFFFFF, Msg);
  833. // Inform all police players about the kill
  834. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} killed {FFFF00}%s{00FF00}, pursue and fine him", KillerName, VictimName);
  835. Police_SendMessage(Msg);
  836. }
  837.  
  838. return 1;
  839. }
  840.  
  841.  
  842.  
  843. // This callback gets called when the player is selecting a class (but hasn't clicked "Spawn" yet)
  844. public OnPlayerRequestClass(playerid, classid)
  845. {
  846. SetPlayerInterior(playerid,14);
  847. SetPlayerPos(playerid,258.4893,-41.4008,1002.0234);
  848. SetPlayerFacingAngle(playerid, 270.0);
  849. SetPlayerCameraPos(playerid,256.0815,-43.0475,1004.0234);
  850. SetPlayerCameraLookAt(playerid,258.4893,-41.4008,1002.0234);
  851.  
  852. // Display a short message to inform the player about the class he's about to choose
  853. switch (classid)
  854. {
  855. case 0, 1, 2, 3, 4, 5, 6, 7: // Classes that will be truckdrivers
  856. {
  857. // Display the name of the class
  858. GameTextForPlayer(playerid, TXT_ClassTrucker, 3000, 4);
  859. // Store the class for the player (truckdriver)
  860. APlayerData[playerid][PlayerClass] = ClassTruckDriver;
  861. }
  862. case 8, 9: // Classes that will be bus-drivers
  863. {
  864. // Display the name of the class
  865. GameTextForPlayer(playerid, TXT_ClassBusDriver, 3000, 4);
  866. // Store the class for the player (busdriver)
  867. APlayerData[playerid][PlayerClass] = ClassBusDriver;
  868. }
  869. case 10: // Classes that will be Pilot
  870. {
  871. // Display the name of the class
  872. GameTextForPlayer(playerid, TXT_ClassPilot, 3000, 4);
  873. // Store the class for the player (pilot)
  874. APlayerData[playerid][PlayerClass] = ClassPilot;
  875. }
  876. case 11, 12, 13: // Classes that will be police
  877. {
  878. // Display the name of the class
  879. GameTextForPlayer(playerid, TXT_ClassPolice, 3000, 4);
  880. // Store the class for the player (police)
  881. APlayerData[playerid][PlayerClass] = ClassPolice;
  882. }
  883. case 14, 15, 16: // Classes that will be mafia
  884. {
  885. // Display the name of the class
  886. GameTextForPlayer(playerid, TXT_ClassMafia, 3000, 4);
  887. // Store the class for the player (mafia)
  888. APlayerData[playerid][PlayerClass] = ClassMafia;
  889. }
  890. case 17, 18: // Classes that will be courier
  891. {
  892. // Display the name of the class
  893. GameTextForPlayer(playerid, TXT_ClassCourier, 3000, 4);
  894. // Store the class for the player (courier)
  895. APlayerData[playerid][PlayerClass] = ClassCourier;
  896. }
  897. case 19: // Classes that will be assistance
  898. {
  899. // Display the name of the class
  900. GameTextForPlayer(playerid, TXT_ClassAssistance, 3000, 4);
  901. // Store the class for the player (assistance)
  902. APlayerData[playerid][PlayerClass] = ClassAssistance;
  903. }
  904. case 20, 21, 22: // Classes that will be roadworker
  905. {
  906. // Display the name of the class
  907. GameTextForPlayer(playerid, TXT_ClassRoadWorker, 3000, 4);
  908. // Store the class for the player (roadworker)
  909. APlayerData[playerid][PlayerClass] = ClassRoadWorker;
  910. }
  911. }
  912.  
  913. return 1;
  914. }
  915.  
  916.  
  917.  
  918. // This callback is called when the player attempts to spawn via class-selection
  919. public OnPlayerRequestSpawn(playerid)
  920. {
  921. new Index, Float:x, Float:y, Float:z, Float:Angle, Name[24], Msg[128];
  922.  
  923. // Get the player's name
  924. GetPlayerName(playerid, Name, sizeof(Name));
  925.  
  926. // Choose a random spawnlocation based on the player's class
  927. switch (APlayerData[playerid][PlayerClass])
  928. {
  929. case ClassTruckDriver:
  930. {
  931. Index = random(sizeof(ASpawnLocationsTrucker)); // Get a random array-index to chose a random spawnlocation
  932. x = ASpawnLocationsTrucker[Index][SpawnX]; // Get the X-position for the spawnlocation
  933. y = ASpawnLocationsTrucker[Index][SpawnY]; // Get the Y-position for the spawnlocation
  934. z = ASpawnLocationsTrucker[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  935. Angle = ASpawnLocationsTrucker[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  936. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Trucker class", Name);
  937. }
  938. case ClassBusDriver:
  939. {
  940. Index = random(sizeof(ASpawnLocationsBusDriver));
  941. x = ASpawnLocationsBusDriver[Index][SpawnX]; // Get the X-position for the spawnlocation
  942. y = ASpawnLocationsBusDriver[Index][SpawnY]; // Get the Y-position for the spawnlocation
  943. z = ASpawnLocationsBusDriver[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  944. Angle = ASpawnLocationsBusDriver[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  945. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Busdriver class", Name);
  946. }
  947. case ClassPilot:
  948. {
  949. Index = random(sizeof(ASpawnLocationsPilot));
  950. x = ASpawnLocationsPilot[Index][SpawnX]; // Get the X-position for the spawnlocation
  951. y = ASpawnLocationsPilot[Index][SpawnY]; // Get the Y-position for the spawnlocation
  952. z = ASpawnLocationsPilot[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  953. Angle = ASpawnLocationsPilot[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  954. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Pilot class", Name);
  955. }
  956. case ClassPolice:
  957. {
  958. // Count the number of normal players (all classes except police) and count the amount of police players
  959. new NormalPlayers, PolicePlayers, bool:CanSpawnAsCop = false;
  960.  
  961. // Block this check if PlayersBeforePolice is set to 0 (this allows anyone to join as police)
  962. if (PlayersBeforePolice > 0)
  963. {
  964. // Loop through all players
  965. for (new pid; pid < MAX_PLAYERS; pid++)
  966. {
  967. // Exclude this player, as he doesn't have a class yet, he's still choosing here
  968. if (pid != playerid)
  969. {
  970. // Also exclude all players who are still in the class-selection screen, as they don't have a class selected yet
  971. if (GetPlayerInterior(pid) != 14)
  972. {
  973. // Check if this player is logged in
  974. if (APlayerData[pid][LoggedIn] == true)
  975. {
  976. // Count the amount of normal players and police players
  977. switch (APlayerData[pid][PlayerClass])
  978. {
  979. case ClassPolice:
  980. PolicePlayers++;
  981. case ClassTruckDriver, ClassBusDriver, ClassPilot, ClassMafia, ClassCourier, ClassAssistance, ClassRoadWorker:
  982. NormalPlayers++;
  983. }
  984. }
  985. }
  986. }
  987. }
  988. // Check if there are less police players than allowed
  989. if (PolicePlayers < (NormalPlayers / PlayersBeforePolice))
  990. CanSpawnAsCop = true; // There are less police players than allowed, so the player can choose this class
  991. else
  992. CanSpawnAsCop = false; // The maximum amount of police players has been reached, the player can't choose to be a cop
  993.  
  994. // Check if the player isn't allowed to spawn as police
  995. if (CanSpawnAsCop == false)
  996. {
  997. // Let the player know the maximum amount of cops has been reached
  998. GameTextForPlayer(playerid, "Maximum amount of cops already reached", 5000, 4);
  999. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}The maximum amount of cops has been reached already, please select another class");
  1000. return 0; // Don't allow the player to spawn as police player
  1001. }
  1002. }
  1003.  
  1004. // If the player has less than 100 scorepoints
  1005. if (APlayerData[playerid][PlayerScore] < 100)
  1006. {
  1007. // Let the player know he needs 100 scorepoints
  1008. GameTextForPlayer(playerid, "You need 100 scorepoints for police class", 5000, 4);
  1009. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need 100 scorepoints for police class");
  1010. return 0; // Don't allow the player to spawn as police player
  1011. }
  1012. // If the player has a wanted level
  1013. if (GetPlayerWantedLevel(playerid) > 0)
  1014. {
  1015. // Let the player know he cannot have a wanted level to join police
  1016. GameTextForPlayer(playerid, "You are not allowed to choose police class when you're wanted", 5000, 4);
  1017. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You are not allowed to choose police class when you're wanted");
  1018. return 0; // Don't allow the player to spawn as police player
  1019. }
  1020.  
  1021. Index = random(sizeof(ASpawnLocationsPolice));
  1022. x = ASpawnLocationsPolice[Index][SpawnX]; // Get the X-position for the spawnlocation
  1023. y = ASpawnLocationsPolice[Index][SpawnY]; // Get the Y-position for the spawnlocation
  1024. z = ASpawnLocationsPolice[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  1025. Angle = ASpawnLocationsPolice[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  1026. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Police class", Name);
  1027. }
  1028. case ClassMafia:
  1029. {
  1030. Index = random(sizeof(ASpawnLocationsMafia));
  1031. x = ASpawnLocationsMafia[Index][SpawnX]; // Get the X-position for the spawnlocation
  1032. y = ASpawnLocationsMafia[Index][SpawnY]; // Get the Y-position for the spawnlocation
  1033. z = ASpawnLocationsMafia[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  1034. Angle = ASpawnLocationsMafia[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  1035. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Mafia class", Name);
  1036. }
  1037. case ClassCourier:
  1038. {
  1039. Index = random(sizeof(ASpawnLocationsCourier));
  1040. x = ASpawnLocationsCourier[Index][SpawnX]; // Get the X-position for the spawnlocation
  1041. y = ASpawnLocationsCourier[Index][SpawnY]; // Get the Y-position for the spawnlocation
  1042. z = ASpawnLocationsCourier[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  1043. Angle = ASpawnLocationsCourier[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  1044. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Courier class", Name);
  1045. }
  1046. case ClassAssistance:
  1047. {
  1048. Index = random(sizeof(ASpawnLocationsAssistance));
  1049. x = ASpawnLocationsAssistance[Index][SpawnX]; // Get the X-position for the spawnlocation
  1050. y = ASpawnLocationsAssistance[Index][SpawnY]; // Get the Y-position for the spawnlocation
  1051. z = ASpawnLocationsAssistance[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  1052. Angle = ASpawnLocationsAssistance[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  1053. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Assistance class", Name);
  1054. }
  1055. case ClassRoadWorker:
  1056. {
  1057. Index = random(sizeof(ASpawnLocationsRoadWorker));
  1058. x = ASpawnLocationsRoadWorker[Index][SpawnX]; // Get the X-position for the spawnlocation
  1059. y = ASpawnLocationsRoadWorker[Index][SpawnY]; // Get the Y-position for the spawnlocation
  1060. z = ASpawnLocationsRoadWorker[Index][SpawnZ]; // Get the Z-position for the spawnlocation
  1061. Angle = ASpawnLocationsRoadWorker[Index][SpawnAngle]; // Get the rotation-angle for the spawnlocation
  1062. format(Msg, 128, "{00FF00}Player {FFFF00}%s{00FF00} joined {FFFF00}Roadworker class", Name);
  1063. }
  1064. }
  1065.  
  1066. // Spawn the player with his chosen skin at a random location based on his class
  1067. SetSpawnInfo(playerid, 0, GetPlayerSkin(playerid), x, y, z, Angle, 0, 0, 0, 0, 0, 0);
  1068. // Send the message to all players (who joined which class)
  1069. SendClientMessageToAll(0xFFFFFFFF, Msg);
  1070.  
  1071. return 1;
  1072. }
  1073.  
  1074.  
  1075.  
  1076. // This callback gets called when a vehicle respawns at it's spawn-location (where it was created)
  1077. public OnVehicleSpawn(vehicleid)
  1078. {
  1079. // Set the vehicle as not-wanted by the mafia
  1080. AVehicleData[vehicleid][MafiaLoad] = false;
  1081. // Also reset the fuel to maximum (only for non-owned vehicles)
  1082. if (AVehicleData[vehicleid][Owned] == false)
  1083. AVehicleData[vehicleid][Fuel] = MaxFuel;
  1084.  
  1085. // Re-apply the paintjob (if any was applied)
  1086. if (AVehicleData[vehicleid][PaintJob] != 0)
  1087. {
  1088. // Re-apply the paintjob
  1089. ChangeVehiclePaintjob(vehicleid, AVehicleData[vehicleid][PaintJob] - 1);
  1090. }
  1091.  
  1092. // Also update the car-color
  1093. ChangeVehicleColor(vehicleid, AVehicleData[vehicleid][Color1], AVehicleData[vehicleid][Color2]);
  1094.  
  1095. // Re-add all components that were installed (if they were there)
  1096. for (new i; i < 14; i++)
  1097. {
  1098. // Remove all mods from the vehicle (all added mods applied by hackers will hopefully be removed this way when the vehicle respawns)
  1099. RemoveVehicleComponent(vehicleid, GetVehicleComponentInSlot(vehicleid, i));
  1100.  
  1101. // Check if the componentslot has a valid component-id
  1102. if (AVehicleData[vehicleid][Components][i] != 0)
  1103. AddVehicleComponent(vehicleid, AVehicleData[vehicleid][Components][i]); // Add the component to the vehicle
  1104. }
  1105.  
  1106. return 1;
  1107. }
  1108.  
  1109.  
  1110.  
  1111. // This callback is called when the vehicle leaves a mod shop
  1112. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  1113. {
  1114. // Let the player pay $150 for changing the color (if they have been changed)
  1115. if ((AVehicleData[vehicleid][Color1] != color1) || (AVehicleData[vehicleid][Color2] != color2))
  1116. {
  1117. RewardPlayer(playerid, -150, 0);
  1118. SendClientMessage(playerid, 0xFFFFFFFF, "{00FF00}You've changed the color of your vehicle for $150");
  1119. }
  1120.  
  1121. // Save the colors
  1122. AVehicleData[vehicleid][Color1] = color1;
  1123. AVehicleData[vehicleid][Color2] = color2;
  1124.  
  1125. // If the primary color is black, remove the paintjob
  1126. if (color1 == 0)
  1127. AVehicleData[vehicleid][PaintJob] = 0;
  1128.  
  1129. return 1;
  1130. }
  1131.  
  1132.  
  1133.  
  1134. // This callback gets called when a player enters or exits a mod-shop
  1135. public OnEnterExitModShop(playerid, enterexit, interiorid)
  1136. {
  1137. return 1;
  1138. }
  1139.  
  1140.  
  1141.  
  1142. // This callback gets called whenever a player mods his vehicle
  1143. public OnVehicleMod(playerid, vehicleid, componentid)
  1144. {
  1145. // When the player changes a component of his vehicle, reduce the price of the component from the player's money
  1146. APlayerData[playerid][PlayerMoney] = APlayerData[playerid][PlayerMoney] - AVehicleModPrices[componentid - 1000];
  1147.  
  1148. // Store the component in the AVehicleData array
  1149. AVehicleData[vehicleid][Components][GetVehicleComponentType(componentid)] = componentid;
  1150.  
  1151. return 1;
  1152. }
  1153.  
  1154.  
  1155.  
  1156. // This callback gets called whenever a player VIEWS at a paintjob in a mod garage (viewing automatically applies it)
  1157. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  1158. {
  1159. // Store the paintjobid for the vehicle (add 1 to the value, otherwise checking for an applied paintjob is difficult)
  1160. AVehicleData[vehicleid][PaintJob] = paintjobid + 1;
  1161.  
  1162. return 1;
  1163. }
  1164.  
  1165.  
  1166.  
  1167. // This callback gets called whenever a player enters a vehicle
  1168. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  1169. {
  1170. // Setup local variables
  1171. new engine, lights, alarm, doors, bonnet, boot, objective;
  1172.  
  1173. // Check if the vehicle has fuel
  1174. if (AVehicleData[vehicleid][Fuel] > 0)
  1175. {
  1176. // Start the engine and turn on the lights
  1177. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  1178. SetVehicleParamsEx(vehicleid, 1, 1, alarm, doors, bonnet, boot, objective);
  1179. }
  1180.  
  1181. // Store the player's current location and interior-id, otherwise anti-airbreak hack code could kick you
  1182. GetPlayerPos(playerid, APlayerData[playerid][PreviousX], APlayerData[playerid][PreviousY], APlayerData[playerid][PreviousZ]);
  1183. APlayerData[playerid][PreviousInt] = GetPlayerInterior(playerid);
  1184.  
  1185. return 1;
  1186. }
  1187.  
  1188.  
  1189.  
  1190. // This callback gets called when a player exits his vehicle
  1191. public OnPlayerExitVehicle(playerid, vehicleid)
  1192. {
  1193. // Setup local variables
  1194. new engine, lights, alarm, doors, bonnet, boot, objective;
  1195.  
  1196. // Check if the player is the driver of the vehicle
  1197. if (GetPlayerVehicleSeat(playerid) == 0)
  1198. {
  1199. // Turn off the lights and engine
  1200. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  1201. SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
  1202. }
  1203.  
  1204. // Chech if the player is a pilot
  1205. if (APlayerData[playerid][PlayerClass] == ClassPilot)
  1206. {
  1207. // If the pilot started a job --> as soon as a pilot leaves his plane while doing a job, he fails his mission
  1208. if (APlayerData[playerid][JobStarted] == true)
  1209. {
  1210. // End the job (clear data)
  1211. Pilot_EndJob(playerid);
  1212. // Inform the player that he failed the mission
  1213. GameTextForPlayer(playerid, TXT_FailedMission, 5000, 4);
  1214. // Reduce the player's cash by 1000
  1215. RewardPlayer(playerid, -1000, 0);
  1216. }
  1217. }
  1218.  
  1219. return 1;
  1220. }
  1221.  
  1222.  
  1223.  
  1224. // This callback gets called whenever a vehicle enters the water or is destroyed (explodes)
  1225. public OnVehicleDeath(vehicleid)
  1226. {
  1227. // Get the houseid to which this vehicle belongs
  1228. new HouseID = AVehicleData[vehicleid][BelongsToHouse];
  1229.  
  1230. // Check if this vehicle belongs to a house
  1231. if (HouseID != 0)
  1232. {
  1233. // If the house doesn't have insurance for it's vehicles
  1234. if (AHouseData[HouseID][Insurance] == 0)
  1235. {
  1236. // Delete the vehicle, clear the data and remove it from the house it belongs to
  1237. Vehicle_Delete(vehicleid);
  1238.  
  1239. // Save the house (and linked vehicles)
  1240. HouseFile_Save(HouseID);
  1241. }
  1242. }
  1243.  
  1244. return 1;
  1245. }
  1246.  
  1247.  
  1248.  
  1249. // This callback gets called when the player changes state
  1250. public OnPlayerStateChange(playerid,newstate,oldstate)
  1251. {
  1252. // Setup local variables
  1253. new vid, Name[24], Msg[128], engine, lights, alarm, doors, bonnet, boot, objective;
  1254.  
  1255. switch (newstate)
  1256. {
  1257. case PLAYER_STATE_DRIVER: // Player became the driver of a vehicle
  1258. {
  1259. // Get the ID of the player's vehicle
  1260. vid = GetPlayerVehicleID(playerid);
  1261. // Get the player's name (the one who is trying to enter the vehicle)
  1262. GetPlayerName(playerid, Name, sizeof(Name));
  1263.  
  1264. // Check if the vehicle is owned
  1265. if (AVehicleData[vid][Owned] == true)
  1266. {
  1267. // Check if the vehicle is owned by somebody else (strcmp will not be 0)
  1268. if (strcmp(AVehicleData[vid][Owner], Name, false) != 0)
  1269. {
  1270. // Force the player out of the vehicle
  1271. RemovePlayerFromVehicle(playerid);
  1272. // Turn off the lights and engine
  1273. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  1274. SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
  1275. // Let the player know he cannot use somebody else's vehicle
  1276. format(Msg, 128, TXT_SpeedometerCannotUseVehicle, AVehicleData[vid][Owner]);
  1277. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  1278. }
  1279.  
  1280. // Check if the vehicle is clamped
  1281. if (AVehicleData[vid][Clamped] == true)
  1282. {
  1283. // Force the player out of the vehicle
  1284. RemovePlayerFromVehicle(playerid);
  1285. // Turn off the lights and engine
  1286. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  1287. SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
  1288. // Let the player know he cannot use a clamped vehicle
  1289. format(Msg, 128, TXT_SpeedometerClampedVehicle);
  1290. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  1291. format(Msg, 128, TXT_SpeedometerClampedVehicle2);
  1292. SendClientMessage(playerid, 0xFFFFFFFF, Msg);
  1293. }
  1294. }
  1295.  
  1296. // Check if the player is not a cop
  1297. if (APlayerData[playerid][PlayerClass] != ClassPolice)
  1298. {
  1299. // First check if the vehicle is a static vehicle (player can still use a bought cop-car that he bought in his house,
  1300. // as a bought vehicle isn't static)
  1301. if (AVehicleData[vid][StaticVehicle] == true)
  1302. {
  1303. // Check if the entered vehicle is a cop vehicle
  1304. switch (GetVehicleModel(vid))
  1305. {
  1306. case VehiclePoliceLSPD, VehiclePoliceSFPD, VehiclePoliceLVPD, VehicleHPV1000, VehiclePoliceRanger:
  1307. {
  1308. // Force the player out of the vehicle
  1309. RemovePlayerFromVehicle(playerid);
  1310. // Turn off the lights and engine
  1311. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  1312. SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
  1313. // Let the player know he cannot use a cop car
  1314. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use a police vehicle");
  1315. }
  1316. }
  1317. }
  1318. }
  1319.  
  1320. // Check if the player is not a pilot
  1321. if (APlayerData[playerid][PlayerClass] != ClassPilot)
  1322. {
  1323. // First check if the vehicle is a static vehicle (player can still use a bought plane that he bought in his house,
  1324. // as a bought vehicle isn't static)
  1325. if (AVehicleData[vid][StaticVehicle] == true)
  1326. {
  1327. // Check if the entered vehicle is a plane or helicopter vehicle
  1328. switch (GetVehicleModel(vid))
  1329. {
  1330. case VehicleShamal, VehicleNevada, VehicleStuntPlane, VehicleDodo, VehicleMaverick, VehicleCargobob:
  1331. {
  1332. // Force the player out of the vehicle
  1333. RemovePlayerFromVehicle(playerid);
  1334. // Turn off the lights and engine
  1335. GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
  1336. SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
  1337. // Let the player know he cannot use a cop car
  1338. SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use a pilot vehicle");
  1339. }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345.  
  1346. return 1;
  1347. }
  1348.  
  1349.  
  1350.  
  1351. // This callback gets called whenever a player presses a key
  1352. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  1353. {
  1354. // Debug the keypresses
  1355. // DebugKeys(playerid, newkeys, oldkeys);
  1356.  
  1357. // ****************************************************************************************
  1358. // NOTE: the keys are messed up, so the code may look strange when testing for certain keys
  1359. // ****************************************************************************************
  1360.  
  1361. // Fining and jailing players when you're police and press the correct keys
  1362. // Check the class of the player
  1363. switch (APlayerData[playerid][PlayerClass])
  1364. {
  1365. case ClassPolice:
  1366. {
  1367. // If the police-player pressed the RMB key (AIM key) when OUTSIDE his vehicle
  1368. if (((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE)) && (GetPlayerVehicleID(playerid) == 0))
  1369. Police_FineNearbyPlayers(playerid);
  1370.  
  1371. // If the police-player pressed the LCTRL (SECUNDAIRY key) key when INSIDE his vehicle
  1372. if (((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION)) && (GetPlayerVehicleID(playerid) != 0))
  1373. Police_WarnNearbyPlayers(playerid);
  1374. }
  1375. case ClassAssistance:
  1376. {
  1377. // If the assistance-player pressed the RMB key (AIM key) when OUTSIDE his vehicle
  1378. if (((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE)) && (GetPlayerVehicleID(playerid) == 0))
  1379. Assistance_FixVehicle(playerid);
  1380.  
  1381. // If the police-player pressed the LCTRL (SECUNDAIRY key) key when INSIDE his vehicle
  1382. if (((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION)) && (GetPlayerVehicleID(playerid) != 0))
  1383. Assistance_FixOwnVehicle(playerid);
  1384. }
  1385. }
  1386.  
  1387. // Trying to attach the closest vehicle to the towtruck when the player pressed FIRE when inside a towtruck
  1388. // Check if the player is inside a towtruck
  1389. if(GetVehicleModel(GetPlayerVehicleID(playerid)) == VehicleTowTruck)
  1390. {
  1391. // Check if the player pushed the fire-key
  1392. if(newkeys & KEY_FIRE)
  1393. {
  1394. // Get the vehicle-id of the closest vehicle
  1395. new closest = GetClosestVehicle(playerid);
  1396. if(VehicleToPlayer(playerid, closest) < 10) // Check if the closest vehicle is within 10m from the player
  1397. AttachTrailerToVehicle(closest, GetPlayerVehicleID(playerid)); // Attach the vehicle to the towtruck
  1398. }
  1399. }
  1400.  
  1401. // Refuel a vehicle when driving a vehicle and pressing the HORN key
  1402. // Check if the player presses the HORN key
  1403. if ((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
  1404. {
  1405. // Check if the player is driving a vehicle
  1406. if (GetPlayerVehicleSeat(playerid) == 0)
  1407. {
  1408. // Loop through all ARefuelPickups
  1409. for (new i; i < sizeof(ARefuelPickups); i++)
  1410. {
  1411. // Check if the player is in range of a refuelpickup
  1412. if(IsPlayerInRangeOfPoint(playerid, 2.5, ARefuelPickups[i][pux], ARefuelPickups[i][puy], ARefuelPickups[i][puz]))
  1413. {
  1414. // Show a message that the player's vehicle is refuelling
  1415. GameTextForPlayer(playerid, TXT_Refuelling, 3000, 4);
  1416. // Don't allow the player to move again (the timer will allow it after refuelling)
  1417. TogglePlayerControllable(playerid, 0);
  1418. // Start a timer (let the player wait until the vehicle is refuelled)
  1419. SetTimerEx("RefuelVehicle", 5000, false, "i", playerid);
  1420. // Stop the search
  1421. break;
  1422. }
  1423. }
  1424. }
  1425. }
  1426.  
  1427. return 1;
  1428. }
  1429.  
  1430.  
  1431.  
  1432. forward VehicleToPlayer(playerid,vehicleid);
  1433. // Get the distance between the vehicle and the player
  1434. public VehicleToPlayer(playerid, vehicleid)
  1435. {
  1436. // Setup local variables
  1437. new Float:pX, Float:pY, Float:pZ, Float:cX, Float:cY, Float:cZ, Float:distance;
  1438. // Get the player position
  1439. GetPlayerPos(playerid, pX, pY, pZ);
  1440. // Get the vehicle position
  1441. GetVehiclePos(vehicleid, cX, cY, cZ);
  1442. // Calculate the distance
  1443. distance = floatsqroot(floatpower(floatabs(floatsub(cX, pX)), 2) + floatpower(floatabs(floatsub(cY, pY)), 2) + floatpower(floatabs(floatsub(cZ, pZ)), 2));
  1444. // Return the distance to the calling routine
  1445. return floatround(distance);
  1446. }
  1447.  
  1448.  
  1449.  
  1450. forward GetClosestVehicle(playerid);
  1451. // Find the vehicle closest to the player
  1452. public GetClosestVehicle(playerid)
  1453. {
  1454. // Setup local variables
  1455. new Float:distance = 99999.000+1, Float:distance2, result = -1;
  1456. // Loop through all vehicles
  1457. for(new i = 0; i < MAX_VEHICLES; i++)
  1458. {
  1459. // First check if the player isn't driving the current vehicle that needs to be checked for it's distance to the player
  1460. if (GetPlayerVehicleID(playerid) != i)
  1461. {
  1462. // Get the distance between player and vehicle
  1463. distance2 = VehicleToPlayer(playerid, i);
  1464. // Check if the distance is smaller than the previous distance
  1465. if(distance2 < distance)
  1466. {
  1467. // Store the distance
  1468. distance = distance2;
  1469. // Store the vehicle-id
  1470. result = i;
  1471. }
  1472. }
  1473. }
  1474.  
  1475. // Return the vehicle-id of the closest vehicle
  1476. return result;
  1477. }
  1478.  
  1479.  
  1480.  
  1481. // This function is used to debug the key-presses
  1482. stock DebugKeys(playerid, newkeys, oldkeys)
  1483. {
  1484. // Debug keys
  1485. if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
  1486. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_FIRE key");
  1487. if ((newkeys & KEY_ACTION) && !(oldkeys & KEY_ACTION))
  1488. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_ACTION key");
  1489. if ((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))
  1490. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_CROUCH key");
  1491. if ((newkeys & KEY_SPRINT) && !(oldkeys & KEY_SPRINT))
  1492. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_SPRINT key");
  1493. if ((newkeys & KEY_SECONDARY_ATTACK) && !(oldkeys & KEY_SECONDARY_ATTACK))
  1494. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_SECONDARY_ATTACK key");
  1495. if ((newkeys & KEY_JUMP) && !(oldkeys & KEY_JUMP))
  1496. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_JUMP key");
  1497. if ((newkeys & KEY_LOOK_RIGHT) && !(oldkeys & KEY_LOOK_RIGHT))
  1498. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_LOOK_RIGHT key");
  1499. if ((newkeys & KEY_HANDBRAKE) && !(oldkeys & KEY_HANDBRAKE))
  1500. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_HANDBRAKE key");
  1501. if ((newkeys & KEY_LOOK_LEFT) && !(oldkeys & KEY_LOOK_LEFT))
  1502. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_LOOK_LEFT key");
  1503. if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
  1504. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_SUBMISSION key");
  1505. if ((newkeys & KEY_LOOK_BEHIND) && !(oldkeys & KEY_LOOK_BEHIND))
  1506. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_LOOK_BEHIND key");
  1507. if ((newkeys & KEY_WALK) && !(oldkeys & KEY_WALK))
  1508. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_WALK key");
  1509. if ((newkeys & KEY_ANALOG_UP) && !(oldkeys & KEY_ANALOG_UP))
  1510. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_ANALOG_UP key");
  1511. if ((newkeys & KEY_ANALOG_DOWN) && !(oldkeys & KEY_ANALOG_DOWN))
  1512. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_ANALOG_DOWN key");
  1513. if ((newkeys & KEY_ANALOG_LEFT) && !(oldkeys & KEY_ANALOG_LEFT))
  1514. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_ANALOG_LEFT key");
  1515. if ((newkeys & KEY_ANALOG_RIGHT) && !(oldkeys & KEY_ANALOG_RIGHT))
  1516. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_ANALOG_RIGHT key");
  1517. if ((newkeys & KEY_UP) && !(oldkeys & KEY_UP))
  1518. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_UP key");
  1519. if ((newkeys & KEY_DOWN) && !(oldkeys & KEY_DOWN))
  1520. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_DOWN key");
  1521. if ((newkeys & KEY_LEFT) && !(oldkeys & KEY_LEFT))
  1522. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_LEFT key");
  1523. if ((newkeys & KEY_RIGHT) && !(oldkeys & KEY_RIGHT))
  1524. SendClientMessage(playerid, 0x0000FFFF, "You pressed the KEY_RIGHT key");
  1525.  
  1526. return 1;
  1527. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement