Skip to content

Commit

Permalink
refactor: update ox_lib and oxmysql version dependencies
Browse files Browse the repository at this point in the history
Other misc changes to formatting.
  • Loading branch information
thelindat committed Aug 8, 2023
1 parent bfbb731 commit 396b5ea
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 151 deletions.
1 change: 0 additions & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ exports('openNearbyInventory', openNearbyInventory)

local currentInstance
local playerCoords
local table = lib.table
local Inventory = require 'modules.inventory.client'
local Shops = require 'modules.shops.client'

Expand Down
44 changes: 23 additions & 21 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
--[[ FX Information ]] --
fx_version 'cerulean'
use_experimental_fxv2_oal 'yes'
lua54 'yes'
game 'gta5'

--[[ Resource Information ]] --
name 'ox_inventory'
author 'Overextended'
version '2.32.1'
repository 'https://github.com/overextended/ox_inventory'
description 'Slot-based inventory with item metadata support'

--[[ Manifest ]] --
dependencies {
'/server:6116',
'/onesync',
'oxmysql',
'ox_lib',
'/server:6116',
'/onesync',
'oxmysql',
'ox_lib',
}

shared_script '@ox_lib/init.lua'

ox_libs {
'locale',
'table',
'math',
}

server_scripts {
'@oxmysql/lib/MySQL.lua',
'init.lua'
'@oxmysql/lib/MySQL.lua',
'init.lua'
}

client_script 'init.lua'

ui_page 'web/build/index.html'

files {
'client.lua',
'server.lua',
'locales/*.json',
'web/build/index.html',
'web/build/assets/*.js',
'web/build/assets/*.css',
'web/images/*.png',
'modules/**/shared.lua',
'modules/**/client.lua',
'modules/bridge/**/client.lua',
'data/*.lua',
'client.lua',
'server.lua',
'locales/*.json',
'web/build/index.html',
'web/build/assets/*.js',
'web/build/assets/*.css',
'web/images/*.png',
'modules/**/shared.lua',
'modules/**/client.lua',
'modules/bridge/**/client.lua',
'data/*.lua',
}
223 changes: 110 additions & 113 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ end
-- https://overextended.dev/ox_inventory#config

shared = {
resource = GetCurrentResourceName(),
framework = GetConvar('inventory:framework', 'esx'),
playerslots = GetConvarInt('inventory:slots', 50),
playerweight = GetConvarInt('inventory:weight', 30000),
target = GetConvarInt('inventory:target', 0) == 1,
police = json.decode(GetConvar('inventory:police', '["police", "sheriff"]')),
resource = GetCurrentResourceName(),
framework = GetConvar('inventory:framework', 'esx'),
playerslots = GetConvarInt('inventory:slots', 50),
playerweight = GetConvarInt('inventory:weight', 30000),
target = GetConvarInt('inventory:target', 0) == 1,
police = json.decode(GetConvar('inventory:police', '["police", "sheriff"]')),
}

do
if type(shared.police) == 'string' then
shared.police = { shared.police }
end
if type(shared.police) == 'string' then
shared.police = { shared.police }
end

