Advertisement
Guest User

Untitled

a guest
Feb 6th, 2018
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.45 KB | None | 0 0
  1. //--------------------------------------------------------------//
  2. // Mechanic job system by hobo101 aka MarkNelson V0.1
  3. // If you're using this system as a filterscript or in your game-mode
  4. // Please, don't remove the credits
  5. // If you find any bug, feel free to report it through PM on samp forums
  6. // to MarkNelson, Thank you for understanding.
  7. //-------------------------------------------------------------//
  8.  
  9. #include <a_samp>
  10. #include <streamer>
  11. #include <zcmd>
  12. #include <sscanf2>
  13.  
  14.  
  15. //Mechanic Job Color + Civil Color + Dialog
  16. #define COLOR_CIVIL 0xFFFF6CFF
  17. #define COLOR_MECHANIC 0x808040FF
  18. #define DIALOG_MECHANIC 894
  19. #define DIALOG_MECHANICS 895
  20. #define DIALOG_MECHHELP 896
  21. //
  22. new mechjob[MAX_PLAYERS];
  23. new mechpickup;
  24. new Repairing[MAX_PLAYERS];
  25. new request[MAX_PLAYERS];
  26. //
  27. Float:GetDistanceBetweenPlayers(playerid,id)
  28. {
  29.     new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  30.     if(!IsPlayerConnected(playerid) || !IsPlayerConnected(id)) {
  31.         return -1.00;
  32.     }
  33.     GetPlayerPos(playerid,x1,y1,z1);
  34.     GetPlayerPos(id,x2,y2,z2);
  35.     return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  36. }
  37. stock SendToMechanics(color, str[])
  38. {
  39.     for(new i=0 ; i<MAX_PLAYERS ; i++)
  40.     {
  41.         if(IsPlayerConnected(i) && mechjob[i] > 0)
  42.         {
  43.             SendClientMessage(i, color, str);
  44.         }
  45.     }
  46. }
  47. stock GetName(playerid) {
  48.     new pName[26];
  49.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  50.     return pName;
  51. }
  52. stock GetPlayerNameEx(playerid)
  53. {
  54.      new playername[25];
  55.      GetPlayerName(playerid, playername, sizeof(playername));
  56.      return playername;
  57. }
  58. //
  59. #define FILTERSCRIPT
  60.  
  61. public OnFilterScriptInit()
  62. {
  63.     print("\n--------------------------------------");
  64.     print("* hobo101(MarkNelson)'s mechanic job system has been loaded *");
  65.     print("--------------------------------------\n");
  66.     Create3DTextLabel("Mechanic Job",0xFFFF80FF,1629.0221,-1903.3815,13.5532,30.0,0); //Mechanic Job 3dtextlabel
  67.     mechpickup = CreateDynamicPickup(1275,2,1629.0221,-1903.3815,13.5532,0,0,-1,100.0); // Mechanic Job Pickup
  68.     AddStaticVehicle(525,1648.6406,-1904.0719,13.2318,11.6325,103,37); // Tow Truck 1
  69.     AddStaticVehicle(525,1632.0477,-1908.3938,13.2304,276.3869,103,37); // Tow Truck 2
  70.     AddStaticVehicle(525,1670.6864,-1894.7494,13.2265,89.3171,103,37); // Tow Truck 3
  71.     AddStaticVehicle(525,1625.6631,-1896.0985,13.2308,269.6205,103,37); // Tow Truck 4
  72.     AddStaticVehicle(525,1624.0439,-1857.5204,13.2281,183.4155,103,37); // Tow Truck 5
  73.     return 1;
  74. }
  75.  
  76. public OnFilterScriptExit()
  77. {
  78.     print("\n----------------------------------");
  79.     print(" * hobo101(MarkNelson)'s mechanic job system has been unloaded *");
  80.     print("----------------------------------\n");
  81.     return 1;
  82. }
  83.  
  84. public OnPlayerConnect(playerid)
  85. {
  86.     mechjob[playerid] = 0;
  87.     Repairing[playerid] = 0;
  88.     request[playerid] = 0;
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerDisconnect(playerid, reason)
  93. {
  94.  
  95.     mechjob[playerid] = 0;
  96.     Repairing[playerid] = 0;
  97.     request[playerid] = 0;
  98.     return 1;
  99. }
  100.  
  101. public OnPlayerDeath(playerid, killerid, reason)
  102. {
  103.     mechjob[playerid] = 0;
  104.     SetPlayerColor(playerid, COLOR_CIVIL);
  105.     return 1;
  106. }
  107.  
  108. public OnPlayerStateChange(playerid, newstate, oldstate)
  109. {
  110.     if(mechjob[playerid] == 0)
  111.     {
  112.         if(newstate == PLAYER_STATE_DRIVER)
  113.         {
  114.             if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525 )
  115.             {
  116.                 SendClientMessage(playerid, COLOR_CIVIL,"This vehicle is restricted.");
  117.                 RemovePlayerFromVehicle(playerid);
  118.             }
  119.         }
  120.     }
  121.     return 1;
  122. }
  123.  
  124. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  125. {
  126.     switch(dialogid)
  127.     {
  128.         case 894:
  129.         {
  130.             if(!response) SendClientMessage(playerid, COLOR_CIVIL, "Okay, Good bye. If you changed your mind, come back.");
  131.             if(response)
  132.             {
  133.                 if(mechjob[playerid] == 1 ) return SendClientMessage(playerid, COLOR_MECHANIC, "You're already a mechanic");
  134.                 if(GetPlayerWantedLevel(playerid) > 0) return SendClientMessage(playerid, COLOR_CIVIL, "You are wanted, you can't join, We don't accept criminals");
  135.                 SendClientMessage(playerid,COLOR_MECHANIC, "Congratulations! Now you're a mechanic. Use /ljob to leave the job");
  136.                 mechjob[playerid] = 1;
  137.                 SetPlayerColor(playerid,COLOR_MECHANIC);
  138.                 new pname[MAX_PLAYER_NAME], string[120];
  139.                 GetPlayerName(playerid, pname, sizeof(pname));
  140.                 format(string, sizeof(string), "%s is now one of our mechanics in San Andreas!", pname);
  141.                 SendClientMessageToAll(COLOR_MECHANIC, string);
  142.             }
  143.         }
  144.     }
  145.     return 1;
  146. }
  147.  
  148. CMD:fix(playerid,params[])
  149. {
  150.     if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to be on foot to use this command");
  151.     if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to be on foot to use this command");
  152.     if(mechjob[playerid] == 0) return SendClientMessage(playerid, COLOR_MECHANIC, "You're not a mechanic!");
  153.     if(mechjob[playerid] == 1)
  154.     {
  155.        
  156.        
  157.        
  158.        
  159.         new id;
  160.         if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_MECHANIC, "Syntax: /fix [id]");
  161.         else if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_CIVIL, "That player is not connected to the server!");
  162.         else if(id == playerid) return SendClientMessage(playerid, COLOR_MECHANIC, "You cannot fix yourself's car!");
  163.         else if(GetDistanceBetweenPlayers(playerid, id) > 5.00) return SendClientMessage(playerid, COLOR_MECHANIC, "That player is too far away!");
  164.         else if(GetPlayerState(id) == PLAYER_STATE_ONFOOT) return SendClientMessage(playerid,COLOR_MECHANIC, "That player is not in a vehicle!");
  165.         else if(GetPlayerState(id) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_MECHANIC, "That player is not driving a vehicle!");
  166.         else if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to be on foot to use this command!");
  167.         else if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to be on foot to use this command!");
  168.         else
  169.         {
  170.            
  171.            
  172.             if(GetPlayerState(id) == PLAYER_STATE_DRIVER)
  173.             {
  174.                 new Float:vhealth;
  175.                 new vehicleid = GetPlayerVehicleID(id);  
  176.                 GetVehicleHealth(vehicleid, vhealth);
  177.                 if(Repairing[playerid] == 1) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to wait 2 minutes to fixing a vehicle another time!");
  178.                 if(vhealth == 1000.0)  return SendClientMessage(playerid, COLOR_MECHANIC, "That player's vehicle has enough health already!");
  179.                 if(vhealth > 1000.0)  return SendClientMessage(playerid, COLOR_MECHANIC, "That player's vehicle has enough health already!");
  180.                 else
  181.                 {
  182.                    
  183.                    
  184.                    
  185.                     new string[100];
  186.                     new pName[MAX_PLAYER_NAME];
  187.                     GetPlayerName(id, pName, sizeof(pName));
  188.                     RepairVehicle(GetPlayerVehicleID(id));
  189.                     format(string, sizeof(string), "You've successfully repaired %s's vehicle (ID: %d)! +$4200", pName, id);
  190.                     SendClientMessage(playerid, COLOR_MECHANIC, string);
  191.                     SendClientMessage(id, COLOR_MECHANIC, "A mechanic has fixed your vehicle!");
  192.                     GivePlayerMoney(playerid,4200);
  193.                     SetTimerEx("repairing", 120000, false, "i", playerid); // the timer of repairing cool down
  194.                     Repairing[playerid] = 1;
  195.                     new pname[MAX_PLAYER_NAME], stringx[190];
  196.                     GetPlayerName(playerid, pname, sizeof(pname));
  197.                     format(stringx, sizeof(stringx), "[MECHANIC]: %s has fixed a vehicle!", pname);
  198.                     SendClientMessageToAll(COLOR_MECHANIC, stringx);
  199.                     PlayerPlaySound(id,1133,0.0,0.0,0.0);
  200.                     PlayerPlaySound(playerid,1133,0.0,0.0,0.0);
  201.  
  202.                    
  203.                 }
  204.             }
  205.         }
  206.     }
  207.     return 1;
  208. }
  209.  
  210. public OnPlayerPickUpDynamicPickup(playerid, pickupid)
  211. {
  212.  
  213.     if(pickupid == mechpickup)
  214.     {
  215.  
  216.        ShowPlayerDialog(playerid, 894, DIALOG_STYLE_MSGBOX, "{808040}Mechanic job{FFFFFF}", "Welcome to Mechanics Garage\nWell, You can work as a mechanic in San Andreas here!\nYou can use /fix to fix player's vehicles\nAre you sure that you want to join?  !", "Yes", "No i won't");
  217.  
  218.     }
  219.     return 1;
  220. }
  221. forward repairing(playerid);
  222. public repairing(playerid)
  223. {
  224.     if(mechjob[playerid] == 1)
  225.     {
  226.        SendClientMessage(playerid,COLOR_MECHANIC,"You can fix a vehicle another time now");
  227.        Repairing[playerid] = 0;
  228.     }
  229. }
  230. forward requested(playerid);
  231. public requested(playerid)
  232. {
  233.     if(request[playerid] == 1)
  234.     {
  235.        SendClientMessage(playerid,COLOR_MECHANIC,"You can request for a mechanic again now");
  236.        request[playerid] = 0;
  237.     }
  238. }
  239. CMD:mechanics(playerid, params[])
  240. {
  241.     new IsMechOnline = 0;
  242.     new string[300], Jstring[128];
  243.  
  244.     for(new i=0;i<MAX_PLAYERS;i++)
  245.     {
  246.         if(IsPlayerConnected(i))
  247.         {
  248.             if(mechjob[i] > 0)
  249.             {
  250.               format(Jstring, 128, "{FFFF00}%s (%d) - Mechanic Available\n", GetPlayerNameEx(i), i);
  251.               strcat(string, Jstring, sizeof(string));
  252.               IsMechOnline++;
  253.             }
  254.         }
  255.     }
  256.     if(IsMechOnline == 0)
  257.     ShowPlayerDialog(playerid,DIALOG_MECHANICS,DIALOG_STYLE_MSGBOX,"Warning","There are no mechanics available at this time" ,"Close","");
  258.     else ShowPlayerDialog(playerid,DIALOG_MECHANICS,DIALOG_STYLE_LIST,"Mechanics", string ,"Close","");
  259.     return 1;
  260. }
  261. CMD:ljob(playerid, params[])
  262. {
  263.     if(mechjob[playerid] == 0) return SendClientMessage(playerid, COLOR_CIVIL, "You're not a mechanic to use this command");
  264.     if(mechjob[playerid] == 1)
  265.     {
  266.         SendClientMessage(playerid, COLOR_CIVIL, "You're a normal civillian now");
  267.         mechjob[playerid] = 0;
  268.         SetPlayerColor(playerid, COLOR_CIVIL);
  269.         ResetPlayerWeapons(playerid);
  270.     }
  271.     if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
  272.     {
  273.         RemovePlayerFromVehicle(playerid);
  274.     }
  275.     return 1;
  276. }
  277. CMD:tow(playerid, params[])
  278. {
  279.     if(mechjob[playerid] == 0) return SendClientMessage(playerid, COLOR_CIVIL, "You have to be a mechanic to do this job");
  280.     if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_MECHANIC, "You are not driving a tow truck!");
  281.     new vehicleid = GetPlayerVehicleID(playerid);
  282.     if(IsTrailerAttachedToVehicle(vehicleid))
  283.     {
  284.         DetachTrailerFromVehicle(vehicleid);
  285.         SendClientMessage(playerid, COLOR_MECHANIC, "You are not towing a vehicle anymore");
  286.         return 1;
  287.     }
  288.     new Float:x, Float:y, Float:z;
  289.     new Float:dist, Float:closedist=8, closeveh;
  290.     for(new i=1; i < MAX_VEHICLES; i++)
  291.     {
  292.         if(i != vehicleid && GetVehiclePos(i, x, y, z))
  293.         {
  294.             dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
  295.             if(dist < closedist)
  296.             {
  297.                 closedist = dist;
  298.                 closeveh = i;
  299.             }
  300.         }
  301.     }
  302.     if(!closeveh) return SendClientMessage(playerid, COLOR_CIVIL, "You are not close to a vehicle!");
  303.     if(GetVehicleModel(GetPlayerVehicleID(playerid)) != 525) return SendClientMessage(playerid, COLOR_CIVIL, "You have to be in a tow truck to use this command");
  304.     if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 525)
  305.     {
  306.        AttachTrailerToVehicle(closeveh, vehicleid);
  307.        SendClientMessage(playerid, COLOR_MECHANIC, "You are now towing a vehicle");
  308.     }
  309.     return 1;
  310. }
  311. CMD:mc(playerid, params[])
  312. {
  313.     if(mechjob[playerid] < 1) return SendClientMessage(playerid, COLOR_MECHANIC, "Error: You must be a mechanic member to use this command");
  314.     new msg[256];
  315.     if(sscanf(params, "s", msg)) return SendClientMessage(playerid, COLOR_MECHANIC, "Use: /mc [Message]");
  316.     for(new i=0;i<MAX_PLAYERS;i++)
  317.     {
  318.  
  319.         if(IsPlayerConnected(i))
  320.         {
  321.  
  322.             if(mechjob[i] > 0)
  323.             {
  324.                
  325.                
  326.                
  327.                 new string[270];
  328.                 format(string, sizeof(string), "[Mechanic Chat] %s(%d): %s", GetPlayerNameEx(playerid), playerid, msg);
  329.                 SendClientMessage(i, COLOR_MECHANIC, string);
  330.             }
  331.         }
  332.     }
  333.     return 1;
  334. }
  335. CMD:mechanic(playerid, params[])
  336. {
  337.     if(request[playerid] == 1) return SendClientMessage(playerid, COLOR_MECHANIC, "You have to wait 1 minute to request a mechanic again");
  338.     new str[256];
  339.     if(sscanf(params, "s[256]", str)) return SendClientMessage(playerid, COLOR_MECHANIC, "Usage: /mechanic [Type your request for help here]");
  340.     request[playerid] = 1;
  341.  
  342.     format(str, 256, "[%s](%d) requested: %s", GetName(playerid), playerid, str);
  343.     SendToMechanics(COLOR_MECHANIC, str);
  344.     SendClientMessage(playerid, COLOR_MECHANIC, "Your request for help has been sent to the available mechanics, please wait until they respound to your request");
  345.  
  346.     SetTimerEx("requested", 60000, false, "i", playerid); // the timer of repairing cool down
  347.     return 1;
  348. }
  349. CMD:mreply(playerid, params[])
  350. {
  351.     if(mechjob[playerid] < 0) return 0;
  352.     if(mechjob[playerid] > 0)
  353.     {
  354.        new id, str[256];
  355.        if(sscanf(params, "us[256]", id, str)) return SendClientMessage(playerid, COLOR_MECHANIC, "Usage: /mreply [Playerid] [Respound]");
  356.        if(!request[id]) return SendClientMessage(playerid, COLOR_MECHANIC, "Error: Player didn't send any request for help!");
  357.  
  358.        new str1[256];
  359.        format(str1, 256, "%s(%d) respounded to %s(%d)'s request. Answer: ", GetName(playerid), playerid, GetName(id), id);
  360.        SendToMechanics(COLOR_MECHANIC, str1);
  361.        SendToMechanics(COLOR_MECHANIC, str);
  362.  
  363.        format(str, 256, "Respound from [%s]: %s", GetName(playerid), str);
  364.        SendClientMessage(id, COLOR_MECHANIC, str);
  365.        request[id] = 0;
  366.     }
  367.     return 1;
  368. }
  369. CMD:mechanichelp(playerid, params[])
  370. {
  371.     ShowPlayerDialog(playerid, 896, DIALOG_STYLE_MSGBOX, "{808040}MarkNelson(hobo101)'s mechanic system help{FFFFFF}", "/mechanic /mreply /fix /tow /mechanichelp /mc /mechanics /ljob", "Close", "");
  372.     return 1;
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement