Skip to content

Commit

Permalink
add object example with shared txd
Browse files Browse the repository at this point in the history
Thank you @THEGizmoOfficial <3
  • Loading branch information
Fernando-A-Rocha committed Aug 1, 2024
1 parent 9522935 commit 086d34b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 35 deletions.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions newmodels_reborn/models/object/1337/big_box/40001.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txd=object/1337/boxes.txd
Binary file added newmodels_reborn/models/object/1337/boxes.txd
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions newmodels_reborn/models/object/1337/small_box/40002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txd=object/1337/boxes.txd
92 changes: 57 additions & 35 deletions newmodels_reborn/scripts/core/server_logic.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
-- Apologies for the excess if statements, I'll clean this up later.

local CUSTOM_MODEL_SETTINGS = {
["disableAutoFree"] = true,
["disableTXDTextureFiltering"] = true,
["enableDFFAlphaTransparency"] = true,
}
-- Additionally, model settings .txt can contain path to txd, dff, and col files.

local function stringStartswith(str, start)
return str:sub(1, #start) == start
end

local function loadModels()
if not pathIsDirectory("models") then
Expand All @@ -14,7 +21,6 @@ local function loadModels()
end
for _, modelType in pairs({"vehicle", "object", "ped"}) do
local modelTypePath = "models/" .. modelType
-- Directory is optional, user might not have any custom models for this type
if pathIsDirectory(modelTypePath) then
local filesAndFoldersHere = pathListDir(modelTypePath)
if not filesAndFoldersHere then
Expand All @@ -37,42 +43,57 @@ local function loadModels()
local fileType = string.sub(thisFileName, -3)
if (fileType == "dff" or fileType == "txd" or fileType == "col" or fileType == "txt") then
local customModel = tonumber(string.sub(thisFileName, 1, -5))
if not customModel then
return false, "invalid " .. modelType .. " custom model: " .. thisFileName
end
if not customModelInfo[customModel] then
if isDefaultID(modelType, customModel) then
return false, "custom " .. modelType .. " model is a default ID: " .. customModel
end
if customModels[customModel] then
return false, "duplicate " .. modelType .. " custom model: " .. customModel
end
customModelInfo[customModel] = {}
end
if fileType == "txt" then
local file = fileOpen(thisFullPath, true)
if not file then
return false, "failed to open file: " .. thisFullPath
end
local info = fileGetContents(file, false)
fileClose(file)
if not info then
return false, "failed to read file: " .. thisFullPath
end
local customModelSettings = {}
local lines = split(info, "\n")
for _, settingName in pairs(lines) do
settingName = settingName:gsub("\r", "")
local settingType = CUSTOM_MODEL_SETTINGS[settingName]
if settingType then
customModelSettings[settingName] = true
if customModel then
if not customModelInfo[customModel] then
if isDefaultID(modelType, customModel) then
return false, "custom " .. modelType .. " model is a default ID: " .. customModel
end
if customModels[customModel] then
return false, "duplicate " .. modelType .. " custom model: " .. customModel
end
customModelInfo[customModel] = {}
end
customModelInfo[customModel].settings = customModelSettings
else
customModelInfo[customModel][fileType] = thisFullPath
if name then
customModelInfo[customModel].name = name
if fileType == "txt" then
local file = fileOpen(thisFullPath, true)
if not file then
return false, "failed to open file: " .. thisFullPath
end
local info = fileGetContents(file, false)
fileClose(file)
if not info then
return false, "failed to read file: " .. thisFullPath
end
local customModelSettings = {}
local lines = split(info, "\n")
for _, settingStr in pairs(lines) do
settingStr = settingStr:gsub("\r", "")
if CUSTOM_MODEL_SETTINGS[settingStr] then
customModelSettings[settingStr] = true
else
for _, settingModelType in pairs({"txd", "dff", "col"}) do
if stringStartswith(settingStr, settingModelType.."=") then
local settingModelPath = settingStr:sub(5)
local settingModelFullPath = "models/" .. settingModelPath
if not fileExists(settingModelFullPath) then
return false, "setting " .. settingModelType .. " file not found: " .. settingModelPath
end
if customModelInfo[customModel][settingModelType] then
return false, "duplicate " .. settingModelType .. " file for custom " .. modelType .. " model: " .. customModel
end
customModelInfo[customModel][settingModelType] = settingModelFullPath
end
end
end
end
customModelInfo[customModel].settings = customModelSettings
else
if customModelInfo[customModel][fileType] then
return false, "duplicate " .. fileType .. " file for custom " .. modelType .. " model: " .. customModel
end
customModelInfo[customModel][fileType] = thisFullPath
if name then
customModelInfo[customModel].name = name
end
end
end
end
Expand Down Expand Up @@ -109,6 +130,7 @@ local function loadModels()
name = info.name or "Unnamed",
settings = info.settings or {},
}
if modelType == "object" then iprint(customModels[customModel]) end
end
end
end
Expand Down

0 comments on commit 086d34b

Please sign in to comment.