├── esx-kr-bag-inventory ├── config.lua ├── __resource.lua ├── esx-kr-bag-inventory.sql ├── server │ └── main.lua └── client │ └── main.lua └── README.md /esx-kr-bag-inventory/config.lua: -------------------------------------------------------------------------------- 1 | Config = {} 2 | 3 | Config.MaxItemCount = 50 4 | Config.MaxDifferentItems = 5 5 | -------------------------------------------------------------------------------- /esx-kr-bag-inventory/__resource.lua: -------------------------------------------------------------------------------- 1 | resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' 2 | 3 | 4 | client_scripts { 5 | 'client/main.lua', 6 | 'config.lua' 7 | } 8 | 9 | server_scripts { 10 | 'server/main.lua', 11 | 'config.lua', 12 | '@mysql-async/lib/MySQL.lua' 13 | } 14 | -------------------------------------------------------------------------------- /esx-kr-bag-inventory/esx-kr-bag-inventory.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `owned_bags`( 2 | `identifier` VARCHAR(50) NULL DEFAULT NULL, 3 | `id` INT(11) NULL DEFAULT NULL, 4 | `x` DOUBLE NULL DEFAULT NULL, 5 | `y` DOUBLE NULL DEFAULT NULL, 6 | `z` DOUBLE NULL DEFAULT NULL, 7 | `itemcount` int(11) NOT NULL DEFAULT '0' 8 | ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB ; 9 | 10 | CREATE TABLE IF NOT EXISTS `owned_bag_inventory` ( 11 | `id` int(11) DEFAULT NULL, 12 | `item` varchar(50) DEFAULT NULL, 13 | `label` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, 14 | `count` int(11) DEFAULT NULL 15 | ); 16 | 17 | INSERT INTO `items` (`name`, `label`, `limit`) VALUES 18 | ('bag', 'Bag', 1) 19 | ; 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | > **ESX-KR-BAG-INVENTORY** 3 | 4 | **Features** 5 | 6 | _- Synced with all players_ 7 | 8 | _- You have the ability to put weapons and items in your bag_ 9 | 10 | _- If you drop your bag with the items inside all items will drop with the bag_ 11 | 12 | _- All bags and it's items are saved in a database_ 13 | 14 | _- All dropped bags respawn after restarting the server_ 15 | 16 | **Usage** 17 | 18 | _- The script was made to promote roleplaying_ 19 | 20 | _- The default key to open the bag is F5_ 21 | 22 | 23 | **Installation** 24 | 25 | 1. Download the files and insert them into your resource folder. 26 | 2. Start the esx-kr-bag-inventory in your server.cfg 27 | 3. Insert the sql to your database. 28 | 4. If you want the bag in your shop you'll have to insert this row 29 | 30 | ```INSERT INTO `shops` (store, item, price) VALUES 31 | ('TwentyFourSeven','bag',1000), 32 | ('RobsLiquor','bag',1000), 33 | ('LTDgasoline','bag',1000);``` 34 | 35 | **Video** 36 | 37 | https://streamable.com/a4y2o 38 | -------------------------------------------------------------------------------- /esx-kr-bag-inventory/server/main.lua: -------------------------------------------------------------------------------- 1 | local ESX = nil 2 | 3 | -- ESX 4 | TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) 5 | 6 | ESX.RegisterUsableItem('bag', function(source) 7 | local xPlayer = ESX.GetPlayerFromId(source) 8 | 9 | xPlayer.removeInventoryItem('bag', 1) 10 | 11 | TriggerClientEvent('esx-kr-bag:CheckBag', source, HasBag) 12 | if not HasBag then 13 | TriggerEvent('esx-kr-bag:InsertBag', source) 14 | else 15 | TriggerClientEvent('esx:showNotification', source, '~r~You already have a bag on you.') 16 | end 17 | end) 18 | 19 | ESX.RegisterServerCallback('esx-kr-bag:getPlayerInventory', function(source, cb) 20 | local xPlayer = ESX.GetPlayerFromId(source) 21 | local items = xPlayer.inventory 22 | 23 | cb({items = items}) 24 | end) 25 | 26 | ESX.RegisterServerCallback('esx-kr-bag:getBag', function(source, cb) 27 | local src = source 28 | local identifier = ESX.GetPlayerFromId(src).identifier 29 | 30 | MySQL.Async.fetchAll('SELECT * FROM owned_bags WHERE identifier = @identifier ',{["@identifier"] = identifier}, function(bag) 31 | 32 | if bag[1] ~= nil then 33 | MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id ',{["@id"] = bag[1].id}, function(inventory) 34 | cb({bag = bag, inventory = inventory}) 35 | end) 36 | else 37 | cb(nil) 38 | end 39 | end) 40 | end) 41 | 42 | ESX.RegisterServerCallback('esx-kr-bag:getAllBags', function(source, cb) 43 | local src = source 44 | 45 | MySQL.Async.fetchAll('SELECT * FROM owned_bags', {}, function(bags) 46 | 47 | if bags[1] ~= nil then 48 | cb(bags) 49 | else 50 | cb(nil) 51 | end 52 | end) 53 | end) 54 | 55 | 56 | ESX.RegisterServerCallback('esx-kr-bag:getBagInventory', function(source, cb, BagId) 57 | local src = source 58 | local identifier = ESX.GetPlayerFromId(src).identifier 59 | 60 | MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id ',{["@id"] = BagId}, function(bag) 61 | cb(bag) 62 | end) 63 | end) 64 | 65 | RegisterServerEvent('esx-kr-bag:InsertBag') 66 | AddEventHandler('esx-kr-bag:InsertBag', function(source) 67 | local src = source 68 | local identifier = ESX.GetPlayerFromId(src).identifier 69 | local xPlayer = ESX.GetPlayerFromId(src) 70 | local xPlayers = ESX.GetPlayers() 71 | 72 | TriggerClientEvent('esx-kr-bag:GiveBag', src) 73 | for i=1, #xPlayers, 1 do 74 | TriggerClientEvent('esx-kr-bag:ReSync', xPlayers[i], id) 75 | end 76 | MySQL.Async.execute('INSERT INTO owned_bags (identifier, id, x, y, z) VALUES (@identifier, @id, @x, @y, @z)', {['@identifier'] = identifier,['@id'] = math.random(1, 100000), ['@x'] = nil, ['@y'] = nil, ['@y'] = nil}) 77 | end) 78 | 79 | RegisterServerEvent('esx-kr-bag:TakeItem') 80 | AddEventHandler('esx-kr-bag:TakeItem', function(id, item, count, type) 81 | local src = source 82 | local identifier = ESX.GetPlayerFromId(src).identifier 83 | local xPlayer = ESX.GetPlayerFromId(src) 84 | 85 | MySQL.Async.fetchAll('SELECT * FROM owned_bags WHERE id = @id ',{["@id"] = id}, function(bag) 86 | MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id AND item = @item ',{["@id"] = id, ["@item"] = item}, function(result) 87 | 88 | if result[1] ~= nil then 89 | 90 | if type == 'weapon' then 91 | xPlayer.addWeapon(item, count) 92 | elseif type == 'item' then 93 | xPlayer.addInventoryItem(item, count) 94 | end 95 | MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE id = @id', {['@id'] = id, ['@itemcount'] = bag[1].itemcount - 1}) 96 | MySQL.Async.execute('DELETE FROM owned_bag_inventory WHERE id = @id AND item = @item AND count = @count',{['@id'] = id,['@item'] = item, ['@count'] = count}) 97 | end 98 | end) 99 | end) 100 | end) 101 | 102 | RegisterServerEvent('esx-kr-bag:PutItem') 103 | AddEventHandler('esx-kr-bag:PutItem', function(id, item, label, count, type) 104 | local src = source 105 | local xPlayer = ESX.GetPlayerFromId(src) 106 | local identifier = ESX.GetPlayerFromId(src).identifier 107 | local update 108 | local insert 109 | 110 | MySQL.Async.fetchAll('SELECT * FROM owned_bags WHERE identifier = @identifier ',{["@identifier"] = identifier}, function(bag) 111 | 112 | if bag[1].itemcount < Config.MaxDifferentItems then 113 | 114 | if type == 'weapon' then 115 | xPlayer.removeWeapon(item, count) 116 | MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1}) 117 | 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}) 118 | elseif type == 'item' and count < Config.MaxItemCount then 119 | xPlayer.removeInventoryItem(item, count) 120 | MySQL.Async.fetchAll('SELECT * FROM owned_bag_inventory WHERE id = @id ',{["@id"] = id}, function(result) 121 | if result[1] ~= nil then 122 | for i=1, #result, 1 do 123 | if result[i].item == item then 124 | count = count + result[i].count 125 | update = 1 126 | elseif result[i].item ~= item then 127 | insert = 1 128 | end 129 | end 130 | if update == 1 then 131 | MySQL.Async.execute('UPDATE owned_bag_inventory SET count = @count WHERE item = @item', {['@item'] = item, ['@count'] = count}) 132 | elseif insert == 1 then 133 | MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1}) 134 | 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}) 135 | end 136 | else 137 | MySQL.Async.execute('UPDATE owned_bags SET itemcount = @itemcount WHERE identifier = @identifier', {['@identifier'] = identifier, ['@itemcount'] = bag[1].itemcount + 1}) 138 | 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}) 139 | end 140 | end) 141 | end 142 | else 143 | TriggerClientEvent('esx:showNotification', src, '~r~You can only have ' .. Config.MaxItemCount .. ' different items in your bag') 144 | end 145 | end) 146 | end) 147 | RegisterServerEvent('esx-kr-bag:PickUpBag') 148 | AddEventHandler('esx-kr-bag:PickUpBag', function(id) 149 | local src = source 150 | local identifier = ESX.GetPlayerFromId(src).identifier 151 | 152 | MySQL.Async.fetchAll('UPDATE owned_bags SET identifier = @identifier, x = @x, y = @y, z = @z WHERE id = @id', {['@identifier'] = identifier, ['@id'] = id, ['@x'] = nil, ['@y'] = nil, ['@z'] = nil}) 153 | 154 | local xPlayers = ESX.GetPlayers() 155 | 156 | for i=1, #xPlayers, 1 do 157 | TriggerClientEvent('esx-kr-bag:SetOntoPlayer', src, id) 158 | TriggerClientEvent('esx:showNotification', src, 'Press ~b~[F5]~w~ to access your bag.') 159 | TriggerClientEvent('esx-kr-bag:ReSync', xPlayers[i], id) 160 | end 161 | end) 162 | 163 | RegisterServerEvent('esx-kr-bag:DropBag') 164 | AddEventHandler('esx-kr-bag:DropBag', function(id, x, y, z) 165 | local src = source 166 | local identifier = ESX.GetPlayerFromId(src).identifier 167 | 168 | MySQL.Async.fetchAll('UPDATE owned_bags SET identifier = @identifier, x = @x, y = @y, z = @z WHERE id = @id', {['@identifier'] = nil, ['@id'] = id, ['@x'] = x, ['@y'] = y, ['@z'] = z}) 169 | 170 | local xPlayers = ESX.GetPlayers() 171 | 172 | for i=1, #xPlayers, 1 do 173 | TriggerClientEvent('esx-kr-bag:ReSync', xPlayers[i], id) 174 | end 175 | end) 176 | -------------------------------------------------------------------------------- /esx-kr-bag-inventory/client/main.lua: -------------------------------------------------------------------------------- 1 | local Keys = { 2 | ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, 3 | ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, 4 | ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, 5 | ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, 6 | ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, 7 | ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, 8 | ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, 9 | ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, 10 | ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 11 | } 12 | 13 | ESX = nil 14 | 15 | local HasBag = false 16 | local Bags = {} 17 | local BagId = false 18 | 19 | Citizen.CreateThread(function() 20 | while ESX == nil do 21 | TriggerEvent('esx:getSharedObject', function(obj) 22 | ESX = obj 23 | end) 24 | 25 | Citizen.Wait(0) 26 | end 27 | 28 | -- On restart check down below. 29 | 30 | if ESX.IsPlayerLoaded() then 31 | ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags) 32 | if bags ~= nil then 33 | for i=1, #bags, 1 do 34 | TriggerEvent('esx-kr-bag:SpawnBagIntoClient', bags[i].x, bags[i].y, bags[i].z) 35 | TriggerEvent('esx-kr-bag:insertIntoClient', bags[i].id) 36 | end 37 | end 38 | 39 | ESX.TriggerServerCallback('esx-kr-bag:getBag', function(bag) 40 | if bag ~= nil then 41 | BagId = bag.bag[1].id 42 | HasBag = true 43 | TriggerEvent('esx-kr-bag:SetOntoPlayer') 44 | end 45 | end) 46 | end) 47 | end 48 | end) 49 | 50 | function Draw3DText(x, y, z, text) 51 | local onScreen,_x,_y=World3dToScreen2d(x,y,z) 52 | local px,py,pz=table.unpack(GetGameplayCamCoords()) 53 | local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1) 54 | 55 | local scale = 0.25 56 | 57 | if onScreen then 58 | SetTextScale(scale, scale) 59 | SetTextFont(0) 60 | SetTextProportional(1) 61 | SetTextColour(255, 255, 255, 255) 62 | SetTextDropshadow(1, 1, 0, 0, 255) 63 | SetTextEdge(0, 0, 0, 0, 150) 64 | SetTextDropShadow() 65 | SetTextOutline() 66 | SetTextEntry("STRING") 67 | SetTextCentre(2) 68 | AddTextComponentString(text) 69 | DrawText(_x,_y) 70 | end 71 | end 72 | 73 | RegisterNetEvent('esx:playerLoaded') 74 | AddEventHandler('esx:playerLoaded', function(xPlayer) 75 | 76 | Citizen.Wait(200) 77 | 78 | PlayerData = xPlayer 79 | 80 | ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags) 81 | if bags ~= nil then 82 | for i=1, #bags, 1 do 83 | TriggerEvent('esx-kr-bag:SpawnBagIntoClient', bags[i].x, bags[i].y, bags[i].z) 84 | TriggerEvent('esx-kr-bag:insertIntoClient', bags[i].id) 85 | 86 | 87 | end 88 | end 89 | 90 | ESX.TriggerServerCallback('esx-kr-bag:getBag', function(bag) 91 | if bag ~= nil then 92 | BagId = bag.bag[1].id 93 | HasBag = true 94 | TriggerEvent('esx-kr-bag:SetOntoPlayer') 95 | 96 | end 97 | end) 98 | end) 99 | end) 100 | 101 | RegisterNetEvent('esx-kr-bag:SetOntoPlayer') 102 | AddEventHandler('esx-kr-bag:SetOntoPlayer', function(id) 103 | ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) 104 | if HasBag and skin.bags_1 ~= 45 then 105 | TriggerEvent('skinchanger:change', "bags_1", 45) 106 | TriggerEvent('skinchanger:change', "bags_2", 0) 107 | TriggerEvent('skinchanger:getSkin', function(skin) 108 | TriggerServerEvent('esx_skin:save', skin) 109 | end) 110 | end 111 | end) 112 | end) 113 | 114 | function LoadAnimation(dict) 115 | RequestAnimDict(dict) 116 | 117 | while not HasAnimDictLoaded(dict) do 118 | Wait(100) 119 | end 120 | end 121 | 122 | RegisterNetEvent('esx-kr-bag:insertIntoClient') 123 | AddEventHandler('esx-kr-bag:insertIntoClient', function(id) 124 | ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags) 125 | for i=1, #bags, 1 do 126 | table.insert(Bags, {id = {coords = {x = bags[i].x, y = bags[i].y, z = bags[i].z}, id = bags[i].id}}) 127 | end 128 | end) 129 | end) 130 | 131 | RegisterNetEvent('esx-kr-bag:ReSync') 132 | AddEventHandler('esx-kr-bag:ReSync', function(id) 133 | Bags = {} 134 | 135 | ESX.TriggerServerCallback('esx-kr-bag:getAllBags', function(bags) 136 | for i=1, #bags, 1 do 137 | table.insert(Bags, {id = {coords = {x = bags[i].x, y = bags[i].y, z = bags[i].z}, id = bags[i].id}}) 138 | end 139 | end) 140 | end) 141 | 142 | 143 | function Bag() 144 | 145 | local elements = {} 146 | 147 | table.insert(elements, {label = 'Put object', value = 'put'}) 148 | table.insert(elements, {label = 'Take object', value = 'take'}) 149 | table.insert(elements, {label = 'Drop bag', value = 'drop'}) 150 | 151 | ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'lel', 152 | { 153 | title = 'Bag', 154 | align = 'left', 155 | elements = elements 156 | }, function(data, menu) 157 | 158 | if data.current.value == 'put' then 159 | PutItem() 160 | elseif data.current.value == 'take'then 161 | TakeItem() 162 | elseif data.current.value == 'drop' then 163 | DropBag() 164 | end 165 | end, function(data, menu) 166 | menu.close() 167 | end) 168 | end 169 | 170 | 171 | RegisterNetEvent('esx-kr-bag:GiveBag') 172 | AddEventHandler('esx-kr-bag:GiveBag', function() 173 | ESX.TriggerServerCallback('esx-kr-bag:getBag', function(bag) 174 | if bag ~= nil then 175 | BagId = bag.bag[1].id 176 | HasBag = true 177 | TriggerEvent('esx-kr-bag:SetOntoPlayer') 178 | end 179 | end) 180 | end) 181 | 182 | RegisterNetEvent('esx-kr-bag:CheckBag') 183 | AddEventHandler('esx-kr-bag:CheckBag', function() 184 | if HasBag then 185 | return true 186 | else 187 | return false 188 | end 189 | end) 190 | 191 | RegisterNetEvent('esx-kr-bag:SpawnBagIntoClient') 192 | AddEventHandler('esx-kr-bag:SpawnBagIntoClient', function(x, y ,z) 193 | local coords3 = { 194 | x = x, 195 | y = y, 196 | z = z 197 | } 198 | 199 | ESX.Game.SpawnObject(1626933972, coords3, function(bag) 200 | FreezeEntityPosition(bag, true) 201 | SetEntityAsMissionEntity(object, true, false) 202 | SetEntityCollision(bag, false, true) 203 | end) 204 | end) 205 | 206 | function DropBag() 207 | ESX.UI.Menu.CloseAll() 208 | HasBag = false 209 | 210 | local coords1 = GetEntityCoords(PlayerPedId()) 211 | local headingvector = GetEntityForwardVector(PlayerPedId()) 212 | local x, y, z = table.unpack(coords1 + headingvector * 1.0) 213 | 214 | local coords2 = { 215 | x = x, 216 | y = y, 217 | z = z - 1 218 | } 219 | 220 | z2 = z - 1 221 | 222 | TriggerServerEvent('esx-kr-bag:DropBag', BagId, x, y, z2) 223 | 224 | ESX.Game.SpawnObject(1626933972, coords2, function(bag) 225 | FreezeEntityPosition(bag, true) 226 | SetEntityCollision(bag, false, true) 227 | TriggerEvent('skinchanger:change', "bags_1", 0) 228 | TriggerEvent('skinchanger:change', "bags_2", 0) 229 | TriggerEvent('skinchanger:getSkin', function(skin) 230 | TriggerServerEvent('esx_skin:save', skin) 231 | end) 232 | end) 233 | end 234 | 235 | function IsWeapon(item) 236 | local hash = GetHashKey(item) 237 | local IsWeapon = IsWeaponValid(hash) 238 | 239 | if IsWeapon then 240 | return true 241 | else 242 | return false 243 | end 244 | end 245 | 246 | 247 | function TakeItem() 248 | 249 | local elements = {} 250 | 251 | ESX.TriggerServerCallback('esx-kr-bag:getBagInventory', function(bag) 252 | 253 | for i=1, #bag, 1 do 254 | table.insert(elements, {label = bag[i].label .. ' | ' .. bag[i].count .. 'x', value = bag[i].item, count = bag[i].count}) 255 | end 256 | 257 | ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'lels', 258 | { 259 | title = 'Bag', 260 | align = 'left', 261 | elements = elements 262 | }, function(data, menu) 263 | 264 | local IsWeapon = IsWeapon(data.current.value) 265 | menu.close() 266 | if IsWeapon then 267 | TriggerServerEvent('esx-kr-bag:TakeItem', BagId, data.current.value, data.current.count, "weapon") 268 | else 269 | TriggerServerEvent('esx-kr-bag:TakeItem', BagId, data.current.value, data.current.count, "item") 270 | end 271 | 272 | end, function(data, menu) 273 | menu.close() 274 | end) 275 | end, BagId) 276 | end 277 | 278 | 279 | function PutItem() 280 | 281 | local elements = {} 282 | 283 | ESX.TriggerServerCallback('esx-kr-bag:getPlayerInventory', function(result) 284 | 285 | for i=1, #result.items, 1 do 286 | local invitem = result.items[i] 287 | if invitem.count > 0 then 288 | table.insert(elements, { label = invitem.label .. ' | ' .. invitem.count .. 'x', count = invitem.count, name = invitem.name, label2 = invitem.label}) 289 | end 290 | end 291 | 292 | local weaponList = ESX.GetWeaponList() 293 | 294 | for i=1, #weaponList, 1 do 295 | local weaponHash = GetHashKey(weaponList[i].name) 296 | local ammo = GetAmmoInPedWeapon(GetPlayerPed(-1), weaponHash) 297 | 298 | if HasPedGotWeapon(GetPlayerPed(-1), weaponHash, false) and weaponList[i].name ~= 'WEAPON_UNARMED' then 299 | table.insert(elements, {label = weaponList[i].label .. ' | ' .. ammo .. 'x', name = weaponList[i].name, count = ammo, label2 = weaponList[i].label}) 300 | end 301 | end 302 | 303 | ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'lel3', 304 | { 305 | title = 'Bag', 306 | align = 'left', 307 | elements = elements 308 | }, function(data, menu) 309 | 310 | local IsWeapon = IsWeapon(data.current.name) 311 | menu.close() 312 | 313 | if IsWeapon then 314 | TriggerServerEvent('esx-kr-bag:PutItem', BagId, data.current.name, data.current.label2, data.current.count, "weapon") 315 | else 316 | TriggerServerEvent('esx-kr-bag:PutItem', BagId, data.current.name, data.current.label2, data.current.count, "item") 317 | end 318 | 319 | end, function(data, menu) 320 | menu.close() 321 | end) 322 | end) 323 | end 324 | 325 | Citizen.CreateThread(function() 326 | while true do 327 | 328 | local wait = 500 329 | 330 | for i=1, #Bags, 1 do 331 | 332 | local playercoords = GetEntityCoords(PlayerPedId()) 333 | 334 | if GetDistanceBetweenCoords(playercoords, Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z, true) <= 1.5 and not HasBag then 335 | wait = 5 336 | 337 | 338 | Draw3DText(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z + 0.45, '~g~[E]~w~ to Pick up the bag') 339 | Draw3DText(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z + 0.35, '~o~[N]~w~ to Search the bag') 340 | 341 | if IsControlJustReleased(0, Keys['E']) then 342 | HasBag = true 343 | BagId = Bags[i].id.id 344 | 345 | local Bag = GetClosestObjectOfType(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z, 1.5, 1626933972, false, false, false) 346 | 347 | NetworkFadeOutEntity(Bag, false, false) 348 | DeleteObject(Bag) 349 | 350 | TriggerServerEvent('esx-kr-bag:PickUpBag', Bags[i].id.id) 351 | end 352 | 353 | if IsControlJustReleased(0, Keys['N']) then 354 | HasBag = false 355 | BagId = Bags[i].id.id 356 | TakeItem() 357 | 358 | wait = 5 359 | Draw3DText(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z + 0.45, '~g~[E]~w~ to pick up the bag') 360 | Draw3DText(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z + 0.35, '~o~[N]~w~ to Search bag') 361 | 362 | if IsControlJustReleased(0, Keys['E']) then 363 | HasBag = true 364 | BagId = Bags[i].id.id 365 | local Bag = GetClosestObjectOfType(Bags[i].id.coords.x, Bags[i].id.coords.y, Bags[i].id.coords.z, 1.5, 1626933972, false, false, false) 366 | 367 | NetworkFadeOutEntity(Bag, false, false) 368 | DeleteObject(Bag) 369 | 370 | TriggerServerEvent('esx-kr-bag:PickUpBag', Bags[i].id.id) 371 | end 372 | if IsControlJustReleased(0, Keys['N']) then 373 | HasBag = false 374 | BagId = Bags[i].id.id 375 | TakeItem() 376 | 377 | end 378 | 379 | end 380 | end 381 | end 382 | 383 | Citizen.Wait(wait) 384 | end 385 | end) 386 | 387 | Citizen.CreateThread(function() 388 | while true do 389 | Wait(5) 390 | 391 | if IsControlJustReleased(0, Keys['F5']) and HasBag and not IsPedInAnyVehicle(GetPlayerPed(-1), true) and not IsEntityInAir(PlayerPedId()) then -- Change F5 to the key you want to open the meny with 392 | Bag() 393 | end 394 | end 395 | end) 396 | --------------------------------------------------------------------------------