Skip to content

Commit

Permalink
MODIFICATIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
Clefas committed Jun 16, 2023
1 parent dcbd238 commit 785a247
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 14 deletions.
4 changes: 4 additions & 0 deletions client/common.lua
Expand Up @@ -9,3 +9,7 @@ end)
if GetResourceState('ox_inventory') ~= 'missing' then
Config.OxInventory = true
end

if GetResourceState('qs-inventory') ~= 'missing' then
Config.QSInventory = true
end
3 changes: 3 additions & 0 deletions client/functions.lua
Expand Up @@ -38,6 +38,9 @@ function ESX.IsPlayerLoaded()
end

function ESX.GetPlayerData()
if Config.QSInventory then
ESX.PlayerData.inventory = exports['qs-inventory']:getUserInventory()
end
return ESX.PlayerData
end

Expand Down
12 changes: 6 additions & 6 deletions client/main.lua
Expand Up @@ -167,7 +167,7 @@ end)
AddEventHandler('esx:restoreLoadout', function()
ESX.SetPlayerData('ped', PlayerPedId())

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
local ammoTypes = {}
RemoveAllPedWeapons(ESX.PlayerData.ped, true)

Expand Down Expand Up @@ -223,7 +223,7 @@ AddEventHandler('esx:setAccountMoney', function(account)
end
end)

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
RegisterNetEvent('esx:addInventoryItem')
AddEventHandler('esx:addInventoryItem', function(item, count, showNotification)
for k,v in ipairs(ESX.PlayerData.inventory) do
Expand Down Expand Up @@ -354,7 +354,7 @@ AddEventHandler('esx:spawnVehicle', function(vehicle)
end)
end)

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
RegisterNetEvent('esx:createPickup')
AddEventHandler('esx:createPickup', function(pickupId, label, coords, type, name, components, tintIndex)
local function setObjectProperties(object)
Expand Down Expand Up @@ -405,7 +405,7 @@ AddEventHandler('esx:registerSuggestions', function(registeredCommands)
end
end)

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
RegisterNetEvent('esx:removePickup')
AddEventHandler('esx:removePickup', function(pickupId)
if pickups[pickupId] and pickups[pickupId].obj then
Expand Down Expand Up @@ -442,7 +442,7 @@ if Config.EnableHud then
end

function StartServerSyncLoops()
if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
-- keep track of ammo

CreateThread(function()
Expand Down Expand Up @@ -509,7 +509,7 @@ if not Config.EnableWantedLevel then
SetMaxWantedLevel(0)
end

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
CreateThread(function()
while true do
local Sleep = 1500
Expand Down
4 changes: 2 additions & 2 deletions config.lua
Expand Up @@ -23,11 +23,11 @@ Config.EnableHud = true -- enable the default hud? Display current j
Config.MaxWeight = 24 -- the max inventory weight without backpack
Config.PaycheckInterval = 7 * 60000 -- how often to recieve pay checks in milliseconds
Config.EnableDebug = false -- Use Debug options?
Config.EnableDefaultInventory = true -- Display the default Inventory ( F2 )
Config.EnableDefaultInventory = false -- Display the default Inventory ( F2 )
Config.EnableWantedLevel = false -- Use Normal GTA wanted Level?
Config.EnablePVP = true -- Allow Player to player combat

Config.Multichar = true -- Enable support for esx_multicharacter
Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing" -- Enable support for esx_multicharacter
Config.Identity = true -- Select a characters identity data before they have loaded in (this happens by default with multichar)
Config.DistanceGive = 4.0 -- Max distance when giving items, weapons etc.
Config.DisableHealthRegen = false -- Player will no longer regenerate health
Expand Down
200 changes: 200 additions & 0 deletions server/classes/overrides/qsinventory.lua
@@ -0,0 +1,200 @@
Core.PlayerFunctionOverrides.QSInventory = {
getInventory = function(self)
return function(minimal)
local inventory = exports['qs-inventory']:GetInventory(self.source)
if not inventory then return {} end
for k,v in pairs(inventory) do
v.count = v.amount
end
return inventory
end
end,

getLoadout = function(self)
return function()
return {}
end
end,

getInventoryItem = function(self)
return function(name,metadata)
local item = exports['qs-inventory']:GetItemByName(self.source, name)
if not item then
return {
count = 0,
}
end
item.count = item.amount
return item
end
end,

getAccount = function(self)
return function(account)
for i=1, #self.accounts do
if self.accounts[i].name == account then
local accounts = exports['qs-inventory']:GetAccounts()
if accounts[account] then
self.accounts[i].money = exports['qs-inventory']:GetItemTotalAmount(self.source, account)
end
return self.accounts[i]
end
end
end
end,

setAccountMoney = function(self)
return function(accountName,money, reason)
reason = reason or 'unknown'
if money >= 0 then
local account = self.getAccount(accountName)

if account then
money = account.round and ESX.Math.Round(money) or money
self.accounts[account.index].money = money

self.triggerEvent('esx:setAccountMoney', account)
TriggerEvent('esx:setAccountMoney', self.source, accountName, money, reason)
local accounts = exports['qs-inventory']:GetAccounts()
if accounts[accountName] and reason ~= 'dropped' then
exports['qs-inventory']:SetInventoryItems(self.source, accountName, money)
end
end
end
end
end,

addAccountMoney = function(self)
return function(accountName,money, reason)
reason = reason or 'unknown'
if money > 0 then
local account = self.getAccount(accountName)

if account then
money = account.round and ESX.Math.Round(money) or money
self.accounts[account.index].money += money
self.triggerEvent('esx:setAccountMoney', account)
TriggerEvent('esx:addAccountMoney', self.source, accountName, money, reason)
local accounts = exports['qs-inventory']:GetAccounts()
if accounts[accountName] then
exports['qs-inventory']:AddItem(self.source, accountName, money)
end
end
end
end
end,

removeAccountMoney = function(self)
return function(accountName,money, reason)
reason = reason or 'unknown'
if money > 0 then
local account = self.getAccount(accountName)

if account then
money = account.round and ESX.Math.Round(money) or money
self.accounts[account.index].money -= money
self.triggerEvent('esx:setAccountMoney', account)
TriggerEvent('esx:removeAccountMoney', self.source, accountName, money, reason)
local accounts = exports['qs-inventory']:GetAccounts()
if accounts[accountName] then
exports['qs-inventory']:RemoveItem(self.source, accountName, money)
end
end
end
end
end,

addInventoryItem = function(self)
return function(name,count,metadata,slot)
return exports['qs-inventory']:AddItem(self.source, name, count or 1, slot, metadata)
end
end,

removeInventoryItem = function(self)
return function(name,count,metadata,slot)
return exports['qs-inventory']:RemoveItem(self.source, name, count or 1, slot, metadata)
end
end,

setInventoryItem = function(self)
return function(name,count,metadata)
return exports['qs-inventory']:SetInventoryItem(self.source, name, count, metadata)
end
end,

canCarryItem = function(self)
return function(name,count,metadata)
return exports['qs-inventory']:CanCarryItem(self.source, name, count)
end
end,

canSwapItem = function(self)
return function(firstItem, firstItemCount, testItem, testItemCount)
return true
end
end,

setMaxWeight = function(self)
return function() end
end,

addWeapon = function(self)
return function(weaponName, ammo)
return exports['qs-inventory']:GiveWeaponToPlayer(self.source, weaponName, ammo)
end
end,

addWeaponComponent = function(self)
return function() end
end,

addWeaponAmmo = function(self)
return function() end
end,

updateWeaponAmmo = function(self)
return function() end
end,

setWeaponTint = function(self)
return function() end
end,

getWeaponTint = function(self)
return function() end
end,

removeWeapon = function(self)
return function() end
end,

removeWeaponComponent = function(self)
return function() end
end,

removeWeaponAmmo = function(self)
return function() end
end,

hasWeaponComponent = function(self)
return function()
return false
end
end,

hasWeapon = function(self)
return function()
return false
end
end,

hasItem = function(self)
return function(name,metadata)
return exports['qs-inventory']:GetItemByName(self.source, name)
end
end,

getWeapon = function(self)
return function() end
end
}
4 changes: 2 additions & 2 deletions server/commands.lua
Expand Up @@ -62,7 +62,7 @@ end, true, {help = _U('command_giveaccountmoney'), validate = true, arguments =
{name = 'amount', help = _U('command_giveaccountmoney_amount'), type = 'number'}
}})

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
ESX.RegisterCommand('giveitem', 'admin', function(xPlayer, args, showError)
args.playerId.addInventoryItem(args.item, args.count)
end, true, {help = _U('command_giveitem'), validate = true, arguments = {
Expand Down Expand Up @@ -118,7 +118,7 @@ ESX.RegisterCommand("refreshjobs", 'admin', function(xPlayer, args, showError)
ESX.RefreshJobs()
end, true, {help = _U('command_clearall')})

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
ESX.RegisterCommand('clearinventory', 'admin', function(xPlayer, args, showError)
for k,v in ipairs(args.playerId.inventory) do
if v.count > 0 then
Expand Down
8 changes: 8 additions & 0 deletions server/common.lua
Expand Up @@ -27,6 +27,11 @@ if GetResourceState('ox_inventory') ~= 'missing' then
SetConvarReplicated('inventory:weight', Config.MaxWeight * 1000)
end

if GetResourceState('qs-inventory') ~= 'missing' then
Config.QSInventory = true
Config.PlayerFunctionOverride = 'QSInventory'
end

local function StartDBSync()
CreateThread(function()
while true do
Expand All @@ -37,6 +42,9 @@ local function StartDBSync()
end

MySQL.ready(function()
if Config.QSInventory then
ESX.Items = exports['qs-inventory']:GetItemList()
end
if not Config.OxInventory then
local items = MySQL.query.await('SELECT * FROM items')
for k, v in ipairs(items) do
Expand Down
22 changes: 21 additions & 1 deletion server/functions.lua
Expand Up @@ -190,6 +190,12 @@ function Core.SavePlayer(xPlayer, cb)
end)
end

AddEventHandler('onResourceStop', function(resourceName)
if (resourceName == "qs-inventory") then
Core.SavePlayers()
end
end)

function Core.SavePlayers(cb)
local xPlayers = ESX.GetExtendedPlayers()
local count = #xPlayers
Expand Down Expand Up @@ -302,12 +308,23 @@ end

function ESX.RegisterUsableItem(item, cb)
Core.UsableItemsCallbacks[item] = cb
if Config.QSInventory then
exports['qs-inventory']:CreateUsableItem(item, cb)
end
end

exports('GetUsableItems', function()
return Core.UsableItemsCallbacks
end)

function ESX.UseItem(source, item, ...)
if ESX.Items[item] then
local itemCallback = Core.UsableItemsCallbacks[item]

if Config.QSInventory then
return exports['qs-inventory']:UseItem(item, source, ...)
end

if itemCallback then
local success, result = pcall(itemCallback, source, item, ...)

Expand All @@ -334,6 +351,9 @@ function ESX.SetPlayerFunctionOverride(index)
end

function ESX.GetItemLabel(item)
if Config.QSInventory then
return exports['qs-inventory']:GetItemLabel(item)
end
if Config.OxInventory then
item = exports.ox_inventory:Items(item)
if item then
Expand All @@ -360,7 +380,7 @@ function ESX.GetUsableItems()
return Usables
end

if not Config.OxInventory then
if not Config.OxInventory and not Config.QSInventory then
function ESX.CreatePickup(type, name, count, label, playerId, components, tintIndex)
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
local xPlayer = ESX.Players[playerId]
Expand Down

0 comments on commit 785a247

Please sign in to comment.