Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local theTrain, startX, startY, startZ, toPedTimer, derailedTimer, pedx, pedy, pedz, pedr, ped, pedBlip, stx, sty, stz = nil
- local stationBlip, midX, midY midZ, speedCheckTimer, walkingPedTimer = nil
- function theJob(peds, pedLocations, trainStLocations)
- theTrain = getPedOccupiedVehicle(source) -- making the train public, that's bad practice tho. But easier to handle.
- if(not startX) then
- startX, startY, startZ = getElementPosition(theTrain) -- gets the starting train position to calculate the total distance.
- end
- destroyAllTheTimers()
- derailedTimer = setTimer(checkIfDerailed, 3000, 0)
- 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.
- local randomPed = pedLocations[math.random(#pedLocations)]
- local randomPedID = peds[math.random(#peds)]
- local randomID = randomPedID[1]
- pedx = randomPed[1]
- pedy = randomPed[2]
- pedz = randomPed[3]
- pedr = randomPed[4]
- ped = createPed(randomID, pedx, pedy, pedz, pedr)
- outputChatBox("" ..pedx.. "")
- pedBlip = createBlipAttachedTo(ped, 62)
- pedColshape = createColCircle(pedx, pedy, 1.3) -- once u hit this, you pickup the luggage.
- addEventHandler("onClientColShapeHit", pedColshape, toHelpPed) -- need to make this for pedColshape only if possible.
- outputChatBox("Mission started, go to the tourist and leave the train to help with the luggage")
- setElementData(source, "inMission", "to_go_to_ped") -- changes the data, this is that he needs to hit the peds colshape to pickup the luggage.
- 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.
- local randomStation = trainStLocations[math.random(#trainStLocations)]
- stx = randomStation[1]
- sty = randomStation[2]
- stz = randomStation[3]
- stationMarker = createMarker(stx, sty, stz)
- stationBlip = createBlipAttachedTo(stationMarker, 19)
- addEventHandler("onClientMarkerHit", stationMarker, notifyForSpeed) -- need to make this for stationMarker only if possible.
- if(not midX) then
- midX, midY, midZ = getElementPosition(theTrain) -- get the position of the station too so i can make the payment.
- end
- speedCheckTimer = setTimer(toStation, 200, 0) -- checking the speed in order to stop the train to complete the mission in the station.
- end
- end
- addEvent("hasStarted", true)
- addEventHandler("hasStarted", localPlayer, theJob)
- function toCheckLeave(thePlayer) -- checking if the player leaves the train so he won't abuse with faster veh
- if(thePlayer ~= localPlayer) then return end
- killTimer(derailedTimer)
- derailedTimer = nil
- if(thePlayer == localPlayer) then
- if(getElementData(localPlayer, "inMission") == "to_go_to_ped") then
- outputChatBox("You have 20 sconds to go to help the tourist, else you will fail the mission.")
- toPedTimer = setTimer(failMission, 20000, 1)
- end
- else
- return false
- end
- end
- addEventHandler("onClientVehicleExit", resourceRoot, toCheckLeave)
- function failMission() -- when the player fails by any means.
- if (theTrain) then
- outputChatBox("Mission Failed")
- destroyPed()
- destroyStation()
- destroyAllTheTimers()
- triggerServerEvent("toDestroy", resourceRoot, theTrain, localPlayer)
- theTrain = nil
- startX, startY, startZ, midX, midY, midZ, stx, sty, stz = nil
- setElementData(localPlayer, "inMission", "to_start_mission")
- else
- return false
- end
- end
- function toHelpPed(theElement) -- the ped and it's colshape here
- if(theElement == localPlayer) then
- if(getElementData(localPlayer, "inMission") == "to_go_to_ped") then
- killTimer(toPedTimer)
- toPedTimer = nil
- setPedControlState(ped, "forwards", true)
- walkingPedTimer = setTimer(stopWalkingPed, 2000, 1)
- setPedAnimation(localPlayer, "misc", "pickup_box", 1300, false, true, false, false)
- outputChatBox("Nice job now re-enter the train and move the tourist to the train station.")
- setElementData(localPlayer, "inMission", "to_go_to_station") -- changing the dataso once it hits it needs to go to the station
- end
- else
- return false
- end
- end
- function toGetPaid(totalD) --payment here
- local money = 2*totalD
- math.floor(money)
- triggerServerEvent("payPlayer", resourceRoot, money)
- startX, startY, startZ = getElementPosition(getPedOccupiedVehicle(localPlayer))
- destroyStation()
- money = 0
- setElementData(localPlayer, "inMission", "to_start_mission")
- triggerServerEvent("onMissionDone", resourceRoot, localPlayer, 0) -- to restart the mission
- end
- function checkIfDerailed() -- to check if the train gets derailed
- local rx, ry, rz = getElementRotation(theTrain)
- local thePlayer = getVehicleController(theTrain)
- if(thePlayer == localPlayer) then
- if(ry ~= 0) then
- failMission()
- outputChatBox("You failed the mission for going over the accepted speed limit and getting your train derailed.")
- end
- end
- end
- function toStation() -- the station marker function, how it works.
- local driver = getVehicleController(theTrain)
- if(driver == localPlayer and getElementModel(theTrain) == 449) then
- local tx, ty, tz = getElementPosition(theTrain)
- local dist = getDistanceBetweenPoints3D(stx, sty, stz, tx, ty, tz)
- if (dist < 10) then
- local speedx, speedy, speedz = getElementVelocity(theTrain)
- local actualspeed = (speedx^2 + speedy^2 + speedz^2)^(0.5)
- local speed = actualspeed * 180
- if (speed < 20) then
- if(speedCheckTimer) then
- killTimer(speedCheckTimer)
- speedCheckTimer = nil
- end
- stopTrainTimer = setTimer(keepTrainStopped, 50, 100)
- local first = getDistanceBetweenPoints3D(startX, startY, startZ, midX, midY, midZ)
- local second = getDistanceBetweenPoints3D(midX, midY, midZ, stx, sty, stz)
- local total = first + second
- toGetPaid(total)
- startX, startY, startZ, midX, midY, midZ, stx, sty, stz = nil
- end
- end
- else
- failMission()
- setElementData(localPlayer, "inMission", "to_start_mission")
- end
- end
- function destroyPed()
- if(ped) then
- destroyElement(ped)
- destroyElement(pedBlip)
- destroyElement(pedColshape)
- pedx, pedy, pedz = nil
- end
- end
- function destroyStation()
- if(stationMarker) then
- destroyElement(stationMarker)
- destroyElement(stationBlip)
- stationMarker, stationBlip = nil
- randomStation, stx, sty, stz = nil
- end
- end
- function stopWalkingPed()
- destroyPed()
- killTimer(walkingPedTimer)
- walkingPedTimer = nil
- end
- function keepTrainStopped()
- setTrainSpeed(theTrain, 0)
- end
- function notifyForSpeed(hitPlayer)
- if(hitPlayer == localPlayer) then
- outputChatBox("Slow down your train")
- end
- end
- function notifyPlayerForJob()
- 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.")
- end
- function checkPlayerForResigned()
- if(theTrain) then
- failMission()
- else
- return false
- end
- end
- function destroyAllTheTimers()
- killTimer(toPedTimer)
- killTimer(derailedTimer)
- killTimer(speedCheckTimer)
- killTimer(walkingPedTimer)
- toPedTimer, derailedTimer, speedCheckTimer, walkingPedTimer = nil
- end
- addEventHandler("onClientPlayerWasted", localPlayer, failMission)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement