RyanUSNS

ClientSide Illegal Trucking

Oct 1st, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.58 KB | None | 0 0
  1. local truckVehicles = {
  2.     --Trucker
  3.     {[403]=true, [515]=true, [514]=true},
  4.     --Delivery Man
  5.     {[482]=true, [413]=true, [440]=true, [414]=true, [499]=true, [456]=true},
  6. }
  7. local delMarkers = {
  8.     ["trucker"] = {
  9.         {},
  10.     },
  11.     ["delivery man"] = {
  12.         ["LS"] = {
  13.             {},
  14.         },
  15.         ["SF"] = {
  16.             {},
  17.         },
  18.     },
  19. }
  20. local marker, blip, trailer
  21. local payment = 1
  22. local dest = {}
  23.  
  24. function showIllegalPanel()
  25.     local resX, resY = guiGetScreenSize()
  26.     illegalWin = guiCreateWindow((resX/2) - 200, (resY/2) - 200, 496, 268, "Illegal Trucking Mission", false)
  27.     guiWindowSetSizable(illegalWin, false)
  28.     guiSetVisible(illegalWin, false)
  29.     guiSetAlpha(illegalWin, 95)
  30.     informationLabel = guiCreateLabel(9, 22, 477, 59, "You has been given the opportunity to transport illegal cargo to another location. You \nwill become wanted if you accept this mission, but you will get extra payment +\ncriminal reputation. Select 1 of 3 missions. If you decline this mission, you will not get \nany mission until you re-enter at vehicle. Doing Delivery man mission at SF will be reduced for 50%", false, illegalWin)
  31.     guiLabelSetHorizontalAlign(informationLabel, "center", false)
  32.     selectionLabel = guiCreateLabel(9, 91, 477, 17, "Please select an option below", false, illegalWin)
  33.     guiSetFont(selectionLabel, "default-bold-small")
  34.     guiLabelSetColor(selectionLabel, 255, 0, 0)
  35.     guiLabelSetHorizontalAlign(selectionLabel, "center", false)
  36.     lowPayRadioButton = guiCreateRadioButton(9, 118, 477, 21, "Delivery Immigrants (1.0x Money, 30 wanted points)", false, illegalWin)
  37.     guiRadioButtonSetSelected(lowPayRadioButton, true)
  38.     medPayRadioButton = guiCreateRadioButton(9, 149, 477, 21, "Deliver Drugs and Guns (1.5x Money, 45 wanted points)", false, illegalWin)
  39.     highPayRadioButton = guiCreateRadioButton(9, 180, 477, 21, "Deliver Counterfeit Money (2.0x Money, 60 wanted points)", false, illegalWin)
  40.     acceptButton = guiCreateButton(124, 218, 91, 35, "Start", false, illegalWin)
  41.     cancelButton = guiCreateButton(281, 218, 91, 35, "Cancel", false, illegalWin)
  42.     --Event Handler
  43.     addEventHandler("onClientGUIClick", acceptButton, acceptMission)
  44.     addEventHandler("onClientGUIClick", cancelButton, showPanel)
  45. end
  46.  
  47. function showPanel()
  48.     if (marker and not guiGetVisible(illegalWin)) then
  49.         return false
  50.     end
  51.     if (not illegalWin) then
  52.         showIllegalPanel()
  53.     end
  54.     local state = not guiGetVisible(illegalWin)
  55.     guiSetVisible(illegalWin, state)
  56.     showCursor(state)
  57.     if (dest[localPlayer]) then
  58.         dest = {}
  59.     end
  60. end
  61.  
  62. function acceptMission()
  63.     local crime = 24
  64.     if (guiRadioButtonGetSelected(medPayRadioButton)) then
  65.         payment = 1.5
  66.         crime = 25
  67.     end
  68.     if (guiRadioButtonGetSelected(highPayRadioButton)) then
  69.         payment = 2
  70.         crime = 26
  71.     end
  72.     triggerServerEvent("CITillegalTrucking.startMission", localPlayer, crime)
  73. end
  74.  
  75. function onCrimEnterVehicle(veh, seat)
  76.     local dim = getElementDimension(localPlayer)
  77.     if (getElementType(localPlayer) ~= "player" or not truckVehicles[1][getElementModel(veh)] and not truckVehicles[2][getElementModel(veh)] or getElementData(localPlayer, "o") ~= "Criminal" or seat ~= 0 or dim ~= 0) then
  78.         return false
  79.     end
  80.     local company = "delivery man"
  81.     if (truckVehicles[1][getElementModel(veh)]) then
  82.         company = "trucker"
  83.     end
  84.     setElementData(localPlayer, "illegalc", company)
  85.     bindKey("n", "down", showPanel)
  86.     exports.CIThelp:modTextBar("illegalTrucking", "Press 'n' for Illegal Trucking", 100, 0, 0, 95, 30000)
  87. end
  88. addEventHandler("onClientPlayerVehicleEnter", localPlayer, onCrimEnterVehicle)
  89.  
  90. function spawnMarkers()
  91.     unbindKey("n", "down", showPanel)
  92.     exports.CIThelp:modTextBar("illegalTrucking", "")
  93.     showPanel()
  94.     local job
  95.     local x, y, z = getElementPosition(localPlayer)
  96.     dest = {x, y, z}
  97.     local loc = getElementData(localPlayer, "z")
  98.     local company = getElementData(localPlayer, "illegalc")
  99.     if (company == "delivery man") then
  100.         if (loc == "LV") then
  101.             exports.CIThelp:dm("Leave from LV for handle this mission.", 255, 0, 0)
  102.             return false
  103.         end
  104.         job = delMarkers[company][loc]
  105.     end
  106.     if (company == "trucker") then
  107.         job = delMarkers[company]
  108.         local veh = getPedOccupiedVehicle(localPlayer)
  109.         local rotx, roty, rotz = getElementRotation(veh)
  110.         trailer = createVehicle(435, x-4, y, z, rotx, roty, rotz)
  111.         attachTrailerToVehicle(veh, trailer)
  112.         removeEventHandler("onClientTrailerDetach", trailer, onDetachTrailer)
  113.         addEventHandler("onClientTrailerDetach", trailer, onDetachTrailer)
  114.     end
  115.     local coord = math.random(#job)
  116.     local x, y, z = job[coord][1], job[coord][2], job[coord][3]
  117.     marker = createMarker(x, y, z, "cylinder", 4, 150, 0, 0, 95)
  118.     blip = createBlipAttachedTo(marker, 51)
  119.     removeEventHandler("onClientMarkerHit", marker, deliveryGoods)
  120.     addEventHandler("onClientMarkerHit", marker, deliveryGoods)
  121.     outputChatBox("Delivery this goods at "..getZoneName(x, y, z)..", "..getZoneName(x, y, z, true))
  122. end
  123. addEvent("CITillegalTrucking.spawnMarkers", true)
  124. addEventHandler("CITillegalTrucking.spawnMarkers", root, spawnMarkers)
  125.  
  126. function deliveryGoods(plr, dim)
  127.     if (not plr or not dim) then
  128.         return false
  129.     end
  130.     local x1, y1, z1 = getElementPosition(marker)
  131.     local x2, y2, z2 = dest[1], dest[2], dest[3]
  132.     local dist = getDistanceBetweenPoints2D(x1, y1, x2, y2)
  133.     if (marker) then
  134.         removeEventHandler("onClientMarkerHit", marker, deliveryGoods)
  135.         destroyElement(marker)
  136.     end
  137.     if (blip) then
  138.         destroyElement(blip)
  139.     end
  140.     if (trailer) then
  141.         removeEventHandler("onClientTrailerDetach", trailer, onDetachTrailer)
  142.         destroyElement(trailer)
  143.     end
  144.     local payIllegal = math.floor(dist*payment)
  145.     local company = getElementData(localPlayer, "illegalc")
  146.     local loc = getElementData(localPlayer, "z")
  147.     if (company == "delivery man" and loc == "SF") then
  148.         payIllegal = math.floor(payIllegal * 0.5)
  149.     end
  150.     triggerServerEvent("CITillegalTrucking.illegalPayment", localPlayer, payIllegal)
  151.     marker = nil
  152.     blip = nil
  153.     trailer = nil
  154.     payment = 1
  155.     setElementData(localPlayer, "illegalc", nil)
  156.     onCrimEnterVehicle(getPedOccupiedVehicle(localPlayer), getPedOccupiedVehicleSeat(localPlayer))
  157. end
  158.  
  159. function onDetachTrailer(veh)
  160.     if (not trailer) then
  161.         return false
  162.     end
  163.     attachTrailerToVehicle(veh, trailer)
  164. end
  165.  
  166. function resignJob(oldJob)
  167.     if (oldJob == "Criminal") then
  168.         if (marker) then
  169.             removeEventHandler("onClientMarkerHit", marker, deliveryGoods)
  170.             destroyElement(marker)
  171.         end
  172.         if (blip) then
  173.             destroyElement(blip)
  174.         end
  175.         if (trailer) then
  176.             removeEventHandler("onClientTrailerDetach", trailer, onDetachTrailer)
  177.             destroyElement(trailer)
  178.         end
  179.     end
  180. end
  181. addEventHandler("onClientPlayerResign", localPlayer, resignJob)
  182. addEventHandler("onClientPlayerEndShift", localPlayer, resignJob)
Advertisement
Add Comment
Please, Sign In to add comment