ed
This commit is contained in:
parent
510e3ffcf2
commit
f43cf424cf
305 changed files with 34683 additions and 0 deletions
|
@ -0,0 +1,117 @@
|
|||
ItemsBuilder = ItemsBuilder or {}
|
||||
|
||||
ItemsBuilder = {}
|
||||
|
||||
---This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge.
|
||||
---@param invoking string
|
||||
---@param itemsTable table
|
||||
ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB)
|
||||
if not itemsTable then return end
|
||||
invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge"
|
||||
|
||||
local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items")
|
||||
|
||||
-- remove any doubles slashes after initial double slash
|
||||
-- resourcePath = resourcePath:gsub("//", "/")
|
||||
-- check if directory exists
|
||||
local folder = io.open(resourcePath, "r")
|
||||
if not folder then
|
||||
local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath)
|
||||
local returned, err = io.popen(createDirectoryCMD)
|
||||
if not returned then
|
||||
print("🌮 Failed to create directory: ", err)
|
||||
return
|
||||
end
|
||||
returned:close()
|
||||
print("🌮 Created Directory: ", resourcePath)
|
||||
else
|
||||
folder:close()
|
||||
end
|
||||
|
||||
local qbOld = {}
|
||||
local qbNew = {}
|
||||
local oxInventory = {}
|
||||
if useQB then
|
||||
for key, item in pairs(itemsTable) do
|
||||
qbOld[key] = string.format(
|
||||
"['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},",
|
||||
key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description
|
||||
)
|
||||
qbNew[key] = string.format(
|
||||
"['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},",
|
||||
key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description
|
||||
)
|
||||
imagewithoutpng = item?.image and item.image:gsub(".png", "")
|
||||
shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key
|
||||
oxInventory[key] = string.format(
|
||||
[[
|
||||
["%s"] = {
|
||||
label = "%s",
|
||||
description = "%s",
|
||||
weight = %s,
|
||||
stack = %s,
|
||||
close = %s,
|
||||
%s
|
||||
}, ]],
|
||||
key, item.label, item.description, item.weight, not item.unique, item.shouldClose,
|
||||
shouldRenderImage and item.image and string.format([[client = {
|
||||
image = '%s'
|
||||
}]], item.image) or ""
|
||||
)
|
||||
end
|
||||
|
||||
else
|
||||
for key, item in pairs(itemsTable) do
|
||||
-- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'},
|
||||
|
||||
qbOld[key] = string.format(
|
||||
"['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},",
|
||||
key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description
|
||||
)
|
||||
qbNew[key] = string.format(
|
||||
"['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},",
|
||||
key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description
|
||||
)
|
||||
imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "")
|
||||
shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key
|
||||
oxInventory[key] = string.format(
|
||||
[[
|
||||
["%s"] = {
|
||||
label = "%s",
|
||||
description = "%s",
|
||||
weight = %s,
|
||||
stack = %s,
|
||||
close = %s,
|
||||
%s
|
||||
}, ]],
|
||||
key, item.label, item.description, item.weight, item.stack, item.close,
|
||||
shouldRenderImage and item?.client?.image and string.format( [[client = {
|
||||
image = '%s'
|
||||
}]], item.client.image) or ""
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local function write(fileName, content)
|
||||
local filePath = resourcePath .. fileName
|
||||
local file = io.open(filePath, "w")
|
||||
if file then
|
||||
for key, value in pairs(content) do
|
||||
file:write(string.format("%s\n", value))
|
||||
end
|
||||
file:close()
|
||||
print("🌮 Items File Created: " .. filePath)
|
||||
else
|
||||
print("🌮 Something Broke for: " .. filePath)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
write(invoking.."(".."qb_core_old).lua", qbOld)
|
||||
write(invoking.."(".."qb_core_new).lua", qbNew)
|
||||
write(invoking.."(".."ox_inventory).lua", oxInventory)
|
||||
end
|
||||
|
||||
exports('ItemsBuilder', ItemsBuilder)
|
||||
return ItemsBuilder
|
|
@ -0,0 +1,74 @@
|
|||
LootTable = LootTable or {}
|
||||
|
||||
local lootTables = {}
|
||||
|
||||
LootTable.Register = function(name, items)
|
||||
local repackedTable = {}
|
||||
for k, v in pairs(items) do
|
||||
table.insert(repackedTable, {
|
||||
name = k,
|
||||
min = v.min,
|
||||
max = v.max,
|
||||
chance = v.chance,
|
||||
tier = v.tier,
|
||||
item = v.item,
|
||||
metadata = v.metadata
|
||||
})
|
||||
end
|
||||
lootTables[name] = repackedTable
|
||||
return lootTables[name]
|
||||
end
|
||||
|
||||
LootTable.Get = function(name)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
return lootTables[name] or {}
|
||||
end
|
||||
|
||||
LootTable.GetRandomItem = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = lootTables[name] or {}
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
for _, v in pairs(lootTable) do
|
||||
if v.chance <= chance and tier == v.tier then
|
||||
return { item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
LootTable.GetRandomItems = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = LootTable.Get(name)
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
local items = {}
|
||||
for _, v in pairs(lootTable) do
|
||||
if v.chance <= chance and tier == v.tier then
|
||||
table.insert(items,{item = v.item, metadata = v.metadata, count = math.random(v.min, v.max), tier = v.tier, chance = v.chance})
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
|
||||
LootTable.GetRandomItemsWithLimit = function(name, tier, randomNumber)
|
||||
assert(name, "No Name Passed For Loot Table")
|
||||
if tier == nil then tier = 1 end
|
||||
local lootTable = LootTable.Get(name)
|
||||
math.randomseed(GetGameTimer())
|
||||
local chance = randomNumber or math.random(1, 100)
|
||||
local items = {}
|
||||
for k = #lootTable, 1, -1 do
|
||||
local v = lootTable[k]
|
||||
if chance <= v.chance and tier == v.tier then
|
||||
table.insert(items, {v.item, v.metadata, math.random(v.min, v.max), v.tier, v.chance})
|
||||
table.remove(lootTable, k)
|
||||
end
|
||||
end
|
||||
return items
|
||||
end
|
||||
--
|
||||
|
||||
exports('LootTable', LootTable)
|
||||
return LootTable
|
Loading…
Add table
Add a link
Reference in a new issue