Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- server
- backpacks = {}
- AddEventHandler("vRP:playerSpawn", function(user_id, source, first_spawn)
- if source ~= nil and user_id ~= nil then
- vRPclient.hasBackpack(source,{}, function(backpack)
- if backpack then
- backpacks[source] = 15
- else
- backpacks[source] = 0
- end
- end)
- end
- end)
- function math.randomchoice(t) --Selects a random item from a table
- local keys = {}
- for key, value in pairs(t) do
- for k,v in pairs(value) do print(k,v) end
- value["idname"] = key
- keys[#keys+1] = {value = value} --Store keys in another table
- end
- index = keys[math.random(1, #keys)]
- return index
- end
- RegisterServerEvent("updateBackpackWeight")
- AddEventHandler("updateBackpackWeight", function()
- if source ~= nil then
- vRPclient.hasBackpack(source,{}, function(backpack)
- if backpack then
- backpacks[source] = 15
- else
- backpacks[source] = 0
- end
- local user_id = vRP.getUserId(source)
- if vRP.getInventoryWeight(user_id) > vRP.getInventoryMaxWeight(user_id) then
- local data = vRP.getUserDataTable(user_id)
- while vRP.getInventoryWeight(user_id) > vRP.getInventoryMaxWeight(user_id) do
- local overweight = vRP.getInventoryWeight(user_id) - vRP.getInventoryMaxWeight(user_id)
- local random = math.randomchoice(data.inventory)
- for i,p in pairs(random) do
- vRP.tryGetInventoryItem(user_id,p.idname,p.amount,true)
- end
- end
- end
- end)
- end
- end)
- AddEventHandler("playerDropped", function()
- if source ~= nil then
- backpacks[source] = 0
- end
- end)
- AddEventHandler("vRP:playerDied",function()
- if source ~= nil then
- TriggerClientEvent("removeBackpack", source)
- end
- end)
- -- return maximum weight of the user inventory
- function vRP.getInventoryMaxWeight(user_id)
- return math.floor(vRP.expToLevel(vRP.getExp(user_id, "physical", "strength")))*cfg.inventory_weight_per_strength + backpacks[vRP.getUserSource(user_id)]
- end
- -- client
- function tvRP.hasBackpack()
- if GetPedDrawableVariation(GetPlayerPed(-1), 5) ~= nil and GetPedDrawableVariation(GetPlayerPed(-1), 5) ~= 0 then
- return true
- end
- return false
- end
- RegisterNetEvent("equipBackpack")
- AddEventHandler("equipBackpack", function()
- SetPedComponentVariation(PlayerPedId(), 5, 45, 0, 0)
- TriggerServerEvent("updateBackpackWeight")
- end)
- RegisterNetEvent("removeBackpack")
- AddEventHandler("removeBackpack", function()
- SetPedComponentVariation(PlayerPedId(), 5, 0, 0,0 )
- TriggerServerEvent("updateBackpackWeight")
- end)
- RegisterCommand("taske", function(source, args)
- SetPedComponentVariation(PlayerPedId(), 5, 0, 0,0 )
- TriggerServerEvent("updateBackpackWeight")
- end, false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement