-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
52 lines (47 loc) · 2.1 KB
/
server.lua
File metadata and controls
52 lines (47 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local QBCore = exports['qb-core']:GetCoreObject()
local vehicles = {}
local function isVehiclePresent(plate)
local vehicles = GetAllVehicles()
for _, vehicle in pairs(vehicles) do
local pl = GetVehicleNumberPlateText(vehicle)
if pl == plate then
return true
end
end
return false
end
RegisterServerEvent('Ogi-NoDespawn:Server:AddVehicleNoDespawn', function(plate, properties, coords, model, vehicleNetId, heading)
if plate == nil or properties == nil then return end
vehicles[plate] = {properties = properties, coords = coords, model = model, vehicle = vehicle, netid = vehicleNetId, heading = heading}
end)
RegisterServerEvent('Ogi-NoDespawn:Server:RemoveVehicleNoDespawn', function(plate)
if vehicles[plate] then
vehicles[plate] = nil
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(Config.RespawnCheckInterval * 60 * 1000) -- waiting interval
local players = QBCore.Functions.GetPlayers()
for vehPlate, v in pairs(vehicles) do
local veh = NetworkGetEntityFromNetworkId(v.netid)
if not veh or not isVehiclePresent(vehPlate) then
local vehCoords = v.coords
for _, player in pairs(players) do
local playerPed = GetPlayerPed(player)
local playerCoords = GetEntityCoords(playerPed)
local dist = #(playerCoords - vector3(vehCoords.x, vehCoords.y, vehCoords.z))
if dist < Config.PlayerDistanceForDespawn then
local vehModel = v.model
local vehProps = v.properties
local vehHeading = v.heading
TriggerClientEvent('Ogi-NoDespawn:Client:UpdateDespawnedVehicle', player, vehProps, vehModel, vehPlate, vehCoords, vehHeading)
vehicles[vehPlate] = nil
Wait(1000) -- this is mandatory to avoid the vehicles being respawned with wrong properties
break
end
end
end
end
end
end)