RyanUSNS

IllegalTruck v2 - Client Side

Jan 29th, 2018
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.88 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. --  COMMUNITY CONTRIBUTION FOR CIT2.NET
  3. --  PURPOSE:    Illegal Trucker version 2.0 - Client Side
  4. --  DEVELOPERS: Ryan#USNS (IRC: Ryan1)
  5. ------------------------------------------------------------------------------------
  6.  
  7. local t = function(...) return exports.CITt:t(...) or arg[1] or "error" end
  8. local allowedVehs = {[403] = true, [514] = true, [515] = true}
  9. local pMarker, pBlip, dMarker, dBlip, inTask, curMission, countLoad, distanceRisk, radarTimer, infoMissions, checkDistance, timerLoad, distanceLeaving, countLeave, crimIllegal, copTimer
  10. local paymentInfo = {}
  11. local crimTeam = {["Criminal"] = true, ["Gangster"] = true}
  12.  
  13. function updateTable(mTable)
  14.     infoMissions = mTable
  15. end
  16. addEvent("CITcrimTruck.updateTables", true)
  17. addEventHandler("CITcrimTruck.updateTables", localPlayer, updateTable)
  18.  
  19. function createIllegalGUI()
  20.     local sx, sh = guiGetScreenSize()
  21.     illegalWindow = guiCreateWindow((sx / 2) - (433 / 2), (sh / 2) - (334 / 2), 433, 334, "Illegal Trucker", false)
  22.     guiWindowSetSizable(illegalWindow, false)
  23.     guiSetAlpha(illegalWindow, 1.00)
  24.     guiSetVisible(illegalWindow, false)
  25.     missionsList = guiCreateGridList(9, 22, 414, 200, false, illegalWindow)
  26.     guiGridListAddColumn(missionsList, t("Mission"), 0.4)
  27.     guiGridListAddColumn(missionsList, t("Risk"), 0.1)
  28.     guiGridListAddColumn(missionsList, t("Payment"), 0.2)
  29.     guiGridListAddColumn(missionsList, t("Deliveries miss"), 0.2)
  30.     guiGridListSetSortingEnabled(missionsList, false)
  31.     getMissionButton = guiCreateButton(10, 292, 96, 32, t("Get Mission"), false, illegalWindow)
  32.     closeButton = guiCreateButton(328, 292, 95, 32, t("Close"), false, illegalWindow)
  33.     riskScrollbar = guiCreateScrollBar(9, 250, 414, 26, true, false, illegalWindow)
  34.     lowRiskLabel = guiCreateLabel(15, 225, 91, 20, t("Low Risk"), false, illegalWindow)
  35.     guiLabelSetVerticalAlign(lowRiskLabel, "center")
  36.     highRiskLabel = guiCreateLabel(332, 225, 91, 20, t("High Risk"), false, illegalWindow)
  37.     guiLabelSetHorizontalAlign(highRiskLabel, "right", false)
  38.     guiLabelSetVerticalAlign(highRiskLabel, "center")
  39.     infoLabel = guiCreateLabel(134, 286, 170, 18, t("Current Risk: "), false, illegalWindow)
  40.     guiLabelSetHorizontalAlign(infoLabel, "center", false)
  41.     guiLabelSetVerticalAlign(infoLabel, "center")
  42.     --Event Handler
  43.     addEventHandler("onClientGUIClick", closeButton, toggleIllegalWindow, false)
  44.     addEventHandler("onClientGUIClick", getMissionButton, getMission, false)
  45.     addEventHandler("onClientGUIDoubleClick", missionsList, getMission, false)
  46.     addEventHandler("onClientGUIScroll", riskScrollbar, selectRisk, false)
  47. end
  48.  
  49. function toggleIllegalWindow()
  50.     if (not crimTeam[getElementData(localPlayer, "o")] and not illegalWindow) then
  51.         return false
  52.     end
  53.     triggerServerEvent("CITcrimTruck.updateTableToPlrs", resourceRoot, true)
  54.     local veh = getPedOccupiedVehicle(localPlayer)
  55.     if (not infoMissions) then
  56.         exports.CIThelp:dm(t("Refreshing the panel. Wait a minute."), 255, 0, 0)
  57.         return false
  58.     end
  59.     local countM = 0
  60.     for i, v in pairs(infoMissions) do
  61.         countM = countM + 1
  62.     end
  63.     if (not countM or countM ~= 10) then
  64.         exports.CIThelp:dm(t("Refreshing the panel. Wait a minute."), 255, 0, 0)
  65.         return false
  66.     end
  67.     if (inTask) then
  68.         if (not illegalWindow or not guiGetVisible(illegalWindow)) then
  69.             return false
  70.         end
  71.         guiSetVisible(illegalWindow, false)
  72.         showCursor(false)
  73.         return false
  74.     end
  75.     if (getPedOccupiedVehicleSeat(localPlayer) ~= 0) then
  76.         return false
  77.     end
  78.     if (getElementSpeed(veh, 2) > 4) then
  79.         exports.CIThelp:dm(t("Stop your vehicle to be assigned to a mission!"), 255, 0, 0)
  80.         return false
  81.     end
  82.     if (not illegalWindow) then
  83.         createIllegalGUI()
  84.     end
  85.     if (not veh or not allowedVehs[getElementModel(veh)]) then
  86.         if (not illegalWindow or not guiGetVisible(illegalWindow)) then
  87.             return false
  88.         end
  89.         guiSetVisible(illegalWindow, false)
  90.         showCursor(false)
  91.         setElementHealth(localPlayer, 0)
  92.         exports.CIThelp:dm(t("You have been killed because you were trying to cheat"), 255, 0, 0)
  93.         return false
  94.     end
  95.     local state = not guiGetVisible(illegalWindow)
  96.     guiSetVisible(illegalWindow, state)
  97.     showCursor(state)
  98.     --setElementFrozen(veh, state)
  99.     if (not state) then
  100.         setElementData(localPlayer, "lccrim", nil, false)
  101.         return true
  102.     end
  103.     refreshGridList()
  104.     setElementData(localPlayer, "lccrim", 1, false)
  105. end
  106.  
  107. function selectRisk()
  108.     local number = guiScrollBarGetScrollPosition(riskScrollbar)
  109.     local risk = math.ceil((number / 20), 0)
  110.     if (risk == 0) then
  111.         risk = 1
  112.     end
  113.     guiSetText(infoLabel, t("Current Risk: %s", tostring(risk)))
  114. end
  115.  
  116. function getMission()
  117.     --Check Police
  118.     local count = 0
  119.     local x, y, z = getElementPosition(localPlayer)
  120.     for i, pol in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
  121.         if (pol == localPlayer) then
  122.             guiSetVisible(illegalWindow, false)
  123.             showCursor(false)
  124.             --setElementFrozen(veh, false)
  125.             setElementData(localPlayer, "lccrim", nil, false)
  126.         end
  127.         local x2, y2, z2 = getElementPosition(pol)
  128.         if (getDistanceBetweenPoints2D(x, y, x2, y2) < 50) then
  129.             count = count + 1
  130.         end
  131.     end
  132.     if (count ~= 0) then
  133.         exports.CIThelp:dm(t("You are near the police. Stay away to start the mission!"), 255, 0, 0)
  134.         return false
  135.     end
  136.     --
  137.     local veh = getPedOccupiedVehicle(localPlayer)
  138.     if (not veh or not allowedVehs[getElementModel(veh)]) then
  139.         if (not illegalWindow or not guiGetVisible(illegalWindow)) then
  140.             return false
  141.         end
  142.         guiSetVisible(illegalWindow, false)
  143.         showCursor(false)
  144.         setElementHealth(localPlayer, 0)
  145.         exports.CIThelp:dm(t("You have been killed because you were trying to cheat"), 255, 0, 0)
  146.         return false
  147.     end
  148.     --Send the mission to server Side.
  149.     local r, c = guiGridListGetSelectedItem(missionsList)
  150.     if (r < 0) then
  151.         return false
  152.     end
  153.     local mission = guiGridListGetItemText(missionsList, r, 1)
  154.     if (not infoMissions[mission] or infoMissions[mission][3] <= 0) then
  155.         exports.CIThelp:dm("Refreshing the panel. Wait a minute.", 255, 0, 0)
  156.         refreshGridList()
  157.         return false
  158.     end
  159.     local scrollPos = guiScrollBarGetScrollPosition(riskScrollbar)
  160.     local riskPlr = math.ceil((scrollPos / 20), 0)
  161.     if (riskPlr == 0) then
  162.         riskPlr = 1
  163.     end
  164.     toggleIllegalWindow()
  165.     triggerServerEvent("CITcrimTruck.assignedMission", resourceRoot, mission)
  166.     --Start the currently mission for client
  167.     local totalRisk = riskPlr * infoMissions[mission][1]
  168.     distanceRisk = 10 * totalRisk
  169.     if (distanceRisk <= 29) then
  170.         distanceRisk = 30
  171.     end
  172.     curMission = mission
  173.     local coords = infoMissions[mission][4][math.random(#infoMissions[mission][4])]
  174.     local px, py, pz, dx, dy, dz = coords[1], coords[2], coords[3], coords[4], coords[5], coords[6]
  175.     pMarker = createMarker(px, py, pz - 1, "cylinder", 4, 100, 0, 0, 255)
  176.     pBlip = createBlipAttachedTo(pMarker, 32)
  177.     dMarker = createMarker(dx, dy, dz - 1, "cylinder", 4, 100, 0, 0, 0)
  178.     removeEventHandler("onClientMarkerHit", pMarker, pickStuff)
  179.     removeEventHandler("onClientMarkerHit", dMarker, deliveryStuff)
  180.     addEventHandler("onClientMarkerHit", pMarker, pickStuff)
  181.     addEventHandler("onClientMarkerHit", dMarker, deliveryStuff)
  182.     local city = exports.CITmapMisc:getZoneName2(px, py, pz, false)
  183.     local zone = exports.CITmapMisc:getZoneName2(px, py, pz, true)
  184.     local distance = getDistanceBetweenPoints2D(px, py, dx, dy)
  185.     exports.CIThelp:modTextBar("illegalTruckMission", t("Company: %s.Destination: %s (%s)", mission, city, zone), 100, 0, 0, 255)
  186.     paymentInfo[localPlayer] = {mission, totalRisk, distance, infoMissions[mission][2]}
  187.     inTask = true
  188.     removeEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
  189.     removeEventHandler("didKillCommand", localPlayer, onPlrWasted)
  190.     addEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
  191.     addEventHandler("didKillCommand", localPlayer, onPlrWasted)
  192. end
  193.  
  194. function pickStuff(plr, mDim)
  195.     if (localPlayer ~= plr) then
  196.         return false
  197.     end
  198.     if (not plr or not mDim or getElementAlpha(pMarker) == 0) then
  199.         return false
  200.     end
  201.     local veh = getPedOccupiedVehicle(plr)
  202.     if (getElementModel(veh) == 435) then
  203.         return false
  204.     end
  205.     if (not veh or not allowedVehs[getElementModel(veh)]) then
  206.         exports.CIThelp:dm(t("You don't have a vehicle or you are using a wrong vehicle."), 255, 0, 0)
  207.         return false
  208.     end
  209.     if (getElementSpeed(veh, 2) > 40) then
  210.         exports.CIThelp:dm(t("You are driving too fast. Slow down to under 64 kph (40 mph)."), 255, 0, 0)
  211.         return false
  212.     end
  213.     setElementFrozen(veh, true)
  214.     setTimer(setElementFrozen, 1000, 1, veh, false)
  215.     countLoad = 0
  216.     timerLoad = setTimer(cargoLoad, 2000, 4, veh)
  217.     exports.CIThelp:modTextBar("cargoType", "Load cargo: "..countLoad.."%", 100, 0, 0, 255)
  218.     setElementAlpha(pMarker, 0)
  219.     if (pBlip) then
  220.         destroyElement(pBlip)
  221.         pBlip = nil
  222.     end
  223.     radarTimer = setTimer(searchCops, 2000, 0)
  224.     triggerServerEvent("CITcrimTruck.pickCargo", resourceRoot)
  225.     setElementData(localPlayer, "lccrim", 1, false)
  226. end
  227.  
  228. function cargoLoad(veh)
  229.     countLoad = countLoad + 25
  230.     exports.CIThelp:modTextBar("cargoType", "Load cargo: "..countLoad.."%", 100, 0, 0, 255)
  231.     if (countLoad == 100) then
  232.         --setElementFrozen(veh, false)
  233.         setElementData(localPlayer, "lccrim", nil, false)
  234.         countLoad = nil
  235.         timerLoad = nil
  236.         exports.CIThelp:modTextBar("cargoType", "")
  237.         local x, y, z = getElementPosition(dMarker)
  238.         local city = exports.CITmapMisc:getZoneName2(x, y, z, false)
  239.         local zone = exports.CITmapMisc:getZoneName2(x, y, z, true)
  240.         exports.CIThelp:modTextBar("illegalTruckMission", "Company: "..curMission..".Destination: "..city.."("..zone..").", 100, 0, 0, 255)
  241.         setElementAlpha(dMarker, 255)
  242.         dBlip = createBlipAttachedTo(dMarker, 51)
  243.         setElementDimension(dBlip, 0)
  244.     end
  245. end
  246.  
  247. function deliveryStuff(plr, mDim)
  248.     if (localPlayer ~= plr) then
  249.         return false
  250.     end
  251.     if (not plr or not mDim or getElementAlpha(source) == 0) then
  252.         return false
  253.     end
  254.     local veh = getPedOccupiedVehicle(plr)
  255.     if (getElementModel(veh) == 435) then
  256.         return false
  257.     end
  258.     if (not veh or not allowedVehs[getElementModel(veh)]) then
  259.         exports.CIThelp:dm(t("You don't have a vehicle or you are using a wrong vehicle."), 255, 0, 0)
  260.         return false
  261.     end
  262.     if (getElementSpeed(veh, 2) > 40) then
  263.         exports.CIThelp:dm(t("You are driving too fast. Slow down to under 64 kph (40 mph)."), 255, 0, 0)
  264.         return false
  265.     end
  266.     if (not getVehicleTowedByVehicle(veh)) then
  267.         exports.CIThelp:dm(t("You need pick the trailer before delivery it. Marked with Diner blip!"), 255, 0, 0)
  268.         exports.CIThelp:dm(t("You may use '/rtrailer' to recover your trailer. For use this command, the requirement is being nearby of your trailer"), 255, 0, 0)
  269.         triggerServerEvent("CITcrimTruck.pickTrailer", localPlayer)
  270.         return false
  271.     end
  272.     local hp = getElementHealth(veh)
  273.     triggerServerEvent("CITcrimTruck.paymentIllegal", resourceRoot, paymentInfo[plr], hp)
  274.     stopMission()
  275.     onPlrVehEnter(veh)
  276. end
  277.  
  278. function stopMission()
  279.     if (isTimer(distanceLeaving)) then
  280.         killTimer(distanceLeaving)
  281.         distanceLeaving = nil
  282.     end
  283.     if (pMarker) then
  284.         destroyElement(pMarker)
  285.         pMarker = nil
  286.     end
  287.     if (pBlip) then
  288.         destroyElement(pBlip)
  289.         pBlip = nil
  290.     end
  291.     if (dMarker) then
  292.         destroyElement(dMarker)
  293.         dMarker = nil
  294.     end
  295.     if (dBlip) then
  296.         destroyElement(dBlip)
  297.         dBlip = nil
  298.     end
  299.     if (isTimer(radarTimer)) then
  300.         killTimer(radarTimer)
  301.         radarTimer = nil
  302.     end
  303.     if (isTimer(timerLoad)) then
  304.         killTimer(timerLoad)
  305.         timerLoad = nil
  306.     end
  307.     removeEventHandler("onClientPlayerWasted", localPlayer, onPlrWasted)
  308.     removeEventHandler("didKillCommand", localPlayer, onPlrWasted)
  309.     setElementData(localPlayer, "lccrim", nil, false)
  310.     triggerServerEvent("CITcrimTruck.removeMarkers", resourceRoot, curMission)
  311.     exports.CIThelp:modTextBar("copSearching", "")
  312.     exports.CIThelp:modTextBar("illegalTruckMission", "")
  313.     exports.CIThelp:modTextBar("cargoType", "")
  314.     inTask = false
  315.     curMission = nil
  316.     distance = nil
  317.     paymentInfo = {}
  318. end
  319. addEvent("CITcrimTruck.stopMission", true)
  320. addEventHandler("CITcrimTruck.stopMission", localPlayer, stopMission)
  321.  
  322. function searchCops()
  323.     local copSearch = {}
  324.     local x, y, z = getElementPosition(localPlayer)
  325.     if (crimTeam[getElementData(localPlayer, "o")] and inTask and getElementDimension(localPlayer) == 0) then
  326.         for i, pol in pairs(exports.CITbusiness:getPlayersByJob("Police Service")) do
  327.             local mX, mY, mZ = getElementPosition(pol)
  328.             local distance = getDistanceBetweenPoints2D(x, y, mX, mY)
  329.             local gCrim, gPolice = getElementData(localPlayer, "g"), getElementData(pol, "g")
  330.             local sCrim, sPolice = getElementData(localPlayer, "s"), getElementData(pol, "s")
  331.             local uCrim, uPolice = getElementData(localPlayer, "n"), getElementData(pol, "n")
  332.             if (distance <= 400 and gCrim ~= gPolice and sCrim ~= sPolice and uCrim ~= uPolice) then
  333.                 copSearch[#copSearch + 1] = {distance, pol}
  334.             end
  335.         end
  336.         if (not copSearch[1]) then
  337.             exports.CIThelp:modTextBar("copSearching", "")
  338.             return false
  339.         end
  340.         table.sort(copSearch, sortMyTable)
  341.         if (copSearch[1] ~= 0) then
  342.             exports.CIThelp:modTextBar("copSearching", t("Stay away from the police to not get caught! Distance: %s m", math.ceil(copSearch[1][1], 0)), 100, 0, 0)
  343.             if (copSearch[1][1] < distanceRisk) then
  344.                 triggerServerEvent("CITcrimTruck.caughtByPolice", resourceRoot, copSearch[1][2])
  345.                 killTimer(radarTimer)
  346.             end
  347.         else
  348.             exports.CIThelp:modTextBar("copSearching", "")
  349.         end
  350.     else
  351.         exports.CIThelp:modTextBar("copSearching", "")
  352.     end
  353. end
  354.  
  355. function sortMyTable(a, b)
  356.     return a[1] < b[1]
  357. end
  358.  
  359. function onPlrVehEnter(veh, seat)
  360.     if (not allowedVehs[getElementModel(veh)] or not crimTeam[getElementData(localPlayer, "o")] or seat ~= 0 or getElementDimension(localPlayer) ~= 0) then
  361.         return false
  362.     end
  363.     if (inTask and isTimer(distanceLeaving)) then
  364.         killTimer(distanceLeaving)
  365.         distanceLeaving = nil
  366.         return true
  367.     end
  368.     unbindKey("n", "down", toggleIllegalWindow)
  369.     bindKey("n", "down", toggleIllegalWindow)
  370.     exports.CIThelp:modTextBar("illegalTruckMission", t("Press 'N' to start the illegal truck."), 100, 0, 0, 255, 30000)
  371.     removeEventHandler("onClientElementDestroy", veh, vehDestroy)
  372.     addEventHandler("onClientElementDestroy", veh, vehDestroy)
  373. end
  374.  
  375. function onPlrVehExit(veh, seat)
  376.     if (not allowedVehs[getElementModel(veh)] or not crimTeam[getElementData(localPlayer, "o")] or seat ~= 0 or getElementDimension(localPlayer) ~= 0) then
  377.         return false
  378.     end
  379.     if (inTask) then
  380.         distanceLeaving = setTimer(checkDistancePlrVeh, 5000, 6, veh)
  381.         countLeave = 0
  382.         --[[if (isElementFrozen(veh)) then
  383.             setElementFrozen(veh, false)
  384.         end]]--
  385.         setElementData(localPlayer, "lccrim", nil, false)
  386.         return true
  387.     end
  388.     exports.CIThelp:modTextBar("illegalTruckMission", "")
  389.     --setElementFrozen(veh, false)
  390.     setElementData(localPlayer, "lccrim", nil, false)
  391. end
  392.  
  393. function checkDistancePlrVeh(veh)
  394.     countLeave = countLeave + 1
  395.     if (not veh or (getPedOccupiedVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) ~= veh)) then
  396.         if (isTimer(distanceLeaving)) then
  397.             killTimer(distanceLeaving)
  398.             distanceLeaving = nil
  399.         end
  400.         stopMission()
  401.         exports.CIThelp:dm(t("The event has been canceled as your vehicle had been destroyed or changed."), 255, 0, 0)
  402.         return false
  403.     end
  404.     if (not crimTeam[getElementData(localPlayer, "o")]) then
  405.         if (isTimer(distanceLeaving)) then
  406.             killTimer(distanceLeaving)
  407.             distanceLeaving = nil
  408.         end
  409.         stopMission()
  410.         exports.CIThelp:dm(t("The event has been canceled as you changed the job!"), 255, 0, 0)
  411.         return false
  412.     end
  413.     local x, y, z = getElementPosition(localPlayer)
  414.     local x1, y1, z1 = getElementPosition(veh)
  415.     if (getDistanceBetweenPoints2D(x, y, x1, y1) > 5 or countLeave == 6) then
  416.         if (isTimer(distanceLeaving)) then
  417.             killTimer(distanceLeaving)
  418.             distanceLeaving = nil
  419.         end
  420.         --[[if (veh and isElementFrozen(veh)) then
  421.             setElementFrozen(veh, false)
  422.         end]]--
  423.         stopMission()
  424.         exports.CIThelp:dm(t("The event has been canceled as you got away from your vehicle!"), 255, 0, 0)
  425.     end
  426. end
  427.  
  428. function vehDestroy()
  429.     removeEventHandler("onClientElementDestroy", source, vehDestroy)
  430.     stopMission()
  431. end
  432.  
  433. function onPlrWasted()
  434.     if (illegalWindow and guiGetVisible(illegalWindow)) then
  435.         guiSetVisible(illegalWindow, false)
  436.         showCursor(false)
  437.     end
  438.     stopMission()
  439. end
  440.  
  441. function refreshGridList()
  442.     guiGridListClear(missionsList)
  443.     for mission, value in pairs(infoMissions) do
  444.         local row = guiGridListAddRow(missionsList)
  445.         guiGridListSetItemText(missionsList, row, 1, mission, false, false)
  446.         guiGridListSetItemText(missionsList, row, 2, tostring(value[1]), false, false)
  447.         guiGridListSetItemText(missionsList, row, 3, value[2], false, false)
  448.         guiGridListSetItemText(missionsList, row, 4, tostring(value[3]), false, false)
  449.     end
  450. end
  451.  
  452. --Cop side
  453. function updateCrimTable(cTable)
  454.     crimIllegal = cTable
  455. end
  456. addEvent("CITcrimTruck.updateCrimTable", true)
  457. addEventHandler("CITcrimTruck.updateCrimTable", localPlayer, updateCrimTable)
  458.  
  459. function copCheck()
  460.     copSearching[localPlayer] = 0
  461.     local x, y, z = getElementPosition(localPlayer)
  462.     for crim, bool in pairs(crimIllegal) do
  463.         if (crim and bool) then
  464.             local mx, my, mz = getElementPosition(crim)
  465.             local gCrim, gPolice = getElementData(crim, "g"), getElementData(localPlayer, "g")
  466.             local sCrim, sPolice = getElementData(crim, "s"), getElementData(localPlayer, "s")
  467.             local uCrim, uPolice = getElementData(crim, "n"), getElementData(localPlayer, "n")
  468.             if (getDistanceBetweenPoints2D(x, y, mx, my) <= 300 and gCrim ~= gPolice and sCrim ~= sPolice and uCrim ~= uPolice) then
  469.                 copSearching[localPlayer] = copSearching[localPlayer] + 1
  470.             end
  471.         end
  472.     end
  473.     if (copSearching[localPlayer] ~= 0) then
  474.         exports.CIThelp:modTextBar(localPlayer, "crimSearching", t(localPlayer, "Exist %s illegal trucker(s) that are close to you!", math.ceil(copSearching[localPlayer], 0)), 0, 0, 200)
  475.     else
  476.         exports.CIThelp:modTextBar(localPlayer, "crimSearching", "")
  477.     end
  478. end
  479. --
  480. function getJob(newJob, newTeam, oldJob, oldTeam)
  481.     if (crimTeam[newJob]) then
  482.         addEventHandler("onClientPlayerVehicleEnter", localPlayer, onPlrVehEnter)
  483.         addEventHandler("onClientPlayerVehicleExit", localPlayer, onPlrVehExit)
  484.     elseif (newJob == "Police Service") then
  485.         triggerServerEvent("CITcrimTruck.updateTableToPlrs", resourceRoot, false, true)
  486.         copTimer = setTimer(copCheck, 2000, 0)
  487.     else
  488.         if (copTimer) then
  489.             killTimer(copTimer)
  490.         end
  491.         removeEventHandler("onClientPlayerVehicleEnter", localPlayer, onPlrVehEnter)
  492.         removeEventHandler("onClientPlayerVehicleExit", localPlayer, onPlrVehExit)
  493.     end
  494. end
  495. addEvent("onClientLocalPlayerChangeJobOrTeam")
  496. addEventHandler("onClientLocalPlayerChangeJobOrTeam", localPlayer, getJob)
  497. setTimer(getJob, 2000, 1, getElementData(localPlayer, "o"))
  498.  
  499. --MTA exports
  500. function getElementSpeed(theElement, unit)
  501.     local unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
  502.     local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
  503.     return (Vector3(getElementVelocity(theElement)) * mult).length
  504. end
Advertisement
Add Comment
Please, Sign In to add comment