-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
103 lines (86 loc) · 2.21 KB
/
utils.lua
File metadata and controls
103 lines (86 loc) · 2.21 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
_G.UnixLib = _G.UnixLib or {}
local Utils = {}
function Utils.Print(...)
if Config.Debug then
print('[UnixLib] ', ...)
end
end
function Utils.Warning(...)
print('[UnixLib] WARNING: ', ...)
end
function Utils.Error(...)
print('[UnixLib] ERROR: ', ...)
end
function Utils.IsRunning(name)
return GetResourceState(name) == 'started'
end
function Utils.WaitForResource(name, timeout)
local start = os.time()
while not Utils.IsRunning(name) do
Wait(100)
if os.time() - start > (timeout or 5000) / 1000 then
return false
end
end
return true
end
function Utils.Export(resource, export, ...)
local success, result = pcall(exports[resource][export], ...)
if success then
return result
end
Utils.Warning(string.format('Export %s:%s not available: %s', resource, export, result))
return nil
end
function Utils.GetPlayer(source)
if Framework == 'esx' then
return exports.esx:GetPlayerFromId(source)
elseif Framework == 'qbx' or Framework == 'qb' then
return exports.qbx_core:GetPlayer(source)
elseif Framework == 'ox' then
return exports.ox_core:GetPlayer(source)
end
return nil
end
function Utils.Contains(tbl, value)
for _, v in pairs(tbl) do
if v == value then return true end
end
return false
end
function Utils.Merge(default, override)
local result = {}
for k, v in pairs(default) do result[k] = v end
for k, v in pairs(override or {}) do result[k] = v end
return result
end
function Utils.GetCoords(entity)
local c = GetEntityCoords(entity)
return vector3(c.x, c.y, c.z)
end
function Utils.GetHeading(entity)
return GetEntityHeading(entity)
end
function Utils.Distance(a, b)
return #(a - b)
end
function Utils.IsVehicle(entity)
return IsEntityAVehicle(entity)
end
function Utils.GetPlate(vehicle)
return string.match(GetVehicleNumberPlateText(vehicle), "^%s*(.-)%s*$")
end
function string.trim(s)
return s:match("^%s*(.-)%s*$")
end
Utils.NotifyTypes = {
success = 'success',
error = 'error',
info = 'info',
warning = 'warning',
primary = 'info',
[1] = 'success',
[2] = 'error',
[3] = 'info',
}
return Utils