Advertisement
Friks12829

Untitled

Jan 3rd, 2020
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. function meta:AddItem(type, class, count)
  2. if not IsValid(self) then return end
  3. if table.HasValue(cfg.Inventory.BlackListItems, class) then return end
  4.  
  5.  
  6.  
  7. local Items = sql.Query("SELECT * FROM Inventory WHERE steamid = '"..self:SteamID().."' AND class = '"..class.."';") or {}
  8.  
  9. local c = count
  10. local slots = {}
  11.  
  12. if Items != nil then
  13. for i=1, #Items do
  14. if tonumber(Items[i].count) >= 20 then continue end
  15.  
  16. if c <= 0 then break end
  17.  
  18. local newcount = (20 - Items[i].count)
  19.  
  20. if newcount >= c then newcount = c end
  21.  
  22. if newcount != 0 and newcount > 0 then
  23. c = c - newcount
  24.  
  25. slots[i] =
  26. {
  27. ['newcount'] = newcount,
  28. ['lastcount'] = tonumber(Items[i].count)
  29. }
  30. end
  31. end
  32.  
  33. for k, count in pairs(slots) do
  34. sql.Query("UPDATE Inventory SET count = " .. (count['newcount'] + count['lastcount']) .. " WHERE SteamID = '" .. self:SteamID().."' AND class='"..class.."' AND count = "..(count['lastcount'])..";")
  35.  
  36. print('Количество обновлено.')
  37. end
  38.  
  39. while c > 0 do
  40. if c >= 20 then
  41. sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..(20).."');")
  42. c = c - 20
  43. else
  44. sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..c.."');")
  45. c = 0
  46. end
  47.  
  48. print('Предмет добавлен в новый слот.')
  49. end
  50. else
  51. for i=1, math.Round(count / 20) do
  52. if c >= 20 then
  53. sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..(20).."');")
  54. c = c - 20
  55. else
  56. sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..c.."');")
  57. c = 0
  58. break
  59. end
  60. print('Предмет добавлен.')
  61. end
  62. end
  63.  
  64. self:SaveInventory()
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement