SHARE
TWEET

Untitled

a guest Aug 19th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local theTrain, startX, startY, startZ, toPedTimer, derailedTimer, pedx, pedy, pedz, pedr, ped, pedBlip, stx, sty, stz = nil
  2. local stationBlip, midX, midY midZ, speedCheckTimer, walkingPedTimer = nil
  3.  
  4. function theJob(peds, pedLocations, trainStLocations)
  5.     theTrain = getPedOccupiedVehicle(source) -- making the train public, that's bad practice tho. But easier to handle.
  6.     if(not startX) then
  7.         startX, startY, startZ = getElementPosition(theTrain) -- gets the starting train position to calculate the total distance.
  8.     end
  9.     destroyAllTheTimers()
  10.     derailedTimer = setTimer(checkIfDerailed, 3000, 0)
  11.     if (peds and pedLocations and trainStLocations and getElementData(source, "inMission") == "to_start_mission") then --if the element data is that, it means you need to go to ped. So i create it here.
  12.         local randomPed = pedLocations[math.random(#pedLocations)]
  13.         local randomPedID = peds[math.random(#peds)]
  14.         local randomID = randomPedID[1]
  15.         pedx = randomPed[1]
  16.         pedy = randomPed[2]
  17.         pedz = randomPed[3]
  18.         pedr = randomPed[4]
  19.         ped = createPed(randomID, pedx, pedy, pedz, pedr)
  20.         outputChatBox("" ..pedx.. "")
  21.         pedBlip = createBlipAttachedTo(ped, 62)
  22.         pedColshape = createColCircle(pedx, pedy, 1.3) -- once u hit this, you pickup the luggage.
  23.         addEventHandler("onClientColShapeHit", pedColshape, toHelpPed) -- need to make this for pedColshape only if possible.
  24.         outputChatBox("Mission started, go to the tourist and leave the train to help with the luggage")
  25.        
  26.         setElementData(source, "inMission", "to_go_to_ped") -- changes the data, this is that he needs to hit the peds colshape to pickup the luggage.
  27.     elseif(peds and pedLocations and trainStLocations and getElementData(source, "inMission") == "to_go_to_station") then --if the element data is that, it means you need to go to station. So i create it.
  28.         local randomStation = trainStLocations[math.random(#trainStLocations)]
  29.         stx = randomStation[1]
  30.         sty = randomStation[2]
  31.         stz = randomStation[3]
  32.         stationMarker = createMarker(stx, sty, stz)
  33.         stationBlip = createBlipAttachedTo(stationMarker, 19)
  34.         addEventHandler("onClientMarkerHit", stationMarker, notifyForSpeed) -- need to make this for stationMarker only if possible.
  35.         if(not midX) then
  36.             midX, midY, midZ = getElementPosition(theTrain) -- get the position of the station too so i can make the payment.
  37.         end
  38.         speedCheckTimer = setTimer(toStation, 200, 0) -- checking the speed in order to stop the train to complete the mission in the station. 
  39.     end
  40. end
  41.  
  42. addEvent("hasStarted", true)
  43. addEventHandler("hasStarted", localPlayer, theJob)
  44.  
  45. function toCheckLeave(thePlayer) -- checking if the player leaves the train so he won't abuse with faster veh
  46.     if(thePlayer ~= localPlayer) then return end
  47.     killTimer(derailedTimer)
  48.     derailedTimer = nil
  49.     if(thePlayer == localPlayer) then
  50.         if(getElementData(localPlayer, "inMission") == "to_go_to_ped") then
  51.             outputChatBox("You have 20 sconds to go to help the tourist, else you will fail the mission.")
  52.             toPedTimer = setTimer(failMission, 20000, 1)
  53.         end
  54.     else
  55.         return false
  56.     end        
  57. end
  58.  
  59. addEventHandler("onClientVehicleExit", resourceRoot, toCheckLeave)
  60.  
  61. function failMission() -- when the player fails by any means.
  62.     if (theTrain) then
  63.         outputChatBox("Mission Failed")
  64.         destroyPed()
  65.         destroyStation()
  66.         destroyAllTheTimers()
  67.         triggerServerEvent("toDestroy", resourceRoot, theTrain, localPlayer)
  68.         theTrain = nil
  69.         startX, startY, startZ, midX, midY, midZ, stx, sty, stz = nil
  70.         setElementData(localPlayer, "inMission", "to_start_mission")
  71.     else
  72.         return false
  73.     end    
  74. end
  75.  
  76. function toHelpPed(theElement) -- the ped and it's colshape here
  77.     if(theElement == localPlayer) then
  78.         if(getElementData(localPlayer, "inMission") == "to_go_to_ped") then
  79.             killTimer(toPedTimer)
  80.             toPedTimer = nil
  81.             setPedControlState(ped, "forwards", true)
  82.             walkingPedTimer = setTimer(stopWalkingPed, 2000, 1)
  83.             setPedAnimation(localPlayer, "misc", "pickup_box", 1300, false, true, false, false)
  84.             outputChatBox("Nice job now re-enter the train and move the tourist to the train station.")
  85.             setElementData(localPlayer, "inMission", "to_go_to_station") -- changing the dataso once it hits it needs to go to the station
  86.         end
  87.     else
  88.         return false
  89.     end        
  90. end
  91.  
  92. function toGetPaid(totalD) --payment here
  93.     local money = 2*totalD
  94.     math.floor(money)
  95.     triggerServerEvent("payPlayer", resourceRoot, money)
  96.     startX, startY, startZ = getElementPosition(getPedOccupiedVehicle(localPlayer))
  97.     destroyStation()
  98.     money = 0
  99.     setElementData(localPlayer, "inMission", "to_start_mission")
  100.     triggerServerEvent("onMissionDone", resourceRoot, localPlayer, 0) -- to restart the mission
  101. end
  102.  
  103. function checkIfDerailed() -- to check if the train gets derailed
  104.     local rx, ry, rz = getElementRotation(theTrain)
  105.     local thePlayer = getVehicleController(theTrain)
  106.     if(thePlayer == localPlayer) then
  107.         if(ry ~= 0) then
  108.             failMission()
  109.             outputChatBox("You failed the mission for going over the accepted speed limit and getting your train derailed.")
  110.         end
  111.     end    
  112. end
  113.  
  114. function toStation()  -- the station marker function, how it works.
  115.     local driver = getVehicleController(theTrain)
  116.     if(driver == localPlayer and getElementModel(theTrain) == 449) then
  117.         local tx, ty, tz = getElementPosition(theTrain)
  118.         local dist = getDistanceBetweenPoints3D(stx, sty, stz, tx, ty, tz)
  119.         if (dist < 10) then
  120.             local speedx, speedy, speedz = getElementVelocity(theTrain)
  121.             local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)
  122.             local speed = actualspeed * 180
  123.             if (speed < 20) then
  124.                 if(speedCheckTimer) then
  125.                     killTimer(speedCheckTimer)
  126.                     speedCheckTimer = nil
  127.                 end
  128.                 stopTrainTimer = setTimer(keepTrainStopped, 50, 100)
  129.                 local first = getDistanceBetweenPoints3D(startX, startY, startZ, midX, midY, midZ)
  130.                 local second = getDistanceBetweenPoints3D(midX, midY, midZ, stx, sty, stz)
  131.                 local total = first + second
  132.                 toGetPaid(total)
  133.                 startX, startY, startZ, midX, midY, midZ, stx, sty, stz = nil      
  134.             end
  135.         end
  136.     else
  137.         failMission()
  138.         setElementData(localPlayer, "inMission", "to_start_mission")
  139.     end        
  140. end
  141.  
  142. function destroyPed()
  143.     if(ped) then
  144.         destroyElement(ped)
  145.         destroyElement(pedBlip)
  146.         destroyElement(pedColshape)
  147.         pedx, pedy, pedz = nil
  148.     end
  149. end
  150.  
  151. function destroyStation()
  152.     if(stationMarker) then
  153.         destroyElement(stationMarker)
  154.         destroyElement(stationBlip)
  155.         stationMarker, stationBlip = nil
  156.         randomStation, stx, sty, stz = nil
  157.     end
  158. end
  159.  
  160. function stopWalkingPed()
  161.     destroyPed()
  162.     killTimer(walkingPedTimer)
  163.     walkingPedTimer = nil
  164. end
  165.  
  166. function keepTrainStopped()
  167.     setTrainSpeed(theTrain, 0)
  168. end
  169.  
  170. function notifyForSpeed(hitPlayer)
  171.     if(hitPlayer == localPlayer) then
  172.         outputChatBox("Slow down your train")
  173.     end
  174. end
  175.  
  176. function notifyPlayerForJob()
  177.     outputChatBox("I guess that's all I need to do for that since my job starts once the player enters the train, also for start shift. All we need is to give him info i guess.")
  178. end
  179.  
  180. function checkPlayerForResigned()
  181.     if(theTrain) then
  182.         failMission()
  183.     else
  184.         return false
  185.     end    
  186. end
  187.  
  188. function destroyAllTheTimers()
  189.     killTimer(toPedTimer)
  190.     killTimer(derailedTimer)
  191.     killTimer(speedCheckTimer)
  192.     killTimer(walkingPedTimer)
  193.     toPedTimer, derailedTimer, speedCheckTimer, walkingPedTimer = nil
  194. end
  195.  
  196. addEventHandler("onClientPlayerWasted", localPlayer, failMission)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top