-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.lua
177 lines (148 loc) · 5.29 KB
/
server.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
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
--[[
Resource: ide-search
File: server.lua
Author: https://github.com/Fernando-A-Rocha
Description: This resource lets you search for model IDs, DFF and TXD names in all of GTA's ide files (as well as SAMP.ide)
You can use it for finding which DFF models use a certain TXD file, etc
Useful link(s):
https://dev.prineside.com/en/gtasa_samp_model_id/ - You can use this platform to search for objects via Model ID/Name
and view its properties including DFF & TXD files it uses
Example:
lae2_ground04 [17513] - https://dev.prineside.com/en/gtasa_samp_model_id/model/17513-lae2_ground04/
DFF: lae2_ground04.dff
TXD: landlae2e.txd
With this script you can search 'landlae2e.txd' and see that it's also used by:
grass_bank [17866] - https://dev.prineside.com/en/gtasa_samp_model_id/model/17866-grass_bank/
Commands: /searchide & /listide
]]
local ideList = {}
-- [Exported]
function getIdeList()
return ideList
end
addEventHandler( "onResourceStart", resourceRoot,
function (startedResource)
local meta = xmlLoadFile("meta.xml")
if not meta then return outputDebugString("Failed to load meta.xml", 1) end
local found = {}
local nodes = xmlNodeGetChildren(meta)
for i, node in pairs(nodes) do
if xmlNodeGetName(node) == "file" then
local src = xmlNodeGetAttribute(node, "src")
local download = xmlNodeGetAttribute(node, "download")
if src and download == "false" then
table.insert(found, src)
end
end
end
xmlUnloadFile(meta)
-- Parse all
for k,src in pairs(found) do
local f = fileOpen(src)
if not f then return outputDebugString("Aborting: failed to load "..src, 1) end
local str = fileRead(f, fileGetSize(f))
fileClose(f)
local idename = split(split(src, "/")[2], ".")[1]
ideList[idename] = {}
local lines = split(str, "\n")
for j, line in pairs(lines) do
line = line:gsub("%\r", "")
local s
if idename == "vehicles" then
-- comma missing after emperor and wayfarer so we just split using tabs instead coz that works
line = line:gsub(",", "")
s = split(line,"\t")
else
s = split(line,",")
end
if s and s[1] and s[2] and s[3] then
local model = tonumber(s[1])
local dff = string.gsub(s[2], '%s+', '')
local txd = string.gsub(s[3], '%s+', '')
if model and (not tonumber(dff)) and (not tonumber(txd)) then
if dff == "emperoremperor" then
iprint(s)
end
table.insert(ideList[idename], {model=model, dff=dff, txd=txd})
end
end
end
end
end)
function listIdeFiles(thePlayer, cmd)
outputChatBox("Total IDE files parsed: "..table.size(ideList), thePlayer, 255, 194, 14)
outputChatBox("Loading GUI...", thePlayer, 187,187,187)
triggerClientEvent(thePlayer, "ide-search:viewList", resourceRoot, ideList)
end
addCommandHandler("listide", listIdeFiles, false, false)
function searchInIde(thePlayer, cmd, idename, stype, svalue)
if not idename or not stype or not svalue then
outputChatBox("SYNTAX: /"..cmd.." [IDE File Name] [Search Type] [...]", thePlayer, 255,194,14)
outputChatBox("You can enter 'all' to search all IDE files", thePlayer, 255,255,255)
outputChatBox("Search Types: model, dff, txd", thePlayer, 255,255,255)
outputChatBox("TIP: You can also use /listide to search via GUI", thePlayer, 187,187,187)
return
end
idename = string.lower(idename)
local search = idename
if idename ~= "all" then
local f = split(idename, ".")
if f and f[2] == "ide" then
search = f[1]
end
local found = false
for name,_ in pairs(ideList) do
if name == search then
found = true
break
end
end
if not found then
return outputChatBox("There's no .ide file in 'files' with the name: "..search, thePlayer, 255, 25, 25)
end
end
stype = string.lower(stype)
if not (stype == "model" or stype == "dff" or stype == "txd") then
return searchInIde(thePlayer, cmd)
end
if stype == "model" and not tonumber(svalue) then
return outputChatBox(stype.." is to search for Model ID in .ide", thePlayer, 255, 25, 25)
end
if stype == "dff" then
local f = split(svalue, ".")
if f and f[2] == "dff" then
svalue = f[1]
end
end
if stype == "txd" then
local f = split(svalue, ".")
if f and f[2] == "txd" then
svalue = f[1]
end
end
outputChatBox("Searching..", thePlayer, 187, 187, 187)
local count = 0
for name,list in pairs(ideList) do
if (search=="all" or search==name) then
for k,v in pairs(list) do
if stype == "model" and (tonumber(v.model) == tonumber(svalue))
or stype == "dff" and (string.find(string.lower(v.dff), string.lower(svalue)))
or stype == "txd" and (string.find(string.lower(v.txd), string.lower(svalue))) then
outputChatBox("#ffe600 "..v.model.." |#2ef5ff "..v.dff..".dff |#ff96fd "..v.txd..".txd #b3b3b3("..name..".ide)", thePlayer, 255, 255, 255, true)
count = count + 1
end
end
end
end
if count > 0 then
outputChatBox("Found "..count.." results for: "..stype.." '"..svalue.."' in "..search.." IDE", thePlayer, 25, 255, 25)
else
outputChatBox("No results found for: "..stype.." '"..svalue.."' in "..search.." IDE", thePlayer, 255, 50, 50)
end
end
addCommandHandler("searchide", searchInIde, false, false)
function table.size(tab)
local length = 0
for _ in pairs(tab) do length = length + 1 end
return length
end