SHARE
TWEET

Untitled

a guest Feb 15th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. -- server
  3. backpacks = {}
  4.  
  5. AddEventHandler("vRP:playerSpawn", function(user_id, source, first_spawn)
  6.   if source ~= nil and user_id ~= nil then
  7.     vRPclient.hasBackpack(source,{}, function(backpack)
  8.       if backpack then
  9.         backpacks[source] = 15
  10.       else
  11.         backpacks[source] = 0
  12.       end
  13.     end)
  14.   end
  15. end)
  16.  
  17. function math.randomchoice(t) --Selects a random item from a table
  18.   local keys = {}
  19.   for key, value in pairs(t) do
  20.     for k,v in pairs(value) do print(k,v) end
  21.       value["idname"] = key
  22.       keys[#keys+1] = {value = value} --Store keys in another table
  23.   end
  24.   index = keys[math.random(1, #keys)]
  25.   return index
  26. end
  27.  
  28. RegisterServerEvent("updateBackpackWeight")
  29. AddEventHandler("updateBackpackWeight", function()
  30.   if source ~= nil then
  31.     vRPclient.hasBackpack(source,{}, function(backpack)
  32.       if backpack then
  33.         backpacks[source] = 15
  34.       else
  35.         backpacks[source] = 0
  36.       end
  37.  
  38.       local user_id = vRP.getUserId(source)
  39.  
  40.       if vRP.getInventoryWeight(user_id) > vRP.getInventoryMaxWeight(user_id) then
  41.         local data = vRP.getUserDataTable(user_id)
  42.         while vRP.getInventoryWeight(user_id) > vRP.getInventoryMaxWeight(user_id) do
  43.           local overweight = vRP.getInventoryWeight(user_id) - vRP.getInventoryMaxWeight(user_id)
  44.           local random = math.randomchoice(data.inventory)
  45.           for i,p in pairs(random) do
  46.            
  47.  
  48.  
  49.  
  50.             vRP.tryGetInventoryItem(user_id,p.idname,p.amount,true)
  51.           end
  52.         end
  53.       end
  54.     end)
  55.   end
  56. end)
  57.  
  58. AddEventHandler("playerDropped", function()
  59.   if source ~= nil then
  60.     backpacks[source] = 0
  61.   end
  62. end)
  63.  
  64. AddEventHandler("vRP:playerDied",function()
  65.   if source ~= nil then
  66.     TriggerClientEvent("removeBackpack", source)
  67.   end
  68. end)
  69.  
  70. -- return maximum weight of the user inventory
  71. function vRP.getInventoryMaxWeight(user_id)
  72.   return math.floor(vRP.expToLevel(vRP.getExp(user_id, "physical", "strength")))*cfg.inventory_weight_per_strength + backpacks[vRP.getUserSource(user_id)]
  73. end
  74.  
  75.  
  76. -- client
  77. function tvRP.hasBackpack()
  78.   if GetPedDrawableVariation(GetPlayerPed(-1), 5) ~= nil and GetPedDrawableVariation(GetPlayerPed(-1), 5) ~= 0 then
  79.     return true
  80.   end
  81.   return false
  82. end
  83.  
  84. RegisterNetEvent("equipBackpack")
  85. AddEventHandler("equipBackpack", function()
  86.   SetPedComponentVariation(PlayerPedId(), 5, 45, 0, 0)
  87.   TriggerServerEvent("updateBackpackWeight")
  88. end)
  89.  
  90. RegisterNetEvent("removeBackpack")
  91. AddEventHandler("removeBackpack", function()
  92.   SetPedComponentVariation(PlayerPedId(), 5, 0, 0,0 )
  93.   TriggerServerEvent("updateBackpackWeight")
  94. end)
  95.  
  96. RegisterCommand("taske", function(source, args)
  97.   SetPedComponentVariation(PlayerPedId(), 5, 0, 0,0 )
  98.   TriggerServerEvent("updateBackpackWeight")
  99. end, false)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top