-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
89 lines (80 loc) · 2.64 KB
/
utils.lua
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local DynamicMenuItems = {}
local FinalMenuItems = {}
-- Functions
local function deepcopy(orig) -- modified the deep copy function from http://lua-users.org/wiki/CopyTable
local orig_type = type(orig)
local copy
if orig_type == 'table' then
if not orig.canOpen or orig.canOpen() then
local toRemove = {}
copy = {}
for orig_key, orig_value in next, orig, nil do
if type(orig_value) == 'table' then
if not orig_value.canOpen or orig_value.canOpen() then
copy[deepcopy(orig_key)] = deepcopy(orig_value)
else
toRemove[orig_key] = true
end
else
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
end
for i=1, #toRemove do table.remove(copy, i) --[[ Using this to make sure all indexes get re-indexed and no empty spaces are in the radialmenu ]] end
if copy and next(copy) then setmetatable(copy, deepcopy(getmetatable(orig))) end
end
elseif orig_type ~= 'function' then
copy = orig
end
return copy
end
function isCloseVeh()
local ped = PlayerPedId()
coordA = GetEntityCoords(ped, 1)
coordB = GetOffsetFromEntityInWorldCoords(ped, 0.0, 100.0, 0.0)
vehicle = getVehicleInDirection(coordA, coordB)
if DoesEntityExist(vehicle) and NetworkHasControlOfEntity(vehicle) then
return true
end
return false
end
function isInHouse()
if IsInside then
exports['ks-houses']:isInHouse()
print(IsInside)
return true
end
return false
end
function getVehicleInDirection(coordFrom, coordTo)
local offset = 0
local rayHandle
local vehicle
for i = 0, 100 do
rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z + offset, 10, PlayerPedId(), 0)
a, b, c, d, vehicle = GetRaycastResult(rayHandle)
offset = offset - 1
if vehicle ~= 0 then break end
end
local distance = Vdist2(coordFrom, GetEntityCoords(vehicle))
if distance > 25 then vehicle = nil end
return vehicle ~= nil and vehicle or 0
end
function hasEnoughOfItem(item)
local retval = false
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
retval = true
end
return retval
end, item)
end
local function AddOption(data, id)
local menuID = id ~= nil and id or (#DynamicMenuItems + 1)
DynamicMenuItems[menuID] = deepcopy(data)
return menuID
end
local function RemoveOption(id)
DynamicMenuItems[id] = nil
end
exports('AddOption', AddOption)
exports('RemoveOption', RemoveOption)