Amount bug when giving items

888 Views Asked by At

I need your help for a minute.

We have the problem that players can assign more things in the inventory than normally possible (example: I don't have "25" sandwiches but if I enter "025" as value I can give 25 to another player).

Does anyone know how I can fix this?

Code-snippet is here:

(server-side):

RegisterNetEvent('grv_inventory:giveItem')
AddEventHandler('grv_inventory:giveItem', function(name, count, target)
    local _source = source
    local xPlayer = ESX.GetPlayerFromId(_source)
    local xTarget = ESX.GetPlayerFromId(target)

    if item == 'bandage' or 'bread' or 'bulletproof' or 'clip' or 'contract' or 'cuffs' or 'cuff_keys' or 'drill' or 'fixkit' or 'jewels' or 'medikit' or 'meth' or 'phone' or 'water' or 'kroeten' or 'kroeten_pooch' or 'ephi' or 'aramidfasern' or 'aramid' or 'kevlar' or 'holz' or 'schraube' or 'huelse' or 'radio' or 'bauxit' or 'aluminiumoxid' or 'aluminium' or 'eisenerz' or 'magazin' or 'trauben' or 'traubenverarbeitet' or 'lspdstandard' or 'orangen' or 'orangenverarbeitet' or 'lsfstandard' or 'weedsamen' or 'weed' or 'joint' or 'kocher' or 'tfcoupon' or 'ffcoupon' or 'teddy' or 'rose' or 'srose' or 'kaffee' or 'cola' or 'steine' or 'fib1' or 'fib2' or 'fib3' or 'lspdweste1' or 'lspdweste2' or 'lspdweste3' then
    xPlayer.removeInventoryItem(name, count)
    xTarget.addInventoryItem(name, count)
    TriggerClientEvent('esx:showNotification', target, "Du hast " ..count.. "x " ..name.. "  bekommen ")

    TriggerClientEvent('grv_inventory:setMax', source, count)
    end
end)

(client-side):

RegisterNUICallback('give', function(data, cb)
    toggleField(false)
    SetNuiFocus(false, false)
    local playerPed = GetPlayerPed(-1)
    loadAnimDict('anim@mp_snowball')
    local player, dist = ESX.Game.GetClosestPlayer()

    if player == -1 or dist > 3.0 then
        ESX.ShowNotification('Es ist keine Person in der Nähe')
    else
        TaskPlayAnim(PlayerPedId(), 'anim@mp_snowball', 'pickup_snowball', 8.0, -1, -1, 0, 1, 0, 0, 0)
        Citizen.Wait(1300)
        ClearPedTasksImmediately(playerPed)
        TriggerServerEvent('grv_inventory:giveItem', data.item, data.amount, GetPlayerServerId(player))
        ESX.ShowNotification(("Du hast jemanden %sx %s zugesteckt"):format(data.amount, data.label))
    end
    
    cb('ok')
end)

Thanks a lot!

1

There are 1 best solutions below

0
On BEST ANSWER

You have a couple of issues:

  1. The comparison if item == 'bandage' or 'bread' ... then is not going to do what you expect it to do, as bread will be evaluated as true (as it's not compared with item value), so the entire expression will be evaluated as true regardless of what the actual value or item is. You need to rewrite it as it item == 'bandage' or item = 'bread' ... and so on
  2. I don't see any comparison with available items, so either it's happening somewhere else (and is not applied because of the first issue) or is not done.