forked from gptrk0/mtasa-pAttach
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexports.lua
More file actions
208 lines (171 loc) · 6.56 KB
/
Copy pathexports.lua
File metadata and controls
208 lines (171 loc) · 6.56 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
--[[ _ _ _
/\ | | | | | |
_ __ / \ | |_ | |_ __ _ ___ | |__
| '_ \ / /\ \ | __|| __|/ _` | / __|| '_ \
| |_) |/ ____ \| |_ | |_| (_| || (__ | | | |
| .__//_/ \_\\__| \__|\__,_| \___||_| |_|
| |
|_|
-- https://github.com/Patrick2562/mtasa-pAttach
-- https://mtasa.com/discord
]]
local isClientSide = isElement(localPlayer)
if isClientSide then
function attach(...)
return pAttach:attach(...)
end
addEvent("pAttach:attach", true)
addEventHandler("pAttach:attach", resourceRoot, attach)
function detach(...)
return pAttach:detach(...)
end
addEvent("pAttach:detach", true)
addEventHandler("pAttach:detach", resourceRoot, detach)
function detachAll(...)
return pAttach:detachAll(...)
end
addEvent("pAttach:detachAll", true)
addEventHandler("pAttach:detachAll", resourceRoot, detachAll)
function setPositionOffset(...)
return pAttach:setPositionOffset(...)
end
addEvent("pAttach:setPositionOffset", true)
addEventHandler("pAttach:setPositionOffset", resourceRoot, setPositionOffset)
function setRotationOffset(...)
return pAttach:setRotationOffset(...)
end
addEvent("pAttach:setRotationOffset", true)
addEventHandler("pAttach:setRotationOffset", resourceRoot, setRotationOffset)
function setPed(...)
return pAttach:setPed(...)
end
addEvent("pAttach:setPed", true)
addEventHandler("pAttach:setPed", resourceRoot, setPed)
function setBone(...)
return pAttach:setBone(...)
end
addEvent("pAttach:setBone", true)
addEventHandler("pAttach:setBone", resourceRoot, setBone)
function invisibleAll(...)
return pAttach:invisibleAll(...)
end
addEvent("pAttach:invisibleAll", true)
addEventHandler("pAttach:invisibleAll", resourceRoot, invisibleAll)
function isAttached(...)
return pAttach:isAttached(...)
end
function setDetails(...)
return pAttach:setDetails(...)
end
function getDetails(...)
return pAttach:getDetails(...)
end
function getAttacheds(...)
return pAttach:getAttacheds(...)
end
else
local cache = {}
function attach(element, ped, boneid, ox, oy, oz, rx, ry, rz)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
cache[element] = { element, ped, boneid, ox or 0, oy or 0, oz or 0, rx or 0, ry or 0, rz or 0 }
return triggerClientEvent("pAttach:attach", resourceRoot, element, ped, boneid, ox, oy, oz, rx, ry, rz)
end
function detach(element)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
cache[element] = nil
return triggerClientEvent("pAttach:detach", resourceRoot, element)
end
function detachAll(ped)
assert(isElement(ped), "Expected element at argument 1, got "..type(ped))
for element, data in pairs(cache) do
if data[2] == ped then
cache[element] = nil
end
end
return triggerClientEvent("pAttach:detachAll", resourceRoot, ped)
end
function setPositionOffset(element, x, y, z)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
cache[element][4] = x or 0
cache[element][5] = y or 0
cache[element][6] = z or 0
return triggerClientEvent("pAttach:setPositionOffset", resourceRoot, element, x, y, z)
end
function setRotationOffset(element, x, y, z)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
cache[element][7] = x or 0
cache[element][8] = y or 0
cache[element][9] = z or 0
return triggerClientEvent("pAttach:setRotationOffset", resourceRoot, element, x, y, z)
end
function setPed(element, ped)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
assert(isElement(ped), "Expected element at argument 2, got "..type(ped))
cache[element][2] = ped
return triggerClientEvent("pAttach:setPed", resourceRoot, element, ped)
end
function setBone(element, boneid)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
cache[element][3] = boneid
return triggerClientEvent("pAttach:setBone", resourceRoot, element, boneid)
end
function invisibleAll(ped, bool)
for element, data in pairs(cache) do
if data[2] == ped then
setElementAlpha(element, bool and 0 or 255)
end
end
return true
end
function isAttached(element)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
return cache[element] and true or false
end
function setDetails(element, ped, boneid, ox, oy, oz, rx, ry, rz)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
local details = getDetails(element)
cache[element] = {
element,
ped or details[2],
boneid or details[3],
ox or details[4], oy or details[5], oz or details[6],
rx or details[7], ry or details[8], rz or details[9]
}
return triggerClientEvent("pAttach:setDetails", resourceRoot, element, ped, boneid, ox, oy, oz, rx, ry, rz)
end
function getDetails(element)
assert(isElement(element), "Expected element at argument 1, got "..type(element))
return cache[element] or false
end
function getAttacheds(ped)
assert(isElement(ped), "Expected element at argument 1, got "..type(element))
local list = {}
for element, data in pairs(cache) do
if data[2] == ped then
list[ #list + 1 ] = element
end
end
return list
end
function requestCache()
if isElement(client) then
triggerClientEvent(client, "pAttach:receiveCache", resourceRoot, cache)
end
end
addEvent("pAttach:requestCache", true)
addEventHandler("pAttach:requestCache", resourceRoot, requestCache)
addEventHandler("onPlayerQuit", root, function()
detachAll(source)
end)
addEventHandler("onElementDestroy", root, function()
if cache[source] then
detach(source)
elseif getElementType(source) == "ped" then
for element, data in pairs(cache) do
if data[2] == source then
cache[element] = nil
end
end
end
end)
end