Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function meta:AddItem(type, class, count)
- if not IsValid(self) then return end
- if table.HasValue(cfg.Inventory.BlackListItems, class) then return end
- local Items = sql.Query("SELECT * FROM Inventory WHERE steamid = '"..self:SteamID().."' AND class = '"..class.."';") or {}
- local c = count
- local slots = {}
- if Items != nil then
- for i=1, #Items do
- if tonumber(Items[i].count) >= 20 then continue end
- if c <= 0 then break end
- local newcount = (20 - Items[i].count)
- if newcount >= c then newcount = c end
- if newcount != 0 and newcount > 0 then
- c = c - newcount
- slots[i] =
- {
- ['newcount'] = newcount,
- ['lastcount'] = tonumber(Items[i].count)
- }
- end
- end
- for k, count in pairs(slots) do
- sql.Query("UPDATE Inventory SET count = " .. (count['newcount'] + count['lastcount']) .. " WHERE SteamID = '" .. self:SteamID().."' AND class='"..class.."' AND count = "..(count['lastcount'])..";")
- print('Количество обновлено.')
- end
- while c > 0 do
- if c >= 20 then
- sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..(20).."');")
- c = c - 20
- else
- sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..c.."');")
- c = 0
- end
- print('Предмет добавлен в новый слот.')
- end
- else
- for i=1, math.Round(count / 20) do
- if c >= 20 then
- sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..(20).."');")
- c = c - 20
- else
- sql.Query("INSERT INTO Inventory VALUES( '"..self:SteamID().."', '"..type.."', '" ..class.. "', '"..c.."');")
- c = 0
- break
- end
- print('Предмет добавлен.')
- end
- end
- self:SaveInventory()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement