Advertisement
Guest User

PPC_Trucking server

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