forked from alvesvin/mta-custom-marker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil-g.lua
129 lines (105 loc) · 3.37 KB
/
util-g.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
local EASING_FUNCTIONS = {
"Linear", "InQuad", "OutQuad", "InOutQuad",
"OutInQuad", "InElastic", "OutElastic", "InOutElastic",
"OutInElastic", "InBack", "OutBack", "InOutBack",
"OutInBack", "InBounce", "OutBounce", "InOutBounce",
"OutInBounce", "SineCurve", "CosineCurve"
}
function getConfig()
return {
viewDistance = viewDistance or 50,
colliderSize = colliderSize or 2,
markers = markers or {},
icons = icons or {},
colors = colors or {
icon = tocolor(255, 255, 255),
base = tocolor(255, 255, 255)
},
sizes = sizes or {
icon = 1,
base = 1.3
},
animation = animation or {
duration = 1000,
easing = "InOutQuad",
pulseMultiplier = 0.3
}
}
end
function strf(str, ...)
assert(type(str) == "string", string.format("Bad argument 1 to 'strf' (string expected got %s)", type(str)))
return string.format(str, ...)
end
function table.filter(tbl, fun)
assert(type(tbl) == "table", strf("Bad argument 1 to 'table.filter' (table expected got %s)", type(tbl)))
assert(type(fun) == "function", strf("Bad argument 2 to 'table.filter' (function expected got %s)", type(fun)))
local result = {}
for key, value in pairs(tbl) do
if fun(value, key) then
result[key] = value
end
end
return result
end
function table.includes(tbl, value)
assert(type(tbl) == "table", strf("Bad argument 1 to 'table.includes' (table expected got %s)", type(tbl)))
for _, v in pairs(tbl) do
if (v == value) then
return true
end
end
return false
end
function getVisibleMarkers(player, all_markers, maxViewDistance)
local px, py, pz = getElementPosition(player)
local pdimension = getElementDimension(player)
local pinterior = getElementInterior(player)
return table.filter(all_markers, function(marker)
local mx, my, mz =
marker.position.x,
marker.position.y,
marker.position.z
local distance = getDistanceBetweenPoints3D(
px, py, pz,
mx, my, mz
)
local samedim = pdimension == marker.dimension
local sameint = pinterior == marker.interior
return
distance <= maxViewDistance and
samedim and
sameint
end)
end
function createAnimation(duration, easing, multiplier)
assert(type(duration) == "number", strf("Bad argument 1 to 'createAnimation' (number expected got %s)", type(duration)))
assert(table.includes(EASING_FUNCTIONS, easing), "Bad argument 2 to 'createAnimation' (valid animation expected)")
local from = 0
local to = multiplier
local startTime = getTickCount()
return function()
local tick = getTickCount()
local passed = tick - startTime
local value = interpolateBetween(
from, 0, 0,
to, 0, 0,
passed / duration,
easing
)
if passed > duration then
local _to = to
to = from
from = _to
startTime = tick
end
return value
end
end
function doesIconExists(icons, icon)
for key, value in pairs(icons) do
if key == icon or value == icon then
return true
end
end
return false
end