[Release] esx-kr-bag-inventory - A bag inventory script synced with the server


#23

Tried your sql now, hope it works for all.


#24

yes now works


#25

Reinstall the sql


#26

Well thanks haha, got damn, i exported my table as a sql. For some reason it never works haha. Well it works on my server, and my server only.


#27

Yea nah your missing something here man, Its not working either on this end, for some reason… I use the bag and nothing then I check my inventory again and it removed the bag, I drop the bag walk up to it and it picks it up… something is missing here.


#28

If i put in 1 fixkit and after this another fixkit i have two times:
fixkit x 1
fixkit x 1
in the bag. if i take out one of them both are deleted from the DB.

if you want here is the fix:

RegisterServerEvent('esx-kr-bag:PutItem')
AddEventHandler('esx-kr-bag:PutItem', function(id, item, label, count, type)
    local src = source
    local xPlayer = ESX.GetPlayerFromId(src)
	local update
	local insert

    if type == 'weapon' then
        xPlayer.removeWeapon(item, count)
		MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item']  = item, ['@label']  = label, ['@count'] = count})
    elseif type == 'item' then
        xPlayer.removeInventoryItem(item, count)
		MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id ',{["@id"] = id}, function(result)
			if result[1] ~= nil then
				for i=1, #result, 1 do
					if result[i].item == item then
						count = count + result[i].count
						update = 1
					elseif result[i].item ~= item then
						insert = 1
					end
				end
				if update == 1 then
					MySQL.Async.execute('UPDATE owned_bag_inventory SET count = @count WHERE item = @item', {['@item'] = item, ['@count'] = count})
				elseif insert == 1 then
					MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item']  = item, ['@label']  = label, ['@count'] = count})
				end
			else
				MySQL.Async.execute('INSERT INTO owned_bag_inventory (id, label, item, count) VALUES (@id, @label, @item, @count)', {['@id'] = id,['@item']  = item, ['@label']  = label, ['@count'] = count})
			end
		end)
    end
end)

#29

Sounds weird, well it works for all the others. Are you sure you’ve inserted the new sql? Any errors?


#30

Thanks for making my life easier


#31

is this normal? https://i.imgur.com/PayFX5v.png


#32

do you edited something ?


#33

nothing, just installed this ressource witheout modification x)


#34

Give me your discord please


#35

I have the data in mysql showing but I can not access any menus to do with the bag at all, I use the bag and nothing changes


#36

the fix for it is in line 125:

    end

but it should looks like:

    end
end)

#37

Heady forgot a end) fixed now anyway


#38

Client or Server In Client This is my line 125-134

RegisterNetEvent('esx-kr-bag:ReSync')
AddEventHandler('esx-kr-bag:ReSync', function(id)
    Bags = {}
    ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags)
        for i=1, #bags, 1 do
            table.insert(Bags, {id = {coords = {x = bags[i].x, y = bags[i].y, z = bags[i].z}, id = bags[i].id}})
        end

    end)
end)

MY SERVER


RegisterServerEvent('esx-kr-bag:DropBag')
AddEventHandler('esx-kr-bag:DropBag', function(id, x, y, z)
    local src = source
    local identifier = ESX.GetPlayerFromId(src).identifier

Edited Ill Reinstall and see if new version works


#39

But have you used the item?


#40

it already have it, https://i.imgur.com/ApOxajP.png
and i got another error when i’m loggin to my server https://i.imgur.com/rS2XsMW.png


#41

Try reinstall, it should work. Seems like it can’t find my cb which it should.


#42

you should put the code from AddEventHandler(‘playerspawned’)

inside of AddEventHandler(‘esx:playerLoaded’)

Because if you get revived (e.g. with the admin command revive) you can pick up the bag but the model is still there.