Jump to content

PILOT JOB


Recommended Posts

Posted

-SERVER-

local rootElement = getRootElement() 
  
local plane = {[431] = true, [437] = true} 
  
local planeTable = { 
[1]={1812.65198, -1889.86047, 13.41406}, 
[2]={1825.22791, -1635.03711, 13.38281}, 
[3]={1855.01685, -1430.47449, 13.39063}, 
[4]={1732.81580, -1296.87122, 13.44294}, 
[5]={1473.19226, -1295.77124, 13.48315}, 
[6]={1443.60376, -1498.26660, 13.37650}, 
[7]={1426.37280, -1716.12439, 13.38281}, 
[8]={1315.06909, -1656.43799, 13.38281}, 
[9]={1359.06250, -1432.39734, 13.38281}, 
[10]={1169.82983, -1392.34473, 13.41728}, 
[11]={930.76508, -1392.92627, 13.26561}, 
[12]={815.24756, -1317.91345, 13.44460}, 
[13]={585.04199, -1320.53748, 13.40609}, 
[14]={526.99365, -1624.20361, 16.63225}, 
} 
  
function getNewPilotLocation(thePlayer, ID) 
local x, y, z = planeTable[ID][1], planeTable[ID][2], planeTable[ID][3] 
triggerClientEvent(thePlayer,"pilot_set_location",thePlayer,x,y,z) 
end 
  
function onVehicleEnter(thePlayer) 
if not plane[getElementModel(source)] then return end 
if not getPlayerTeam(thePlayer) then return end 
if getTeamName(getPlayerTeam(thePlayer)) == "Pilot" then 
local x, y, z = getNewPilotLocation(thePlayer, 1) 
setElementData(thePlayer,"pilotData",1) 
  end 
end 
addEventHandler("onVehicleEnter",rootElement,onVehicleEnter) 
  
addEvent("pilot_finish",true) 
addEventHandler("pilot_finish",rootElement, 
function (client) 
if not isPedInVehicle(client) then return end 
if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end 
givePlayerMoney(client, math.random(30,60)) 
if #busTable == tonumber(getElementData(client,"pilotData")) then 
setElementData(client,"pilotData",1) 
else 
setElementData(client,"pilotData",tonumber(getElementData(client,"pilotData"))+1) 
end 
getNewPilotLocation(client, tonumber(getElementData(client,"pilotData"))) 
end) 

-CLIENT-

local client = getLocalPlayer( ) 
local rootElement = getRootElement() 
local marker = nil 
local blip = nil 
  
addEvent("pilot_set_location",true) 
addEventHandler("pilot_set_location",rootElement, 
function (x, y, z) 
marker = createMarker(tostring(x), tostring(y), tostring(z)-1, "cylinder", 3.5, 255, 255, 0, 170) 
blip = createBlipAttachedTo( marker, 0, 2, 255, 255, 0, 255 ) 
addEventHandler("onClientMarkerHit",marker,onPilotStopHit) 
end) 
  
function onPilotStopHit(hitPlayer) 
if not hitPlayer == client then return end 
triggerServerEvent("pilot_finish",client,client) 
if isElement(blip) then destroyElement(blip) end 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onPilotStopHit) 
destroyElement(marker)  
  end 
end 
  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onPilotStopHit) 
destroyElement(marker)  
end 
if isElement(blip) then destroyElement(blip) end 
end) 

Leaving the bus resets the marker. How can I make:

1) The marker stays if I get back to the bus.

2) Make a timer 10secs when leave the bus, after 10secs it will reset to the first marker.

Posted

Not entirely sure if I got you right, but here's a possible solution for your 2. question:

  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
timerDestroy = setTimer(function() 
removeEventHandler("onClientMarkerHit",marker,onPilotStopHit) 
destroyElement(marker) 
end, 10000, 1) 
end 
if isElement(blip) then  
setTimer(destroyElement(blip), 10000, 1) 
end 
end) 
  

About the 1. question: I suggest you add this in the first setTimer I made:

  
addEventHandler("OnClientVehicleEnter", rootElement, 
function() 
local veh = getPedVehicle(client) 
if veh == originalveh then -- about the originalveh, you need to make a function at the beggining of your clientside script, just declare it 
if isTimer(timerDestroy) then 
killTimer(timerDestroy) 
end 
end 
end) 
  

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...