-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_s.lua
85 lines (69 loc) · 2.23 KB
/
core_s.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
local models = {}
-- Read directory and look for
-- model files (.txd, .dff, .col, .conf)
local function ReadDir(path)
local tbl = {}
for _,entry in ipairs(pathListDir(path)) do
local modelName
do
local offset = entry:find('%.')
if not offset then
modelName = entry
end
modelName = entry:sub(1, offset-1)
end
if entry:endswith('.txd') then
local txd = GetFileData(path..'/'..entry)
if not tbl[modelName] then
tbl[modelName] = {}
end
tbl[modelName].txd = txd
end
if entry:endswith('.dff') then
local dff = GetFileData(path..'/'..entry)
if not tbl[modelName] then
tbl[modelName] = {}
end
tbl[modelName].dff = dff
end
if entry:endswith('.col') then
local col = GetFileData(path..'/'..entry)
if not tbl[modelName] then
tbl[modelName] = {}
end
tbl[modelName].col = col
end
-- special: For vehicles and peds only
if entry:endswith('.conf') then
local config
local xml = xmlLoadFile(path..'/'..entry)
if xml then
for _,node in ipairs(xmlNodeGetChildren(xml) or {}) do
-- load data for model
local propName, propValue = ML.Funcs.XML.LoadData(node)
if propName and propValue then
config[propName] = propValue
end
end
xmlUnloadFile(xml)
end
if not tbl[modelName] then
tbl[modelName] = {}
end
tbl[modelName].config = config
end
end
return tbl
end
-- When resource starts, read model directory
addEventHandler('onResourceStart', resourceRoot, function()
models.vehicles = ReadDir('models/vehicles')
models.peds = ReadDir('models/peds')
end)
-- Export functions --
function ReplaceModel(model, id)
return triggerClientEvent(root, resourceName..':ReplaceModel', root, model, id)
end
function GetModels()
return models
end