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


#127

this is for the English locale for what you put together

Locales ['en'] = {
  ['already_bag'] = 'You already own a bag',
  ['bag_maxitem'] = 'You can only have ~r%~ different stuff ~s~ in the bag',
  ['bag_access'] = 'Press ~b~[F5]~s~ access the bag',
  ['bag_drop'] = 'Take off the bag',
  ['bag_pickup'] = 'Press ~g~[E]~w~ pick up the bag',
  ['bag_search'] = 'Press ~o~[N]~w~ search your bag',
  ['put_object'] = 'Place in the bag',
  ['take_object'] = 'Take out of the bag',
  ['too_much'] = 'More than ~r~%s~s~ do not fit in the bag',
  ['pick_toomuch'] = 'You do not have that much space in your bag',
}```

#128

Great script! Works like a flower in the shower so to say!


#129

French Translate !

Locales [‘fr’] = {
[‘already_bag’] = ‘Tu as déjà un sac’,
[‘bag_maxitem’] = ‘Vous ne pouvez avoir MAX 2 ~s~différentes choses~s~ dans le sac’,
[‘bag_access’] = ‘Accédez au sac avec ~b~[F5]~s~’,
[‘bag_drop’] = ‘Enlevez le sac’,
[‘bag_pickup’] = ‘~g~[E]~w~ ramasser le sac’,
[‘bag_search’] = ‘~o~[N]~w~ chercher dans le sac’,
[‘put_object’] = ‘Mettre un objet’,
[‘take_object’] = ‘Prendre un objet’,
[‘too_much’] = ‘Plus de ~r~%s~s~ ne rentrera pas dans le sac’,
[‘pick_toomuch’] = ‘Vous n’avez pas beaucoup dans votre sac’,
}


#130

My friend - with this you can duplicate the item like saying i have 1 in my inventory i can go up to 75 without having it it just puts it in the bag


#131

oh yeah… thank you :slight_smile:

here is the fix in the server/main.lua
(replace the ServerEvent-esx-kr-bag:PutItem)

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 identifier = ESX.GetPlayerFromId(src).identifier
	local update
	local count2 = count
    local insert
    local xItem = xPlayer.getInventoryItem(item)
	
	
    MySQL.Async.fetchAll('SELECT * FROM owned_bags WHERE identifier = @identifier ',{["@identifier"] = identifier}, function(bag)
		if xItem.count >= count then
			if bag[1].itemcount < Config.MaxItemCount then
				if count2 <= Config.MaxPerItem then
					if type == 'weapon' then
						xPlayer.removeWeapon(item, count)
						MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
						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
						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
									if count <= Config.MaxPerItem then
										MySQL.Async.execute('UPDATE owned_bag_inventory SET count = @count WHERE item = @item', {['@item'] = item, ['@count'] = count})
										xPlayer.removeInventoryItem(item, count2)
									else
										TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
										return
									end
								elseif insert == 1 then
									if count2 <= Config.MaxPerItem then
										MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
										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})
										xPlayer.removeInventoryItem(item, count2)
									else
										TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
										return
									end
								end
							else
								MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1})
								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})
								xPlayer.removeInventoryItem(item, count2)
							end
						end)
					end
				else
					TriggerClientEvent('esx:showNotification', src, _U('too_much', Config.MaxPerItem))
				end
			else
				TriggerClientEvent('esx:showNotification', src, _U('bag_maxitem',Config.MaxItemCount))
			end
		else
			TriggerClientEvent('esx:showNotification', src, _U('pick_toomuch'))
		end
    end)
end)

//EDIT:
optimized code (removed the canBeStored-variable)
a second doublecation-fix


#132

hands down i love how everyone is working together to make this work in everyday
we can


#133

Nice job ! But the key N for search in the bag don’t working (sorry if my english is bad)


#134

there is still a problem for an roleplay.
imagine that between an object and another there is different “weight”

Being able to carry 25 of cocaine is different than carrying 7 of stones

I do not know if I explain, in my case it is;
The maximum that can be carried out of stone is 7
And maximum of cocaine let’s say 25
Now how do I make it possible to make the same amount in the backpack?


#135

its possible to edit the code… but the problem is that you have to setup every item in a config.file.

and i dont want to do it… because my server has nearly 2k items ^^

its possible to add a column in the database.items but there you have to setup the weight for each item. its a lot of work


#136

Like Heady said.


#137

When I activate this script, the F6 menu of the font job no longer works, it opens and closes immediately


#138

First thanks a lot to KRILLE and Heady20006

Here a feedback for Heady Version with server main.lua edit like it show… 6-7 post before.

Everything work… stuff save to database… put in… take out… drop the bag…
i had to change bag 45 to 41 cause i use eup and it change my stuff… doesnt matter.

Here a little error in console when a new player come in… or when a bag is drop and the player relog in.

Error running call reference function for resource esx-kr-bag-inventory: citizen:/scripting/lua/scheduler.lua:403: server/main.lua:27: attempt to index a nil value
stack traceback:
        server/main.lua:27: in upvalue 'ref'
        citizen:/scripting/lua/scheduler.lua:389: in function <citizen:/scripting/lua/scheduler.lua:388>
        [C]: in function 'xpcall'
        citizen:/scripting/lua/scheduler.lua:388: in function <citizen:/scripting/lua/scheduler.lua:387>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:403: in function <citizen:/scripting/lua/scheduler.lua:372>
Error running system event handling function for resource es_extended: citizen:/scripting/lua/scheduler.lua:41: Failed to execute thread: citizen:/scripting/lua/MessagePack.lua:830: missing bytes
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/MessagePack.lua:830: in method 'underflow'
        citizen:/scripting/lua/MessagePack.lua:465: in field 'any'
        citizen:/scripting/lua/MessagePack.lua:860: in field 'unpack'
        citizen:/scripting/lua/scheduler.lua:626: in field '?'
        server/functions.lua:33: in field 'TriggerServerCallback'
        server/common.lua:63: in upvalue 'handler'
        citizen:/scripting/lua/scheduler.lua:219: in function <citizen:/scripting/lua/scheduler.lua:218>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:41: in field 'CreateThreadNow'
        citizen:/scripting/lua/scheduler.lua:218: in function <citizen:/scripting/lua/scheduler.lua:182>

Also… when drop a bag and take it back… the bag on floor diasapear (fine)
When i drop a bag and logout and log back in, the bag is there and i can take it… Stuff is still inside (fine)
But this time a bag copy stay on floor… The copy cant be taken (fine) But still confusing for player.

Something Else:
[N] Search the bag doesnt work

Something Else:
Lets say that i have a bag on me (use). And i found a bag drop from someone… Nothing appear ( E or N )
I have to drop mine to Take the one i found… Would be fun that i can search inside at least!

Something Else: i tried to deposit weapon… First i tried a ShotGun with 5 ammo DIDNT WORK
then i tried a pistol with 5 ammo DIDNT WORK
also try with no ammo. DIDNT WORK

When trying to put weapon in the bag:

Error running call reference function for resource esx-kr-bag-inventory: citizen:/scripting/lua/scheduler.lua:403: server/main.lua:127: attempt to index a nil value (upvalue 'xItem')
stack traceback:
        server/main.lua:127: in upvalue 'ref'
        citizen:/scripting/lua/scheduler.lua:389: in function <citizen:/scripting/lua/scheduler.lua:388>
        [C]: in function 'xpcall'
        citizen:/scripting/lua/scheduler.lua:388: in function <citizen:/scripting/lua/scheduler.lua:387>
stack traceback:
        [C]: in function 'error'
        citizen:/scripting/lua/scheduler.lua:403: in function <citizen:/scripting/lua/scheduler.lua:372>
[ERROR] [MySQL] Check the error above, an error happens when executing the callback from the query : "SELECT * FROM owned_bags WHERE identifier = @identifier  {@identifier=steam:11000010a1ea5c0}"

Again thx guys… this is so cool!
5 start release!


#139

great feedback my friend :slight_smile: thx.

here is a new version with the following features:

  • you can store weapons
  • you can restore the empty bag to your inventory

*actually no time to do the other ideas in your feedback :wink:
*have to sleep now ^^

esx-kr-bag-inventory.rar (6.2 KB)


#140

What is the "font job?


#141

Just a heads up players can duplicate items if the bag is on the ground and they both are searching it and take item at same time. I removed the option to search the bag while on the ground until I can mess with it more.


#142

The job is esx_policejob, the F6 menu don’t work before activate your script


#143

dose it not work in cars or both


#144

F6 menu don’t work


#145

its F5 dude , read carefully


#146

btw thank you for this script , for 6 of my server , its run very smooth and nice job man , but when i set the limit to 100 , like my water bottle limi is 100 , we can have 1000+ , any solution ?