157 lines
4.3 KiB
Lua
157 lines
4.3 KiB
Lua
debugToggle = false
|
|
objectsToRegister = {}
|
|
objectsToPlace = {}
|
|
objectRegister = {}
|
|
modelRegister = {}
|
|
textureRegister = {}
|
|
collisionRegister = {}
|
|
blacklistObjects = {}
|
|
-- Blacklist for SanVice:
|
|
-- blacklistObjects[7479] = true
|
|
-- blacklistObjects[7316] = true
|
|
-- blacklistObjects[7317] = true
|
|
-- blacklistObjects[7318] = true
|
|
-- blacklistObjects[10904] = true
|
|
-- blacklistObjects[1205] = true
|
|
-- blacklistObjects[7324] = true
|
|
-- blacklistObjects[7319] = true
|
|
-- blacklistObjects[7320] = true
|
|
-- blacklistObjects[7321] = true
|
|
-- blacklistObjects[7322] = true
|
|
-- blacklistObjects[7323] = true
|
|
tempObj = false
|
|
|
|
logpath = "log.txt"
|
|
if fileExists(logpath) then fileDelete(logpath) end
|
|
logfile = fileCreate(logpath)
|
|
|
|
function registerCollisionArchive(path)
|
|
cols = engineGetCOLsFromLibrary(path)
|
|
for colName,colData in pairs(cols) do
|
|
colNameStd = string.lower(colName)
|
|
if collisionRegister[colNameStd] == nil then
|
|
collisionRegister[colNameStd] = engineLoadCOL(colData)
|
|
else
|
|
outputChatBox("Warning: Duplicate collision: " ..colName)
|
|
end
|
|
end
|
|
end
|
|
|
|
function displayStatus(text)
|
|
if debugToggle == false then return end
|
|
x,y = guiGetScreenSize()
|
|
dxDrawText(text .. " uwu",0,0,x,y,tocolor(0,255,0),1,"clear","center","center")
|
|
end
|
|
|
|
function debugWrite(text)
|
|
if debugToggle == false then return end
|
|
fileWrite(text)
|
|
fileFlush(logfile)
|
|
end
|
|
|
|
function registerObject(...) -- id,model,texture,drawDistance
|
|
table.insert(objectsToRegister,arg)
|
|
end
|
|
|
|
function registerObjectNow(id,model,texture,drawDistance)
|
|
modelStd = string.lower(model)
|
|
textureStd = string.lower(texture)
|
|
|
|
if blacklistObjects[id] then
|
|
debugWrite("Skipping object " ..tostring(id).. " (" ..texture.. " + " ..model.. ") - Blacklisted.\n")
|
|
return
|
|
end
|
|
|
|
if textureRegister[textureStd] == nil then
|
|
debugWrite("Loading texture: " ..texture.. "\n")
|
|
textureRegister[textureStd] = engineLoadTXD("img/" ..texture.. ".txd")
|
|
end
|
|
|
|
if modelRegister[modelStd] == nil then
|
|
debugWrite("Loading model: " ..model.. "\n")
|
|
modelRegister[modelStd] = engineLoadDFF("img/" ..model.. ".dff")
|
|
end
|
|
|
|
realID = engineRequestModel("object",10768)
|
|
debugWrite("Making object " ..tostring(id).. ": " ..texture.. " + " ..model.. " = " ..tostring(realID).. "\n")
|
|
colAvailable = false
|
|
if collisionRegister[modelStd] ~= nil then
|
|
engineReplaceCOL(collisionRegister[modelStd],realID)
|
|
colAvailable = true
|
|
end
|
|
engineImportTXD(textureRegister[textureStd],realID)
|
|
engineReplaceModel(modelRegister[modelStd],realID)
|
|
engineSetModelLODDistance(realID,drawDistance)
|
|
objectRegister[id] = {}
|
|
objectRegister[id]["realID"] = realID
|
|
objectRegister[id]["colAvailable"] = colAvailable
|
|
|
|
if tempObj then
|
|
destroyElement(tempObj)
|
|
end
|
|
|
|
if debugToggle == true then
|
|
x,y,z = getElementPosition(localPlayer)
|
|
tempObj = createObject(realID,x,y,z)
|
|
setElementCollisionsEnabled(tempObj,false)
|
|
end
|
|
|
|
displayStatus("Loaded model: " ..model.. ", " ..tostring(#objectsToRegister).. " remaining...")
|
|
end
|
|
|
|
function placeObject(...) -- id,interior,x,y,z,rx,ry,rz,rw,lod
|
|
table.insert(objectsToPlace,arg)
|
|
end
|
|
|
|
function placeObjectNow(id,interior,x,y,z,rx,ry,rz,rw,lod)
|
|
if objectRegister[id] == nil then return end
|
|
erx,ery,erz = fromQuaternion(rx,ry,rz,rw)
|
|
obj = createObject(objectRegister[id]["realID"],x,y + 6000,z,erx,ery,erz)
|
|
setElementInterior(obj,interior)
|
|
if not objectRegister[id]["colAvailable"] then
|
|
setElementCollisionsEnabled(obj,false)
|
|
end
|
|
displayStatus("Placed model: " ..tostring(id).. ", " ..tostring(#objectsToPlace).. " remaining...")
|
|
end
|
|
|
|
function handleLoading()
|
|
if debugToggle == true then
|
|
if #objectsToRegister > 0 then
|
|
object = table.remove(objectsToRegister,1)
|
|
registerObjectNow(unpack(object))
|
|
return
|
|
end
|
|
else
|
|
while #objectsToRegister > 0 do
|
|
object = table.remove(objectsToRegister,1)
|
|
registerObjectNow(unpack(object))
|
|
end
|
|
end
|
|
|
|
if tempObj then
|
|
destroyElement(tempObj)
|
|
end
|
|
|
|
if debugToggle == true then
|
|
if #objectsToPlace > 0 then
|
|
object = table.remove(objectsToPlace,1)
|
|
placeObjectNow(unpack(object))
|
|
return
|
|
end
|
|
else
|
|
while #objectsToPlace > 0 do
|
|
object = table.remove(objectsToPlace,1)
|
|
placeObjectNow(unpack(object))
|
|
end
|
|
end
|
|
end
|
|
|
|
addEventHandler("onClientRender",root,handleLoading)
|
|
|
|
addEventHandler("onClientResourceStop",root,function(res)
|
|
if res == resource then
|
|
for key,_ in pairs(objectRegister) do
|
|
engineFreeModel(objectRegister[key]["realID"])
|
|
end
|
|
end
|
|
end) |