mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 02:01:33 +00:00
Remove inventory code from the core (#784)
* tweak(config): remove inventory code * tweak(client/functions): remove inventory code * cleanup(server/commands): remove inventory command * cleanup(server/events): remove hasitem callback * cleanup(server/functions): remove inventory code * cleanup(server/player): remove inventory code * feat(server/player): QBCore:Player:SetPlayerData server side Removed QBCore:Server:PlayerLoaded for PR that will be merged before me that adds it * feat(server/player): QBCore:Server:OnGangUpdate * fix(shared/items): remove duplicate snowball * fix(server/events): warn for exploitable event * fix(server/functions): startup error * feat(server/player): some backwards compatibility * fix(server/events): warn for exploitable event * feat(server/player): Player.Functions.AddField * feat(server/exports): SetField and AddField * fix(server/player): inventory state check
This commit is contained in:
+3
-39
@@ -167,10 +167,10 @@ end)
|
||||
|
||||
-- Items
|
||||
|
||||
-- This event is exploitable and should not be used. It has been deprecated, and will be removed soon.
|
||||
RegisterNetEvent('QBCore:Server:UseItem', function(item)
|
||||
local src = source
|
||||
if not item or item.amount <= 0 or not QBCore.Functions.CanUseItem(item.name) then return end
|
||||
QBCore.Functions.UseItem(src, item)
|
||||
print(string.format("%s triggered QBCore:Server:UseItem by ID %s with the following data. This event is deprecated due to exploitation, and will be removed soon. Check qb-inventory for the right use on this event.", GetInvokingResource(), source))
|
||||
QBCore.Debug(item)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Server:RemoveItem', function(itemName, amount, slot)
|
||||
@@ -206,42 +206,6 @@ RegisterNetEvent('QBCore:CallCommand', function(command, args)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Has Item Callback (can also use client function - QBCore.Functions.HasItem(item))
|
||||
|
||||
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, amount)
|
||||
local retval = false
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if not Player then return cb(false) end
|
||||
local isTable = type(items) == 'table'
|
||||
local isArray = isTable and table.type(items) == 'array' or false
|
||||
local totalItems = #items
|
||||
local count = 0
|
||||
local kvIndex = 2
|
||||
if isTable and not isArray then
|
||||
totalItems = 0
|
||||
for _ in pairs(items) do totalItems += 1 end
|
||||
kvIndex = 1
|
||||
end
|
||||
if isTable then
|
||||
for k, v in pairs(items) do
|
||||
local itemKV = {k, v}
|
||||
local item = Player.Functions.GetItemByName(itemKV[kvIndex])
|
||||
if item and ((amount and item.amount >= amount) or (not amount and not isArray and item.amount >= v) or (not amount and isArray)) then
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
if count == totalItems then
|
||||
retval = true
|
||||
end
|
||||
else -- Single item as string
|
||||
local item = Player.Functions.GetItemByName(items)
|
||||
if item and not amount or (item and amount and item.amount >= amount) then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
cb(retval)
|
||||
end)
|
||||
|
||||
-- Use this for player vehicle spawning
|
||||
-- Vehicle server-side spawning callback (netId)
|
||||
-- use the netid on the client with the NetworkGetEntityFromNetworkId native
|
||||
|
||||
Reference in New Issue
Block a user