forked from Fernando-A-Rocha/mta-add-models
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_debug.lua
More file actions
106 lines (96 loc) · 3.61 KB
/
Copy pathc_debug.lua
File metadata and controls
106 lines (96 loc) · 3.61 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
local enabled = false
local SW = guiGetScreenSize()
local debugTimer = nil
local loadedModelsStr = ""
local streamedElements = {}
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
table.insert(a, n)
end
table.sort(a)
local i = 0
local iter = function()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
return iter
end
local function getElementCustomModelString(element)
local customModel = getElementCustomModel(element)
if customModel and customModels[customModel] then
local name, baseModel = customModels[customModel].name, customModels[customModel].baseModel
return { ("%d \"%s\" (%d)"):format(customModel, name, baseModel), 0xffffa263 }
else
return { ("%d"):format(getElementModel(element)) }
end
end
local function updateDebugViewInfo()
local loadedModelsStr_ = ""
local count = 0
for customModel, v in pairsByKeys(loadedModels) do
local str = ("%d \"%s\" (%d)"):format(customModel, v.name, v.baseModel)
if loadedModelsStr_ == "" then
loadedModelsStr_ = str
else
loadedModelsStr_ = str .. ", " .. loadedModelsStr_
end
count = count + 1
end
if loadedModelsStr_ ~= "" then
loadedModelsStr = ("Loaded new models (client-side: %d):\n"):format(count) .. loadedModelsStr_
else
loadedModelsStr = "No new models loaded (client-side)"
end
streamedElements = {}
for _, element in pairs(getElementsByType("vehicle", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("object", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("ped", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
for _, element in pairs(getElementsByType("player", root, true)) do
streamedElements[element] = getElementCustomModelString(element)
end
end
local function drawDebug()
dxDrawText("Newmodels v6 Red", SW / 2, 15, SW / 2, 15, 0xffff7070, 1.5, "default-bold", "center", "center")
dxDrawText(loadedModelsStr, SW / 2, 32, SW / 2, 32, 0xFFFFFFFF, 1, "default-bold", "center", "top")
for element, customModelStr in pairs(streamedElements) do
local x, y, z = getElementPosition(element)
local sx, sy = getScreenFromWorldPosition(x, y, z + 0.5)
if sx and sy then
dxDrawText(customModelStr[1], sx, sy, sx, sy, customModelStr[2] or 0xFFFFFFFF, 1, "default", "center")
end
end
end
local function handleElementDestroyed()
streamedElements[source] = nil
end
local function toggleDebugView(cmd)
if not enabled then
if not (debugTimer) or (not isTimer(debugTimer)) then debugTimer = setTimer(updateDebugViewInfo, 1000, 0) end
addEventHandler("onClientRender", root, drawDebug, false)
addEventHandler("onClientElementDestroy", root, handleElementDestroyed)
else
if debugTimer and isTimer(debugTimer) then
killTimer(debugTimer); debugTimer = nil
end
streamedElements = {}
removeEventHandler("onClientRender", root, drawDebug)
removeEventHandler("onClientElementDestroy", root, handleElementDestroyed)
end
enabled = not enabled
outputChatBox(cmd .. " => " .. tostring(enabled))
end
addCommandHandler("newmodelsdebug", toggleDebugView, false)
if (DEBUG_VIEW_ON_BY_DEFAULT) then
executeCommandHandler("newmodelsdebug")
end