#Inventory full?

1 messages · Page 1 of 1 (latest)

pseudo token
#

Hello, i want to ask, theres any method to get true or false if the inventory full or have space? like slots and weights 😄

#

if the target inventory full then i got false, but if its not full i got true.

novel dock
#

It would notify when the inventory is full

#

By default

pseudo token
# novel dock It would notify when the inventory is full

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

novel dock
#

Write a check for to see if the pockets are full

pseudo token
#

yeah, so qbcore doesnt have this function what is does that, right?

novel dock
#

It should by default

pseudo token
#

ah okay thanks ❤️

charred garnet
#

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

pseudo token
charred garnet
#

Send me the qb-adminGiveWeapon event in here please

#

aka, the server side code

pseudo token
#

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)

charred garnet
#

yeah, bare with

pseudo token
#

wdym

charred garnet
#
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

pseudo token
#

only the notify?

charred garnet
#
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)

pseudo token
#

remove the notify like that i think yeah? or i neet to remove the trigger too?

#

ah

charred garnet
#

Thats it

pseudo token
#

nvm

#

lets goo

charred garnet
#

😄

pseudo token
#

thanks mate ❤️

charred garnet
#

You're welcome

#

You could make it even better, and use the item label

pseudo token
#

i just translated all the adminmenu things and overwrite some thing because a lot of thing not working lol

charred garnet
#

rather than the "name"

pseudo token
#

thanks the help ❤️

charred garnet
#
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)
pseudo token
#

😮

charred garnet
#

on the triggerserverevent, change v.name to v (remove .name)

#

That work for you?

pseudo token
#

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"

charred garnet
#

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?