#Inventory full?
1 messages · Page 1 of 1 (latest)
i mean, ive an idea. Ive this code, and i want to create a if cycle for ensuring the inventory is not full, i gived a lot of crowbars but when my inventory got full its still saying sucefully got a crowbars because i dont have a if cycle ... sry for my english lol
Write a check for to see if the pockets are full
yeah, so qbcore doesnt have this function what is does that, right?
It should by default
ah okay thanks ❤️
That code isnt good. You should remove the notify from there.
Notify on the server, only if the addition of the item was successful
Essentially, what you have, will always give a success notification, if it works or not
yes, thats why i want to create a IF cycle, it probably will work, not?
this? :
RegisterServerEvent('qb-admin:giveWeapon', function(weapon)
local src = source
if QBCore.Functions.HasPermission(src, 'admin') or IsPlayerAceAllowed(src, 'command') then
exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon')
else
BanPlayer(src)
end
end)
yeah, bare with
wdym
RegisterServerEvent('qb-admin:giveWeapon', function(weapon)
local src = source
if not weapon or weapon == '' then
return QBCore.Functions.Notify(src, 'Weapon ' .. weapon .. ' does not exist', 'error')
end
if QBCore.Functions.HasPermission(src, 'admin') or IsPlayerAceAllowed(src, 'command') then return BanPlayer(src) end
if not exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon') then
return QBCore.Functions.Notify(src, 'You do not have enough space in your inventory', 'error')
end
QBCore.Functions.Notify(src, 'You have received a weapon: ' .. weapon, 'success')
end)
replace with that, remove the notify from client and try it please
wait
thats wrong
only the notify?
RegisterServerEvent('qb-admin:giveWeapon', function(weapon)
local src = source
if not weapon or weapon == '' then
return QBCore.Functions.Notify(src, 'Weapon ' .. weapon .. ' does not exist', 'error')
end
if not QBCore.Functions.HasPermission(src, 'admin') and not IsPlayerAceAllowed(src, 'command') then return BanPlayer(src) end
if not exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon') then
return QBCore.Functions.Notify(src, 'You do not have enough space in your inventory', 'error')
end
QBCore.Functions.Notify(src, 'You have received a weapon: ' .. weapon, 'success')
end)
The permissions part was wrong (was flipped)
Thats it
😄
i just translated all the adminmenu things and overwrite some thing because a lot of thing not working lol
rather than the "name"
ah yeah
thanks the help ❤️
RegisterServerEvent('qb-admin:giveWeapon', function(weaponData)
local src = source
if type(weaponData) ~= 'table' then
return QBCore.Functions.Notify(src, 'Invalid weapon data', 'error')
end
local weapon = weaponData.name
if not weapon or weapon == '' then
return QBCore.Functions.Notify(src, 'Weapon ' .. weapon .. ' does not exist', 'error')
end
local weaponLabel = weaponData.label or weapon
if not QBCore.Functions.HasPermission(src, 'admin') and not IsPlayerAceAllowed(src, 'command') then return BanPlayer(src) end
if not exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon') then
return QBCore.Functions.Notify(src, 'You do not have enough space in your inventory', 'error')
end
QBCore.Functions.Notify(src, 'You have received a weapon: ' .. weaponLabel, 'success')
end)
😮
yeah!
i just translate it and done ❤️
btw i need to use this if i want to know if the inventory full or not? " if not exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon') then"
So, that function, returns a true or false value
you can break it down
local successfully_added_item = exports['qb-inventory']:AddItem(src, weapon, 1, false, false, 'qb-admin:giveWeapon')
if not successfully_added_item then
return QBCore.Functions.Notify(src, 'You do not have enough space in your inventory', 'error')
end
Does that make more sense?