I scripted a Capture Hijack. Looks like CIT Hijack. But It isn't working. Can you fix it?
ClientSide
local client = getLocalPlayer( )
local rootElement = getRootElement()
blip = nil
marker = nil
addEvent("clientSpawnHijack",true)
addEventHandler("clientSpawnHijack",rootElement,
function (id, x, y, z)
vehicle = createVehicle(tostring(id), tostring(x), tostring(y), tostring(z))
blip = createBlipAttachedTo( vehicle, 0, 2, 255, 255, 0, 255 )
end)
addEvent("hijack_set_location",true)
addEventHandler("hijack_set_location",rootElement,
function (x, y, z)
marker = createMarker(tostring(x), tostring(y), tostring(z))
blip = createBlipAttachedTo( vehicle, 0, 2, 255, 255, 0, 255 )
addEventHandler("onClientMarkerHit",marker,onBusStopHit)
end)
function onBusStopHit(hitPlayer)
if not hitPlayer == client then return end
triggerServerEvent("bus_finish",client,client)
if isElement(blip) then destroyElement(blip) end
if isElement(marker) then
removeEventHandler("onClientMarkerHit",marker,onBusStopHit)
destroyElement(marker)
end
end
addEventHandler("onClientVehicleExit",rootElement,
function ()
if isElement(marker) then
removeEventHandler("onClientMarkerHit",marker,onBusStopHit)
destroyElement(marker)
end
if isElement(blip) then destroyElement(blip) end
end)
ServerSide
local rootElement = getRootElement()
blip = nil
id, x, y, z = nil
local busTable = {
[1]={471, 1812.65198, -1889.86047, 13.41406},
[2]={471, 1825.22791, -1635.03711, 13.38281},
[3]={471, 1855.01685, -1430.47449, 13.39063},
[4]={471, 1732.81580, -1296.87122, 13.44294},
[5]={471, 1473.19226, -1295.77124, 13.48315},
[6]={471, 1443.60376, -1498.26660, 13.37650},
[7]={471, 1426.37280, -1716.12439, 13.38281},
[8]={471, 1315.06909, -1656.43799, 13.38281},
[9]={471, 1359.06250, -1432.39734, 13.38281},
[10]={471, 1169.82983, -1392.34473, 13.4172},
[11]={471, 930.76508, -1392.92627, 13.26561},
[12]={471, 815.24756, -1317.91345, 13.44460},
[13]={471, 585.04199, -1320.53748, 13.40609},
[14]={471, 526.99365, -1624.20361, 16.63225},
}
local locationsTable = {
[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.4172},
[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 SpawnHijack(thePlayer , ID)
local id, x, y, z = busTable[iD][1], busTable[iD][2], busTable[iD][3], busTable[iD][4]
vehicle = createVehicle(tostring(id), tostring(x), tostring(y), tostring(z))
blip = createBlipAttachedTo( vehicle, 0, 2, 255, 255, 0, 255 )
end
addEventHandler ( "onResourceStart", getRootElement(), SpawnHijack )
function getNewHijackLocation(thePlayer, ID)
local x, y, z = locationsTable[iD][1], locationsTable[iD][2], locationsTable[iD][3]
triggerClientEvent(thePlayer,"hijack_set_location",thePlayer,x,y,z)
end
function onVehicleEnter(thePlayer)
if not getPlayerTeam(thePlayer) then return end
if getTeamName(getPlayerTeam(thePlayer)) == "Criminals" then
local x, y, z = getNewHijackLocation(thePlayer, 1)
setElementData(thePlayer,"hijackData",1)
end
end
addEventHandler("onVehicleEnter",vehicle,onVehicleEnter)
addEvent("bus_finish",true)
addEventHandler("bus_finish",rootElement,
function (client)
if not isPedInVehicle(client) then return end
if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end
givePlayerMoney(client, 100)
if #busTable == tonumber(getElementData(client,"hijackData")) then
setElementData(client,"hijackData",1)
else
setElementData(client,"hijackData",tonumber(getElementData(client,"hijackData"))+1)
end
getNewHijackLocation(client, tonumber(getElementData(client,"hijackData")))
end)