local Chests = {} local function getChestMaxWeight(id) local s = splitString(id, ":") local type = s[1] local maxWeight = Config.DefaultChestMaxWeight if type == "trunk" then local vehicle = s[3] local thisWeight = Config.Trunks[vehicle] maxWeight = Config.DefaultTrunkWeight if thisWeight ~= nil then maxWeight = thisWeight end elseif type == "glovebox" then local vehicle = s[3] local thisWeight = Config.Gloveboxes[vehicle] maxWeight = Config.DefaultGloveboxWeight if thisWeight ~= nil then maxWeight = thisWeight end elseif type == "chest" then local chestId = s[2] if Config.Chests[chestId] ~= nil then local thisWeight = Config.Chests[chestId].maxWeight if thisWeight ~= nil then maxWeight = thisWeight end end elseif type == 'deposit' then maxWeight = 5000 end return maxWeight end function vRPin.putIntoChest(idname, amount) local user_id = vRP.getUserId({source}) local chestname = openInventories[user_id] local player = vRP.getUserSource({user_id}) if idname == "id_doc" or idname == "permis_masina" or idname == "policebadge" or idname == "gunpermit_doc" then return vRPclient.notify(player, {"Eroare: Nu poti depozita acest item aici!"}) end if vRP.isUserInFaction({user_id, "Politie"}) then if string.find(idname, "WEAPON_") or string.find(idname, "bandaj_mic") or string.find(idname, "medkit") or string.find(idname, "adrenalina") or string.find(idname, "ammo-") or string.find(idname, "suppressor") or string.find(idname, "lanterna") or string.find(idname, "extended") then return vRPclient.notify(player,{"Eroare: Nu poti oferi din bunurile factiunii!"}) end end if vRP.isUserInFaction({user_id, "Smurd"}) then if string.find(idname, "WEAPON_") or string.find(idname, "bandaj_mic") or string.find(idname, "medkit") then return vRPclient.notify(player,{"Eroare: Nu poti oferi din bunurile factiunii!"}) end end if vRP.isUserInFaction({user_id, "Diicot"}) then if string.find(idname, "WEAPON_") or string.find(idname, "medkit") or string.find(idname, "bandaj_mic") or string.find(idname, "adrenalina") or string.find(idname, "ammo-") or string.find(idname, "suppressor") or string.find(idname, "lanterna") or string.find(idname, "extended") then return vRPclient.notify(player,{"Eroare: Nu poti oferi din bunurile factiunii!"}) end end if chestname ~= nil then local items = Chests[chestname] or {} local new_weight = vRP.computeItemsWeight({items})+vRP.getItemWeight({idname})*amount if new_weight <= getChestMaxWeight(chestname) then if amount >= 0 and vRP.tryGetInventoryItem({user_id, idname, amount, true}) then local citem = items[idname] if citem ~= nil then citem.amount = citem.amount+amount else items[idname] = {amount=amount} end Chests[chestname] = items local logs = string.format("[CHEST] %s (%d) a PUS %dx %s in %s", GetPlayerName(player), user_id, amount, idname, chestname) TriggerEvent("vRP:logChestAction", logs) end else vRPclient.notify(player,{"Eroare: Chest plin"}) end Wait(20) vRPin.getChestItems(chestname, player) INclient.loadPlayerInventory(player) end end function vRPin.takeFromChest(idname, amount) local user_id = vRP.getUserId({source}) local chestname = openInventories[user_id] local player = vRP.getUserSource({user_id}) if chestname ~= nil then local items = Chests[chestname] or {} local citem = items[idname] if amount >= 0 and amount <= citem.amount then local new_weight = vRP.getInventoryWeight({user_id})+vRP.getItemWeight({idname})*amount if new_weight <= vRP.getInventoryMaxWeight({user_id}) then vRP.giveInventoryItem({user_id, idname, amount, true}) citem.amount = citem.amount-amount if citem.amount <= 0 then items[idname] = nil end Chests[chestname] = items local logs = string.format("[CHEST] %s (%d) a LUAT %dx %s din %s", GetPlayerName(player), user_id, amount, idname, chestname) TriggerEvent("vRP:logChestAction", logs) else vRPclient.notify(player,{"Eroare: Inventar plin!"}) end end Wait(20) vRPin.getChestItems(chestname, player) INclient.loadPlayerInventory(player) end end function vRPin.getChestItems(chestname, player, label) if Chests[chestname] then local weight = vRP.computeItemsWeight({Chests[chestname]}) local max_weight = getChestMaxWeight(chestname) local items = {} for k,v in pairs(Chests[chestname]) do local item_name,description,weight = vRP.getItemDefinition({k}) items[#items+1] = {label = item_name, count = v.amount, description = description, name = k, weight = weight} end INclient.setSecondInventoryItems(player, {items, weight, max_weight, label}) else vRP.getSData({chestname, function(cdata) local rawItems = json.decode(cdata) or {} local items = {} local weight = vRP.computeItemsWeight({rawItems}) local max_weight = getChestMaxWeight(chestname) for k,v in pairs(rawItems) do local item_name,description,weight = vRP.getItemDefinition({k}) items[#items+1] = {label = item_name, count = v.amount, description = description, name = k, weight = weight} end INclient.setSecondInventoryItems(player, {items, weight, max_weight, label}) Chests[chestname] = rawItems end}) end end function openTrunk(player, user_id, owner_id, vname, vtype) local id = "trunk:user-" .. owner_id .. ":" .. string.lower(vname) if isChestFree(id) then openInventories[user_id] = id INclient.openInventory(player, {"trunk"}) vRPin.getChestItems(id, player) local ownerSource = vRP.getUserSource({owner_id}) vRPclient.vc_openDoor(ownerSource, {vtype,5}) vTypes[user_id] = {ownerSource,vtype} vRPclient.playAnim(player,{true,{{"mini@repair","fixing_a_player",1}},true}) else vRPclient.notify(player,{"Eroare: Portbagajul este folosit de altcineva"}) end end function openGlovebox(player, user_id, owner_id, vname) local id = "glovebox:user-" .. owner_id .. ":" .. string.lower(vname) if isChestFree(id) then openInventories[user_id] = id INclient.openInventory(player, {"glovebox"}) vRPin.getChestItems(id, player) vRPclient.playAnim(player,{true,{{"mini@repair","fixing_a_player",1}},true}) else vRPclient.notify(player,{"Eroare: Torpedoul este folosit de altcineva"}) end end function isChestFree(id) for user_id, chestId in pairs(openInventories) do if chestId == id then return false end end return true end function openChest(user_id, player, id, label) if isChestFree(id) then openInventories[user_id] = id INclient.openInventory(player, {"chest"}) vRPin.getChestItems(id, player, label) else vRPclient.notify(player,{"Eroare: Altcineva foloseste aceasta actiune acum!"}) end end exports("openChest", openChest) function vRPin.openDeposit(name, pos) if not (name and pos) then return end local player = source local user_id = vRP.getUserId{player} if not user_id then return end if vRP.tryPayment({user_id,Config.Depozite[name].accesPrice}) then local label = 'deposit:'..name..':user-'..user_id openChest(user_id, player, label, name) else vRPclient.notify(player, {"Eroare: Nu ai suficienti bani pentru a face acest lucru!"}) end end function vRPin.openChest(name, pos) local user_id = vRP.getUserId({source}) if user_id ~= nil then local id = "chest:".. name if vRP.hasPermission({user_id, Config.Chests[name].permission}) then openChest(user_id, source, id, name) end end end RegisterServerEvent('server$saveChests',function() for k,v in pairs(Chests) do vRP.setSData({k,json.encode(v)}) end end) exports("getChests",function() return Chests end) function task_save_chests() for k,v in pairs(Chests) do vRP.setSData({k,json.encode(v)}) end CreateThread(function() Wait(3000) task_save_chests() end) end CreateThread(function() Wait(3000) task_save_chests() end) AddEventHandler("vRP:logChestAction", function(msg) PerformHttpRequest("https://discord.com/api/webhooks/1388541084547809382/fT0PLayqyeBTXHVyLKVcaeJceUcf-cgzTA6zsFxIlH7nMpnazKbjcyOBSIwnk1ddcs0N", function() end, "POST", json.encode({ username = "Logs Chest", embeds = {{ color = 65280, title = "Interacțiune Chest", description = msg, footer = { text = os.date("%d/%m/%Y - %H:%M:%S") } }} }), { ["Content-Type"] = "application/json" }) end)