Advertisement
B-Matt

Mechanic System by B-Matt

Jan 3rd, 2013
3,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.02 KB | None | 0 0
  1. /***************************************************************
  2. *                                                              *
  3. *   Mechanic System v1.0                                       *
  4. *   (c) 2013. B-Matt                                           *
  5. *   WEB: https://gas-locator.com                               *
  6. *                                                              *
  7. ****************************************************************/
  8. /* Includes */
  9. #include <a_samp>
  10. #include <sscanf2>
  11. #include <ZCMD>
  12.  
  13. /* Colors */
  14.  
  15. #define COLOR_LIGHTBLUE     0x468CFFFF
  16. #define COLOR_GREEN         0x1E8200FF
  17. #define COLOR_RED           0xFF1414FF
  18.  
  19. /* Timers for mechanic */
  20. new SprayT;
  21.  
  22. /* Spray system*/
  23. new Spray[MAX_PLAYERS];
  24. new pick, color;
  25. new Service[MAX_PLAYERS][3];
  26.  
  27. new vehid; //Var for vehicle for mechanic service
  28. new Float:Car[4]; //Array for vehicle position (used in spray system)
  29.  
  30. /* Encodes */
  31.  
  32. encode_tires(tire1, tire2, tire3, tire4) return tire1 | (tire2 << 1) | (tire3 << 2) | (tire4 << 3);
  33. encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper)
  34. {
  35.     return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
  36. }
  37. encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door)
  38. {
  39.     #pragma unused behind_driver_door
  40.     #pragma unused behind_passenger_door
  41.     return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
  42. }
  43. encode_lights(light1, light2, light3, light4)
  44. {
  45.     return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
  46. }
  47.  
  48. /* SA-MP Callbacks */
  49.  
  50. public OnFilterScriptInit()
  51. {
  52.     print("\n ===========================");
  53.     print("    Mechanic System v1.0");
  54.     print("      (c) B-Matt, 2013.");
  55.     print(" ===========================\n");
  56.     /* OPTIONAL - Mechanic garage */
  57.     CreateObject(11387, 2187.78, -2000.54, 15.92,   0.00, 0.00, 0.00);
  58.     CreateObject(11389, 2178.43, -1984.54, 15.70,   0.00, 0.00, 0.00);
  59.     CreateObject(11388, 2178.43, -1984.49, 19.30,   0.00, 0.00, 0.00);
  60.     CreateObject(11390, 2178.25, -1984.50, 16.99,   0.00, 0.00, 0.00);
  61.     CreateObject(11391, 2170.19, -1992.65, 13.85,   0.00, 0.00, 0.00);
  62.     CreateObject(11393, 2182.99, -1989.86, 14.00,   0.00, 0.00, 0.00);
  63.     CreateObject(11359, 2173.93, -2000.64, 14.64,   0.00, 0.00, 0.00);
  64.     CreateObject(11359, 2187.40, -1980.91, 14.70,   0.00, 0.00, 90.00);
  65.     CreateObject(1676, 2199.84, -1994.45, 14.26,   0.00, 0.00, 90.00);
  66.     AddStaticVehicle(562, Car[1], Car[2], Car[3], 90.0, 0, 0); //Optional - vehicle
  67.     return 1;
  68. }
  69.  
  70. public OnPlayerConnect(playerid)
  71. {
  72.     return 1;
  73. }
  74.  
  75. public OnPlayerDisconnect(playerid, reason)
  76. {
  77.     return 1;
  78. }
  79.  
  80. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  81. {
  82.     if(newkeys & KEY_FIRE)
  83.     {
  84.         if(IsPlayerInRangeOfPoint(playerid, 3.0, Car[1], Car[2], Car[3]))
  85.         {
  86.             if(Spray[playerid] == 1)
  87.             {
  88.                 SprayT = SetTimer("OnPlayerSpray", 5000, false);
  89.             }
  90.         }
  91.     }
  92.     else return KillTimer(SprayT);
  93.     return 1;
  94. }
  95.  
  96. /* Custom Callbacks */
  97.  
  98. forward OnPlayerSpray(playerid);
  99. public OnPlayerSpray(playerid)
  100. {
  101.     if(pick == 1) {
  102.         ChangeVehicleColor(vehid, color, 0); }
  103.     else {
  104.     ChangeVehicleColor(vehid, 0, color); }
  105.     KillTimer(SprayT);
  106.     Spray[playerid] = 0;
  107.     Service[playerid][0] = 0;
  108.     SendClientMessage(playerid, COLOR_GREEN, "You successfully paint this vehicle!");
  109.     return 1;
  110. }
  111.  
  112. /* Commands */
  113.  
  114. CMD:meh(playerid, params[]) //Optional - Mechanic garage port cmd
  115. {
  116.     SetPlayerPos(playerid, 2190.9937+4, -1980.8362, 13.2);
  117.     return 1;
  118. }
  119.  
  120. CMD:spray(playerid, params[])
  121. {
  122.     if(IsPlayerInRangeOfPoint(playerid, 20.0, 2180.9875,-1979.7583,13.5606)) //Optional - CHANGE
  123.     {
  124.         new string[128], pName[MAX_PLAYER_NAME], mName[MAX_PLAYER_NAME], pID;
  125.         GetPlayerName(pID, pName, sizeof(pName));
  126.         GetPlayerName(playerid, mName, sizeof(mName));
  127.         if(sscanf(params, "uii", pID, pick, color)) return SendClientMessage(playerid, -1, "USAGE: /spray [ID/Name][Color pick (1/2)][Color]");
  128.         if(pick > 2 || pick < 1) return SendClientMessage(playerid, COLOR_RED,"Colorpick can't be lower than 1 and higher than 2.");
  129.         if(color > 126 || color < 0) return SendClientMessage(playerid, COLOR_RED,"Color ID can't be lower than 0 and higher than 126.");
  130.         vehid = GetPlayerVehicleID(pID);
  131.         format(string, sizeof(string), "%s has offered you spray service for your vehicle. Colorpick: {FFFFFF}%d{468CFF}, ColorID: {FFFFFF}%d", mName, pick, color);
  132.         SendClientMessage(pID, COLOR_LIGHTBLUE, string);
  133.         SendClientMessage(pID, COLOR_LIGHTBLUE, "Use /acceptmeh for accepting that offer.");
  134.         Service[pID][0] = 1;
  135.     }
  136.     else return SendClientMessage(playerid, COLOR_RED, "You must be in the garage to repair vehicles!");
  137.     return 1;
  138. }
  139.  
  140. CMD:repair(playerid, params[])
  141. {
  142.     if(IsPlayerInRangeOfPoint(playerid, 20.0, 2180.9875,-1979.7583,13.5606)) //Optional - CHANGE
  143.     {
  144.         new string[128], item[32], pID, mName[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
  145.         if(sscanf(params, "s[32] ", item)) {
  146.             SendClientMessage(playerid, -1, "USAGE: /repair [option]");
  147.             SendClientMessage(playerid, -1, "Options: bodykit, engine");
  148.             return 1;
  149.         }
  150.         if(strcmp(item,"bodykit",true) == 0) {
  151.             if (sscanf(params, "s[32]u", item, pID)) return SendClientMessage(playerid, -1, "USAGE: /repair bodykit [ID/Name]");
  152.             GetPlayerName(playerid, mName, sizeof(mName));
  153.             GetPlayerName(pID, pName, sizeof(pName));
  154.             format(string, sizeof(string), "%s has offered you a repair of bodykit on your car!", mName);
  155.             SendClientMessage(pID, COLOR_LIGHTBLUE, string);
  156.             SendClientMessage(pID, COLOR_LIGHTBLUE, "Use: /acceptmeh to accept that offer!");
  157.             format(string, sizeof(string), "You offered %s to repair bodykit on his vehicle.", pName);
  158.             SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  159.             Service[pID][1] = 1;
  160.         }
  161.         else if(strcmp(item,"engine",true) == 0) {
  162.             if(sscanf(params, "s[32]u",item, pID)) return SendClientMessage(playerid, -1, "USAGE: /repair engine [ID/Name]");
  163.             GetPlayerName(playerid, mName, sizeof(mName));
  164.             GetPlayerName(pID, pName, sizeof(pName));
  165.             format(string, sizeof(string), "%s has offered you a repair of engine on your vehicle!", mName);
  166.             SendClientMessage(pID, COLOR_LIGHTBLUE, string);
  167.             SendClientMessage(pID, COLOR_LIGHTBLUE, "Use: /acceptmeh to accept that offer!");
  168.             format(string, sizeof(string), "You offered %s to repair engine on his vehicle.", pName);
  169.             SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  170.             Service[pID][2] = 1;
  171.         }
  172.     }
  173.     else return SendClientMessage(playerid, COLOR_RED, "You must be in the garage to repair vehicles!");
  174.     return 1;
  175. }
  176.  
  177. CMD:acceptmeh(playerid, params[])
  178. {
  179.     new Float: X, Float: Y, Float: Z, pID;
  180.     if(Service[playerid][0] == 1)
  181.     {
  182.         SendClientMessage(playerid, -1, "You accepted mechanic service. Please wait!");
  183.         GetVehiclePos(vehid, X, Y, Z);
  184.         Car[1] = X;
  185.         Car[2] = Y;
  186.         Car[3] = Z;
  187.         Spray[pID] = 1;
  188.         GivePlayerWeapon(pID, 41, 500);
  189.     }
  190.     else if(Service[playerid][1] == 1)
  191.     {
  192.         new panels,doors,lights,tires;
  193.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "You accepted mechanic service. Please wait!");
  194.         vehid = GetPlayerVehicleID(playerid);
  195.         tires = encode_tires(0, 0, 0, 0); // fix all tires
  196.         panels = encode_panels(0, 0, 0, 0, 0, 0, 0); // fix all panels
  197.         doors = encode_doors(0, 0, 0, 0, 0, 0); // fix all doors
  198.         lights = encode_lights(0, 0, 0, 0); // fix all lights
  199.         UpdateVehicleDamageStatus(vehid, panels, doors, lights, tires);
  200.         Service[playerid][1] = 0;
  201.         SendClientMessage(playerid, COLOR_GREEN, "Bodykit on your vehicle has been fully repaired!");
  202.     }
  203.     else if(Service[playerid][2] == 1)
  204.     {
  205.         SendClientMessage(playerid, COLOR_LIGHTBLUE, "You accepted mechanic service. Please wait!");
  206.         vehid = GetPlayerVehicleID(playerid);
  207.         SetVehicleHealth(vehid, 1000.0);
  208.         Service[playerid][2] = 0;
  209.         SendClientMessage(playerid, COLOR_GREEN, "Your vehicle's engine has been fully repaired!");
  210.     }
  211.     else return SendClientMessage(playerid, COLOR_RED, "No one has offered you mechanic service!");
  212.     return 1;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement