-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_shared.lua
More file actions
68 lines (61 loc) · 1.85 KB
/
utils_shared.lua
File metadata and controls
68 lines (61 loc) · 1.85 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
function isEventHandlerAdded(eventName, attachedTo, handlerFunction)
local attachedFunctions = getEventHandlers(eventName, attachedTo)
if type(attachedFunctions) == "table" and #attachedFunctions > 0 then
for i, func in ipairs(attachedFunctions) do
if func == handlerFunction then
return true
end
end
end
return false
end
function table.find(t, value)
for _, v in pairs(t) do
if v == value then
return true
end
end
return false
end
function getNextPedName(appliedAnimations)
local maxNum = 0
for _, entry in ipairs(appliedAnimations) do
local num = tostring(entry.name):match("^pasped(%d+)$")
num = tonumber(num)
if num and num > maxNum then
maxNum = num
end
end
return "pasped" .. (maxNum + 1)
end
-- Map editor autoSnap function
local camDistance = 5
local elementDiameter = 1
local radius = 5
function focusCameraOnPed(element)
if not isElement(element) then
return false
end
local elemX, elemY, elemZ = getElementPosition(element)
if not elemX or not elemY or not elemZ then
return false
end
local maxDist = radius
--
local realDistance = (maxDist / elementDiameter) * camDistance
local camX, camY, camZ, cameraLookX, cameraLookY, cameraLookZ = getCameraMatrix()
--we move backwards from the camera angle, invert the vector
local distance = getDistanceBetweenPoints3D(camX, camY, camZ, cameraLookX, cameraLookY, cameraLookZ)
local vectorX = camX - cameraLookX
local vectorY = camY - cameraLookY
local vectorZ = camZ - cameraLookZ
local ratio = realDistance / distance
vectorX = vectorX * ratio
vectorY = vectorY * ratio
vectorZ = vectorZ * ratio
-- calculate a camera position based on the current position and an offset based on the new vector
local camPosX = elemX + vectorX
local camPosY = elemY + vectorY
local camPosZ = elemZ + vectorZ
return setCameraMatrix(camPosX, camPosY, camPosZ, elemX, elemY, elemZ)
end