Skip to content

Commit

Permalink
Merge pull request #686 from bitpredator/main
Browse files Browse the repository at this point in the history
sync fork
  • Loading branch information
bitpredator authored Mar 31, 2024
2 parents d942b97 + 82e7fc6 commit b757d49
Show file tree
Hide file tree
Showing 5 changed files with 673 additions and 0 deletions.
130 changes: 130 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_doorlock/server/convert.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---@type table?
Config.DoorList = {}

local function flattenTableToArray(tbl)
if type(tbl) == 'table' then
if table.type(tbl) == 'array' then return tbl end

local array = {}

for k in pairs(tbl) do
array[#array + 1] = k
end

return array
end
end

MySQL.ready(function()
local files, fileCount = require 'server.utils'.getFilesInDirectory('convert', '%.lua')

if fileCount > 0 then
print(('^3Found %d nui_doorlock config files.^0'):format(fileCount))
end

local query = 'INSERT INTO `bpt_doorlock` (`name`, `data`) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM `bpt_doorlock` WHERE `name` = ?)'
local queries = {}

for i = 1, fileCount do
local fileName = files[i]
local file = LoadResourceFile('bpt_doorlock', ('convert/%s.lua'):format(fileName))

if file then
load(file)()

if next(Config.DoorList) then
local size = 0

for k, door in pairs(Config.DoorList) do
size += 1
local double = door.doors
local qb = door.objName or (double and double[1].objName)

if qb then
if double then
for j = 1, 2 do
double[j].objHash = double[j].objName
double[j].objHeading = double[j].objYaw or 0
end
else
door.objHash = door.objName
door.objHeading = door.objYaw or 0
end

local groups = door.authorizedJobs or {}

if door.authorizedGangs then
for gang, grade in pairs(door.authorizedGangs) do
groups[gang] = grade
end
end

door.authorizedJobs = next(groups) and groups
door.lockpick = door.pickable
door.showNUI = not door.hideLabel
door.characters = flattenTableToArray(door.authorizedCitizenIDs)
end

local data = {
auto = door.slides or door.garage or door.sliding or door.doublesliding,
autolock = (door.autolock and door.autolock / 1000) or (door.autoLock and door.autoLock / 1000),
coords = door.objCoords,
heading = door.objHeading and math.floor(door.objHeading + 0.5),
model = door.objHash,
characters = door.characters,
groups = door.authorizedJobs,
items = door.items,
lockpick = door.lockpick,
hideUi = door.showNUI ~= nil and not door.showNUI or false,
lockSound = door.audioLock?.file and door.audioLock.file:gsub('%.ogg', ''),
unlockSound = door.audioUnlock?.file and door.audioUnlock.file:gsub('%.ogg', ''),
maxDistance = door.maxDistance or door.distance,
doorRate = door.doorRate and door.doorRate + 0.0 or nil,
state = door.locked and 1 or 0,
passcode = door.passcode,
doors = double and {
{
coords = double[1].objCoords,
heading = math.floor(double[1].objHeading + 0.5),
model = double[1].objHash,
},
{
coords = double[2].objCoords,
heading = math.floor(double[2].objHeading + 0.5),
model = double[2].objHash,
},
},
}

if data.auto and not data.lockSound then
if door.audioRemote then
data.lockSound = 'button-remote'
end
end

if double and not data.coords then
double = data.doors
data.coords = double[1].coords - ((double[1].coords - double[2].coords) / 2)
end

local name = ('%s %s'):format(fileName, k)

queries[size] = {
query = query, values = { name, json.encode(data), name }
}
end

print(('^3Loaded %d doors from convert/%s.lua.^0'):format(size, fileName))

if MySQL.transaction.await(queries) then
SaveResourceFile('bpt_doorlock', ('convert/%s.lua'):format(fileName), '-- This file has already been converted for bpt_doorlock and should be removed.\r\ndo return end\r\n\r\n' .. file, -1)
end

table.wipe(Config.DoorList)
table.wipe(queries)
end
end
end

Config.DoorList = nil
end)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
local resourceName = 'es_extended'

if not GetResourceState(resourceName):find('start') then return end

SetTimeout(0, function()
local ESX = exports[resourceName]:getSharedObject()

GetPlayer = ESX.GetPlayerFromId

if not ESX.GetConfig().OxInventory then
function RemoveItem(playerId, item)
local player = GetPlayer(playerId)

if player then player.removeInventoryItem(item, 1) end
end

---@param player table
---@param items string[] | { name: string, remove?: boolean, metadata?: string }[]
---@param removeItem? boolean
---@return string?
function DoesPlayerHaveItem(player, items, removeItem)
for i = 1, #items do
local item = items[i]
local itemName = item.name or item
local data = player.getInventoryItem(itemName)

if data?.count > 0 then
if removeItem or item.remove then
player.removeInventoryItem(itemName, 1)
end

return itemName
end
end
end
end
end)

function GetCharacterId(player)
return player.identifier
end

function IsPlayerInGroup(player, filter)
local type = type(filter)

if type == 'string' then
if player.job.name == filter then
return player.job.name, player.job.grade
end
else
local tabletype = table.type(filter)

if tabletype == 'hash' then
local grade = filter[player.job.name]

if grade and grade <= player.job.grade then
return player.job.name, player.job.grade
end
elseif tabletype == 'array' then
for i = 1, #filter do
if player.job.name == filter[i] then
return player.job.name, player.job.grade
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
local resourceName = 'qb-core'

if not GetResourceState(resourceName):find('start') then return end

SetTimeout(0, function()
local QB = exports[resourceName]:GetCoreObject()

GetPlayer = QB.Functions.GetPlayer

if GetResourceState('ox_inventory') == 'missing' then
function RemoveItem(playerId, item, slot)
local player = GetPlayer(playerId)

if player then player.Functions.RemoveItem(item, 1, slot) end
end

---@param player table
---@param items string[] | { name: string, remove?: boolean, metadata?: string }[]
---@param removeItem? boolean
---@return string?
function DoesPlayerHaveItem(player, items, removeItem)
for i = 1, #items do
local item = items[i]
local itemName = item.name or item

if item.metadata then
local playerItems = player.Functions.GetItemsByName(itemName)

for j = 1, #playerItems do
local data = playerItems[j]

if data.info.type == item.metadata then
if removeItem or item.remove then
player.Functions.RemoveItem(itemName, 1, data.slot)
end

return itemName
end
end
else
local data = player.Functions.GetItemByName(itemName)

if data then
if item.remove then
player.Functions.RemoveItem(itemName, 1, data.slot)
end

return itemName
end
end
end
end
end
end)

function GetCharacterId(player)
return player.PlayerData.citizenid
end

local groups = { 'job', 'gang' }

function IsPlayerInGroup(player, filter)
local type = type(filter)

if type == 'string' then
for i = 1, #groups do
local data = player.PlayerData[groups[i]]

if data.name == filter then
return data.name, data.grade.level
end
end
else
local tabletype = table.type(filter)

if tabletype == 'hash' then
for i = 1, #groups do
local data = player.PlayerData[groups[i]]
local grade = filter[data.name]

if grade and grade <= data.grade.level then
return data.name, data.grade.level
end
end
elseif tabletype == 'array' then
for i = 1, #filter do
local group = filter[i]

for j = 1, #groups do
local data = player.PlayerData[groups[j]]

if data.name == group then
return data.name, data.grade.level
end
end
end
end
end
end
Loading

0 comments on commit b757d49

Please sign in to comment.