local police = table.create(0, shared.police and #shared.police or 0)
local police = table.create(0, shared.police and #shared.police or 0)

for i = 1, #shared.police do
police[shared.police[i]] = 0
end
for i = 1, #shared.police do
police[shared.police[i]] = 0
end

shared.police = police
shared.police = police
end

if IsDuplicityVersion() then
server = {
loglevel = GetConvarInt('inventory:loglevel', 1),
randomprices = GetConvarInt('inventory:randomprices', 0) == 1,
randomloot = GetConvarInt('inventory:randomloot', 1) == 1,
evidencegrade = GetConvarInt('inventory:evidencegrade', 2),
trimplate = GetConvarInt('inventory:trimplate', 1) == 1,
vehicleloot = json.decode(GetConvar('inventory:vehicleloot', [[
server = {
loglevel = GetConvarInt('inventory:loglevel', 1),
randomprices = GetConvarInt('inventory:randomprices', 0) == 1,
randomloot = GetConvarInt('inventory:randomloot', 1) == 1,
evidencegrade = GetConvarInt('inventory:evidencegrade', 2),
trimplate = GetConvarInt('inventory:trimplate', 1) == 1,
vehicleloot = json.decode(GetConvar('inventory:vehicleloot', [[
[
["cola", 1, 1],
["water", 1, 1],
Expand All @@ -53,15 +53,15 @@ if IsDuplicityVersion() then
["bandage", 1, 1]
]
]])),
dumpsterloot = json.decode(GetConvar('inventory:dumpsterloot', [[
dumpsterloot = json.decode(GetConvar('inventory:dumpsterloot', [[
[
["mustard", 1, 1],
["garbage", 1, 3],
["money", 1, 10],
["burger", 1, 1]
]
]])),
}
}

local accounts = json.decode(GetConvar('inventory:accounts', '["money"]'))
server.accounts = table.create(0, #accounts)
Expand All @@ -70,38 +70,38 @@ if IsDuplicityVersion() then
server.accounts[accounts[i]] = 0
end
else
PlayerData = {}
client = {
autoreload = GetConvarInt('inventory:autoreload', 0) == 1,
screenblur = GetConvarInt('inventory:screenblur', 1) == 1,
keys = json.decode(GetConvar('inventory:keys', '')) or { 'F2', 'K', 'TAB' },
enablekeys = json.decode(GetConvar('inventory:enablekeys', '[249]')),
aimedfiring = GetConvarInt('inventory:aimedfiring', 0) == 1,
giveplayerlist = GetConvarInt('inventory:giveplayerlist', 0) == 1,
weaponanims = GetConvarInt('inventory:weaponanims', 1) == 1,
itemnotify = GetConvarInt('inventory:itemnotify', 1) == 1,
imagepath = GetConvar('inventory:imagepath', 'nui://ox_inventory/web/images'),
dropprops = GetConvarInt('inventory:dropprops', 0) == 1,
dropmodel = joaat(GetConvar('inventory:dropmodel', 'prop_med_bag_01b')),
weaponmismatch = GetConvarInt('inventory:weaponmismatch', 1) == 1,
ignoreweapons = json.decode(GetConvar('inventory:ignoreweapons', '[]')),
suppresspickups = GetConvarInt('inventory:suppresspickups', 1) == 1,
}

local ignoreweapons = table.create(0, (client.ignoreweapons and #client.ignoreweapons or 0) + 3)

for i = 1, #client.ignoreweapons do
local weapon = client.ignoreweapons[i]
ignoreweapons[tonumber(weapon) or joaat(weapon)] = true
end

ignoreweapons[`WEAPON_UNARMED`] = true
ignoreweapons[`WEAPON_HANDCUFFS`] = true
ignoreweapons[`WEAPON_GARBAGEBAG`] = true
ignoreweapons[`OBJECT`] = true
PlayerData = {}
client = {
autoreload = GetConvarInt('inventory:autoreload', 0) == 1,
screenblur = GetConvarInt('inventory:screenblur', 1) == 1,
keys = json.decode(GetConvar('inventory:keys', '')) or { 'F2', 'K', 'TAB' },
enablekeys = json.decode(GetConvar('inventory:enablekeys', '[249]')),
aimedfiring = GetConvarInt('inventory:aimedfiring', 0) == 1,
giveplayerlist = GetConvarInt('inventory:giveplayerlist', 0) == 1,
weaponanims = GetConvarInt('inventory:weaponanims', 1) == 1,
itemnotify = GetConvarInt('inventory:itemnotify', 1) == 1,
imagepath = GetConvar('inventory:imagepath', 'nui://ox_inventory/web/images'),
dropprops = GetConvarInt('inventory:dropprops', 0) == 1,
dropmodel = joaat(GetConvar('inventory:dropmodel', 'prop_med_bag_01b')),
weaponmismatch = GetConvarInt('inventory:weaponmismatch', 1) == 1,
ignoreweapons = json.decode(GetConvar('inventory:ignoreweapons', '[]')),
suppresspickups = GetConvarInt('inventory:suppresspickups', 1) == 1,
}

local ignoreweapons = table.create(0, (client.ignoreweapons and #client.ignoreweapons or 0) + 3)

for i = 1, #client.ignoreweapons do
local weapon = client.ignoreweapons[i]
ignoreweapons[tonumber(weapon) or joaat(weapon)] = true
end

ignoreweapons[`WEAPON_UNARMED`] = true
ignoreweapons[`WEAPON_HANDCUFFS`] = true
ignoreweapons[`WEAPON_GARBAGEBAG`] = true
ignoreweapons[`OBJECT`] = true
ignoreweapons[`WEAPON_HOSE`] = true

client.ignoreweapons = ignoreweapons
client.ignoreweapons = ignoreweapons
end

function shared.print(...) print(string.strjoin(' ', ...)) end
Expand All @@ -121,95 +121,92 @@ end

-- People like ignoring errors for some reason
local function spamError(err)
shared.ready = false

CreateThread(function()
while true do
Wait(10000)
CreateThread(function()
error(err, 0)
end)
end
end)
shared.ready = false

CreateThread(function()
while true do
Wait(10000)
CreateThread(function()
error(err, 0)
end)
end
end)

addDeferral(err)
error(err, 0)
error(err, 0)
end

CreateThread(function()
if shared.framework == 'ox' then
local file = ('imports/%s.lua'):format(lib.context)
local import = LoadResourceFile('ox_core', file)
local func, err = load(import, ('@@ox_core/%s'):format(file))
if shared.framework == 'ox' then
local file = ('imports/%s.lua'):format(lib.context)
local import = LoadResourceFile('ox_core', file)
local func, err = load(import, ('@@ox_core/%s'):format(file))

if not func or err then
shared.ready = false
return spamError(err)
end
if not func or err then
shared.ready = false
return spamError(err)
end

func()
func()

Ox = Ox or {}
end
Ox = Ox or {}
end
end)

---@param name string
---@return table
function data(name)
if shared.server and shared.ready == nil then return {} end
local file = ('data/%s.lua'):format(name)
local datafile = LoadResourceFile(shared.resource, file)
local path = ('@@%s/%s'):format(shared.resource, file)

if not datafile then
warn(('no datafile found at path %s'):format(path:gsub('@@', '')))
return {}
end
if shared.server and shared.ready == nil then return {} end
local file = ('data/%s.lua'):format(name)
local datafile = LoadResourceFile(shared.resource, file)
local path = ('@@%s/%s'):format(shared.resource, file)

if not datafile then
warn(('no datafile found at path %s'):format(path:gsub('@@', '')))
return {}
end

local func, err = load(datafile, path)
local func, err = load(datafile, path)

if not func or err then
shared.ready = false
---@diagnostic disable-next-line: return-type-mismatch
return spamError(err)
end
if not func or err then
shared.ready = false
---@diagnostic disable-next-line: return-type-mismatch
return spamError(err)
end

return func()
return func()
end

if not lib then
return spamError('ox_inventory requires the ox_lib resource, refer to the documentation.')
return spamError('ox_inventory requires the ox_lib resource, refer to the documentation.')
end

lib.locale()

local success, msg = lib.checkDependency('oxmysql', '2.7.2')

if not success then return spamError(msg) end

success, msg = lib.checkDependency('ox_lib', '3.2.0')

if not success then spamError(msg) end
if not lib.checkDependency('oxmysql', '2.7.3', true)
or not lib.checkDependency('ox_lib', '3.8.1', true)
then
return
end

if not LoadResourceFile(shared.resource, 'web/build/index.html') then
return spamError('UI has not been built, refer to the documentation or download a release build.\n ^3https://overextended.dev/ox_inventory^0')
return spamError(
'UI has not been built, refer to the documentation or download a release build.\n ^3https://overextended.dev/ox_inventory^0')
end

if shared.target then
local ox_target = GetResourceState('ox_target'):find('start')
local qtarget = GetResourceState('qtarget'):find('start')

if not ox_target and not qtarget then
shared.target = false
warn('targeting resource is not loaded - it should start before ox_inventory')
else
shared.target = ox_target and 'ox_target' or 'qtarget'
end
local ox_target = GetResourceState('ox_target'):find('start')
local qtarget = GetResourceState('qtarget'):find('start')

if not ox_target and not qtarget then
shared.target = false
warn('targeting resource is not loaded - it should start before ox_inventory')
else
shared.target = ox_target and 'ox_target' or 'qtarget'
end
end

if lib.context == 'server' then
shared.ready = false
return require 'server'
shared.ready = false
return require 'server'
end

require 'client'
2 changes: 0 additions & 2 deletions modules/inventory/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ else
Inventory.Dumpsters = dumpsters
end

local table = lib.table

---@param search 'slots' | 1 | 'count' | 2
---@param item table | string
---@param metadata? table | string
Expand Down
2 changes: 0 additions & 2 deletions modules/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,6 @@ function Inventory.Load(id, invType, owner)
return returnData, weight
end

local table = lib.table

local function assertMetadata(metadata)
if metadata and type(metadata) ~= 'table' then
metadata = metadata and { type = metadata or nil }
Expand Down
Loading

0 comments on commit 396b5ea

Please sign in to comment.