253 lines
8.1 KiB
Lua
253 lines
8.1 KiB
Lua
|
|
if Config.esxSettings.enabled and Config.qbSettings.enabled then
|
||
|
|
print('^1BOTH FRAMEWORKS ENABLED!! MAKE SURE TO ONLY ENABLE ONE FRAMEWORK IN THE CONFIG FILE!')
|
||
|
|
end
|
||
|
|
if not Config.esxSettings.enabled and not Config.qbSettings.enabled then
|
||
|
|
print('^1NO FRAMEWORK ENABLED!! MAKE SURE TO ENABLE ONE FRAMEWORK IN THE CONFIG FILE!')
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Do not remove this!
|
||
|
|
sellableVehicles = {}
|
||
|
|
|
||
|
|
newHeist = {
|
||
|
|
player = nil,
|
||
|
|
truck = nil,
|
||
|
|
trailer = nil,
|
||
|
|
npc = nil,
|
||
|
|
passenger = nil,
|
||
|
|
support = nil,
|
||
|
|
supportEnabled = nil,
|
||
|
|
weaponsEnabled = nil,
|
||
|
|
passengerEnabled = nil,
|
||
|
|
bulletproofTiresEnabled = nil,
|
||
|
|
touches = 0,
|
||
|
|
vehicles = {}
|
||
|
|
}
|
||
|
|
|
||
|
|
heist = {}
|
||
|
|
|
||
|
|
function AttemptCreateHeist()
|
||
|
|
EndHeist()
|
||
|
|
|
||
|
|
heist = json.decode(json.encode(newHeist))
|
||
|
|
|
||
|
|
heist.hash = math.random(1, 99999)
|
||
|
|
|
||
|
|
heist.startLocation = Config.startLocations[math.random(1, #Config.startLocations)]
|
||
|
|
heist.endLocation = heist.startLocation.finish
|
||
|
|
|
||
|
|
local closestPlayer = nil
|
||
|
|
local closestDistance = 99999.9
|
||
|
|
|
||
|
|
for _, playerId in ipairs(GetPlayers()) do
|
||
|
|
playerId = tonumber(playerId)
|
||
|
|
local playerCoords = GetEntityCoords(GetPlayerPed(playerId))
|
||
|
|
|
||
|
|
local distance = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, heist.startLocation.truck.x, heist.startLocation.truck.y, heist.startLocation.truck.z)
|
||
|
|
|
||
|
|
if distance < 120 then
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
if closestDistance > distance then
|
||
|
|
closestPlayer = playerId
|
||
|
|
closestDistance = distance
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if not closestPlayer then
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
heist.weaponsEnabled = true
|
||
|
|
if math.random(0, 100) > Config.weaponChance then
|
||
|
|
heist.weaponsEnabled = false
|
||
|
|
end
|
||
|
|
|
||
|
|
local odds = 0
|
||
|
|
local eventKey = nil
|
||
|
|
local hit = math.random(0, 100)
|
||
|
|
for k, event in pairs(Config.events) do
|
||
|
|
if event.chance + odds > hit and not eventKey then
|
||
|
|
eventKey = k
|
||
|
|
else
|
||
|
|
odds = odds + event.chance
|
||
|
|
end
|
||
|
|
end
|
||
|
|
if not eventKey then
|
||
|
|
eventKey = math.random(1, #Config.events)
|
||
|
|
end
|
||
|
|
|
||
|
|
heist.event = eventKey
|
||
|
|
local event = Config.events[eventKey]
|
||
|
|
|
||
|
|
local empty = 0
|
||
|
|
for k, slot in pairs(Settings.trailerSlots) do
|
||
|
|
if math.random(0, 100) <= event.vehicleSlotChance or (empty + event.minimumVehicles == #Settings.trailerSlots) then
|
||
|
|
local vehicle = event.vehicles[math.random(1, #event.vehicles)]
|
||
|
|
heist.vehicles[k] = { data = vehicle, vehicle = nil }
|
||
|
|
else
|
||
|
|
empty = empty + 1
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
heist.passengerEnabled = true
|
||
|
|
if math.random(0, 100) > event.passengerChance then
|
||
|
|
heist.passengerEnabled = false
|
||
|
|
end
|
||
|
|
|
||
|
|
heist.bulletproofTiresEnabled = true
|
||
|
|
if math.random(0, 100) > event.bulletproofTiresChance then
|
||
|
|
heist.bulletproofTiresEnabled = false
|
||
|
|
end
|
||
|
|
|
||
|
|
heist.supportEnabled = true
|
||
|
|
if math.random(0, 100) > event.supportChance then
|
||
|
|
heist.supportEnabled = false
|
||
|
|
end
|
||
|
|
|
||
|
|
heist.player = closestPlayer
|
||
|
|
Debug('starting heist, initiator: ' .. closestPlayer)
|
||
|
|
TriggerClientEvent('kq_carheist:createHeist', closestPlayer, heist)
|
||
|
|
|
||
|
|
OnHeistCreated()
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
|
||
|
|
function EndHeist()
|
||
|
|
DeleteIfExists(heist.truck)
|
||
|
|
DeleteIfExists(heist.trailer)
|
||
|
|
DeleteIfExists(heist.npc)
|
||
|
|
DeleteIfExists(heist.passenger)
|
||
|
|
|
||
|
|
if heist.supportEnabled and heist.support then
|
||
|
|
DeleteIfExists(heist.support.vehicle)
|
||
|
|
for k, ped in pairs(heist.support.peds) do
|
||
|
|
DeleteIfExists(ped)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
TriggerClientEvent('kq_carheist:endHeist', -1)
|
||
|
|
|
||
|
|
heist = json.decode(json.encode(newHeist))
|
||
|
|
end
|
||
|
|
|
||
|
|
RegisterServerEvent('kq_carheist:heistCreated')
|
||
|
|
AddEventHandler('kq_carheist:heistCreated', function(syncedHeist)
|
||
|
|
if source ~= heist.player then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
heist = syncedHeist
|
||
|
|
|
||
|
|
TriggerClientEvent('kq_carheist:startDriver', -1)
|
||
|
|
TriggerClientEvent('kq_carheist:syncHeist', -1, heist)
|
||
|
|
|
||
|
|
if Config.announceTruckDepartureToPlayers then
|
||
|
|
TriggerClientEvent('kq_carheist:announceHeist', -1, vector3(heist.startLocation.truck.x, heist.startLocation.truck.y, heist.startLocation.truck.z))
|
||
|
|
end
|
||
|
|
end)
|
||
|
|
|
||
|
|
if Config.debug then
|
||
|
|
RegisterCommand('cheist', function(source, args)
|
||
|
|
AttemptCreateHeist()
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
Citizen.CreateThread(function()
|
||
|
|
while true do
|
||
|
|
local sleep = 20000
|
||
|
|
if heist.player and heist.truck then
|
||
|
|
sleep = 4000
|
||
|
|
|
||
|
|
local truckCoords = GetEntityCoords(NetworkGetEntityFromNetworkId(heist.truck))
|
||
|
|
local trailerCoords = GetEntityCoords(NetworkGetEntityFromNetworkId(heist.trailer))
|
||
|
|
local ended = false
|
||
|
|
|
||
|
|
Debug('Truck Owner: ' .. NetworkGetEntityOwner(NetworkGetEntityFromNetworkId(heist.truck)))
|
||
|
|
Debug(truckCoords)
|
||
|
|
|
||
|
|
Debug('Trailer Owner: ' .. NetworkGetEntityOwner(NetworkGetEntityFromNetworkId(heist.trailer)))
|
||
|
|
Debug(trailerCoords)
|
||
|
|
|
||
|
|
if not DoesEntityExist(NetworkGetEntityFromNetworkId(heist.truck)) or not DoesEntityExist(NetworkGetEntityFromNetworkId(heist.trailer)) or not DoesEntityExist(NetworkGetEntityFromNetworkId(heist.npc)) then
|
||
|
|
Debug('Ending heist')
|
||
|
|
EndHeist()
|
||
|
|
ended = true
|
||
|
|
end
|
||
|
|
|
||
|
|
if not ended then
|
||
|
|
Debug('Remaining distance: ' .. GetDistanceBetweenCoords(truckCoords.x, truckCoords.y, truckCoords.z, heist.endLocation.x, heist.endLocation.y, heist.endLocation.z))
|
||
|
|
|
||
|
|
if GetDistanceBetweenCoords(truckCoords.x, truckCoords.y, truckCoords.z, heist.endLocation.x, heist.endLocation.y, heist.endLocation.z) < 18.0 and GetDistanceBetweenCoords(trailerCoords.x, trailerCoords.y, trailerCoords.z, heist.endLocation.x, heist.endLocation.y, heist.endLocation.z) < 25.0 then
|
||
|
|
Debug('Truck arrived to its destination. Ending heist')
|
||
|
|
TriggerClientEvent('kq_carheist:truckArrived', -1)
|
||
|
|
EndHeist()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
Citizen.Wait(sleep)
|
||
|
|
end
|
||
|
|
end)
|
||
|
|
|
||
|
|
|
||
|
|
Citizen.CreateThread(function()
|
||
|
|
Citizen.Wait(30000)
|
||
|
|
while true do
|
||
|
|
if Config.minimumOfficers > 0 then
|
||
|
|
local enough = false
|
||
|
|
while not enough do
|
||
|
|
local currentOfficers = GetPoliceCount()
|
||
|
|
|
||
|
|
if currentOfficers >= Config.minimumOfficers then
|
||
|
|
enough = true
|
||
|
|
else
|
||
|
|
Debug('Couldn\'t start a new heist. Not enough police online')
|
||
|
|
Citizen.Wait(120000)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if heist.player ~= nil and heist.trailer and DoesEntityExist(NetworkGetEntityFromNetworkId(heist.trailer)) and not Config.ignoreDistances then
|
||
|
|
Citizen.Wait(20000)
|
||
|
|
|
||
|
|
local tooClose = true
|
||
|
|
while tooClose do
|
||
|
|
local closestDistance = 99999.9
|
||
|
|
|
||
|
|
for _, playerId in ipairs(GetPlayers()) do
|
||
|
|
playerId = tonumber(playerId)
|
||
|
|
local playerCoords = GetEntityCoords(GetPlayerPed(playerId))
|
||
|
|
|
||
|
|
local trailerCoords = GetEntityCoords(NetworkGetEntityFromNetworkId(heist.trailer))
|
||
|
|
|
||
|
|
local distance = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, trailerCoords.x, trailerCoords.y, trailerCoords.z)
|
||
|
|
|
||
|
|
Debug('Distance: ' .. distance)
|
||
|
|
if closestDistance > distance then
|
||
|
|
closestDistance = distance
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if closestDistance > 100.0 then
|
||
|
|
tooClose = false
|
||
|
|
else
|
||
|
|
Debug('Couldn\'t start a new heist. Someone is too near the old trailer')
|
||
|
|
Citizen.Wait(60000)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
local success = false
|
||
|
|
while not success do
|
||
|
|
success = AttemptCreateHeist()
|
||
|
|
if not success then
|
||
|
|
Debug('Couldn\'t start a new heist. Someone is too close the spawn location')
|
||
|
|
Citizen.Wait(60000)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
Citizen.Wait(Config.heistSpawnTime * 60000)
|
||
|
|
end
|
||
|
|
end)
|