dkm
Ripped a part utility folder and shoved it into a lib. Changed a lot of Utility prefixes to the modules name. This contains breaking changes. Scripts that use 0.2.0 will need to update to match the new format
This commit is contained in:
1 parent
a08c22afed
commit
84480f8939
36 files changed
+2523
-97
No files matched your search
@@ -0,0 +1,53 @@
|
||||
Logs = Logs or {}
|
||||
|
||||
local WebhookURL = ""
|
||||
local LogoForEmbed = ""
|
||||
|
||||
Logs.Send = function(src, message)
|
||||
if not src or not message then return end
|
||||
if BridgeServerConfig.LogSystem == "builtin" then
|
||||
PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode(
|
||||
{
|
||||
username = "Community_Bridge's Logger",
|
||||
avatar_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
|
||||
embeds = {
|
||||
{
|
||||
color = "15769093",
|
||||
title = GetCurrentResourceName(),
|
||||
url = 'https://discord.gg/wsPAK5mEPg',
|
||||
--description = message,
|
||||
thumbnail = { url = LogoForEmbed },
|
||||
fields = {
|
||||
{
|
||||
name = '**Player ID**',
|
||||
value = src,
|
||||
inline = true,
|
||||
},
|
||||
{
|
||||
name = '**Player Identifier**',
|
||||
value = Framework.GetPlayerIdentifier(src),
|
||||
inline = true,
|
||||
},
|
||||
{
|
||||
name = 'Log Message',
|
||||
value = "```"..message.."```",
|
||||
inline = false,
|
||||
},
|
||||
},
|
||||
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
|
||||
footer = {
|
||||
text = "Community_Bridge | "..GetCurrentResourceName(),
|
||||
icon_url = 'https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024',
|
||||
},
|
||||
}
|
||||
}
|
||||
}), { ['Content-Type']= 'application/json' })
|
||||
elseif BridgeServerConfig.LogSystem == "qb" then
|
||||
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
|
||||
elseif BridgeServerConfig.LogSystem == "ox" then
|
||||
return exports.ox_lib:logger(src, GetCurrentResourceName(), message)
|
||||
end
|
||||
end
|
||||
|
||||
exports('Logs', Logs)
|
||||
return Logs
|
||||
@@ -0,0 +1,73 @@
|
||||
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
|
||||
@@ -0,0 +1,66 @@
|
||||
SQL = {}
|
||||
|
||||
Require("lib/MySQL.lua", "oxmysql")
|
||||
|
||||
function SQL.Create(tableName, columns)
|
||||
assert(MySQL, "Tried using module SQL without MySQL being loaded")
|
||||
local columnsList = {}
|
||||
for i, column in pairs(columns) do
|
||||
table.insert(columnsList, string.format("%s %s", column.name, column.type))
|
||||
end
|
||||
|
||||
local query = string.format("CREATE TABLE IF NOT EXISTS %s (%s);",
|
||||
tableName,
|
||||
table.concat(columnsList, ", ")
|
||||
)
|
||||
|
||||
MySQL.query.await(query)
|
||||
end
|
||||
|
||||
-- insert if not exist otherwise update
|
||||
function SQL.InsertOrUpdate(tableName, data)
|
||||
assert(MySQL, "Tried using module SQL without MySQL being loaded")
|
||||
local columns = {}
|
||||
local values = {}
|
||||
local updates = {}
|
||||
|
||||
for column, value in pairs(data) do
|
||||
table.insert(columns, column)
|
||||
table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted
|
||||
table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update
|
||||
end
|
||||
|
||||
local query = string.format(
|
||||
"INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s;",
|
||||
tableName,
|
||||
table.concat(columns, ", "),
|
||||
table.concat(values, ", "),
|
||||
table.concat(updates, ", ")
|
||||
)
|
||||
|
||||
MySQL.query.await(query)
|
||||
end
|
||||
|
||||
function SQL.Get(tableName, where)
|
||||
assert(MySQL, "Tried using module SQL without MySQL being loaded")
|
||||
local query = string.format("SELECT * FROM %s WHERE %s;", tableName, where)
|
||||
local result = MySQL.query.await(query)
|
||||
return result
|
||||
end
|
||||
|
||||
function SQL.GetAll(tableName)
|
||||
assert(MySQL, "Tried using module SQL without MySQL being loaded")
|
||||
local query = string.format("SELECT * FROM %s;", tableName)
|
||||
local result = MySQL.query.await(query)
|
||||
return result
|
||||
end
|
||||
|
||||
function SQL.Delete(tableName, where)
|
||||
assert(MySQL, "Tried using module SQL without MySQL being loaded")
|
||||
local query = string.format("DELETE FROM %s WHERE %s;", tableName, where)
|
||||
MySQL.query.await(query)
|
||||
end
|
||||
|
||||
exports('SQL', SQL)
|
||||
|
||||
return SQL
|
||||
Reference in new issue
Block a user