mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:08:57 +00:00
Merge branch 'main' into ClientCallbacks
This commit is contained in:
+30
-50
@@ -1,17 +1,17 @@
|
||||
-- Event Handler
|
||||
|
||||
AddEventHandler('chatMessage', function(source, _, message)
|
||||
AddEventHandler('chatMessage', function(_, _, message)
|
||||
if string.sub(message, 1, 1) == '/' then
|
||||
CancelEvent()
|
||||
return
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('playerDropped', function()
|
||||
AddEventHandler('playerDropped', function(reason)
|
||||
local src = source
|
||||
if not QBCore.Players[src] then return end
|
||||
local Player = QBCore.Players[src]
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..')
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**' .. GetPlayerName(src) .. '** (' .. Player.PlayerData.license .. ') left..' ..'\n **Reason:** ' .. reason)
|
||||
Player.Functions.Save()
|
||||
QBCore.Player_Buckets[Player.PlayerData.license] = nil
|
||||
QBCore.Players[src] = nil
|
||||
@@ -144,14 +144,13 @@ end)
|
||||
RegisterNetEvent('QBCore:Server:SetMetaData', function(meta, data)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if not Player then return end
|
||||
if meta == 'hunger' or meta == 'thirst' then
|
||||
if data > 100 then
|
||||
data = 100
|
||||
end
|
||||
end
|
||||
if Player then
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
end
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
|
||||
end)
|
||||
|
||||
@@ -214,54 +213,35 @@ end)
|
||||
|
||||
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, amount)
|
||||
local retval = false
|
||||
if items == nil then return cb(true) end
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if not Player then return cb(false) end
|
||||
if type(items) == 'table' then
|
||||
local count = 0
|
||||
local finalcount = 0
|
||||
for k, v in pairs(items) do
|
||||
if type(k) == 'string' then
|
||||
finalcount = 0
|
||||
for i, _ in pairs(items) do finalcount += 1 end
|
||||
local item = Player.Functions.GetItemByName(k)
|
||||
if item then
|
||||
if item.amount >= v then
|
||||
count += 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
finalcount = #items
|
||||
local item = Player.Functions.GetItemByName(v)
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
count += 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
else
|
||||
count += 1
|
||||
if count == finalcount then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
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
|
||||
else
|
||||
local item = Player.Functions.GetItemByName(items)
|
||||
if not item then return cb(false) end
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
retval = true
|
||||
end
|
||||
else
|
||||
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 (amount and item.amount >= amount) then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
cb(retval)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user