-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_c.lua
125 lines (107 loc) · 3.23 KB
/
core_c.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
ML.ReplacedModels = {
ped = {},
vehicle = {},
}
ML.ReplacedModelsID = {
ped = {},
vehicle = {},
}
-- Function for request ID for a model
ML.Funcs.RequestModel = function(modelType, modelName, modelData)
local id = engineRequestModel(modelType)
if not id then return end
local modelTable = {}
local col
local txd
local dff
if modelData.col then
col = engineLoadCOL(modelData.col)
if col then
engineReplaceCOL(col, id)
end
end
if modelData.txd then
txd = engineLoadTXD(modelData.txd)
if txd then
engineImportTXD(txd, id)
end
end
if modelData.dff then
dff = engineLoadDFF(modelData.dff)
if dff then
engineReplaceModel(dff, id)
end
end
modelTable.id = id
modelTable.modelName = modelName
modelTable.col = col
modelTable.txd = txd
modelTable.dff = dff
modelTable.config = modelData.config
-- replaced model
ML.ReplacedModels[modelType][modelName] = modelTable
-- helper table used for getting the model by id
ML.ReplacedModelsID[modelType][id] = modelName
return id
end
-- Function for replacing a model
ML.Funcs.ReplaceModel = function(model, id)
if not model or not isElement(model) then return end
local modelType = getElementType(model)
local modelTypeIDTable = ML.ReplacedModelsID[modelType]
if not modelTypeIDTable then return end
local modelName = modelTypeIDTable[id]
if not modelName then return end
local modelTypeTable = ML.ReplacedModels[modelType]
if not modelTypeTable then return end
local modelEntry = modelTypeTable[modelName]
if not modelEntry then return end
if modelType == 'vehicle' then
for name, value in pairs(modelEntry.config) do
if ML.Funcs.IsVehicleProperty(name) then
if not setVehicleHandling(model, name, value) then
break
end
end
end
end
if modelTypeTable == 'ped' then
for name, value in pairs(modelEntry.config) then
if ML.Funcs.IsWalkingStyle(name) then
if not setPedWalkingStyle(model, value) then
break
end
end
if ML.Funcs.IsPedStat(name) then
if not setPedStat(model, name, value) then
break
end
end
if ML.Funcs.IsPedVoice(name, value) then
if not setPedVoice(model, name, value) then
break
end
end
end
end
return setElementModel(model, id)
end
-- Free model id
ML.Funcs.FreeModel = function(id)
return engineFreeModel(id)
end
-- Replace model
addEvent(resourceName..':ReplaceModel', true)
addEventHandler(resourceName..':ReplaceModel', localPlayer, function(model, id)
if type(model) == 'table' then
for _,entry in ipairs(model) do
-- replace provided model with certain id
ML.Funcs.ReplaceModel(entry, id)
end
end
ML.Funcs.ReplaceModel(model, id)
end)
-- Export functions --
ReplaceModel = ML.Funcs.ReplaceModel
RequestModel = ML.Funcs.RequestModel
FreeModel = ML.Funcs.FreeModel