Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function savereserve(char)
- nut.db.updateTable({
- _reserve = char:getReserve()
- }, nil, "reserve", "_charID = "..char:getID())
- end
- function SCHEMA:OnReserveChanged(char)
- savereserve(char)
- end
- do
- local MYSQL_CREATE_TABLES = [[
- CREATE TABLE IF NOT EXISTS `nut_reserve` (
- `_charID` int(11) NOT NULL,
- `_reserve` int(11) unsigned DEFAULT NULL,
- PRIMARY KEY (`_charID`)
- );
- ]]
- local SQLITE_CREATE_TABLES = [[
- CREATE TABLE IF NOT EXISTS `nut_reserve` (
- `_charID` INTEGER PRIMARY KEY,
- `_reserve` INTEGER
- );
- ]]
- function SCHEMA:OnLoadTables()
- if (nut.db.object) then
- -- This is needed to perform multiple queries since the string is only 1 big query.
- local queries = string.Explode(";", MYSQL_CREATE_TABLES)
- nut.db.query(queries[1])
- nut.db.query(queries[2])
- else
- nut.db.query(SQLITE_CREATE_TABLES)
- end
- end
- function SCHEMA:CharacterPreSave(char)
- savereserve(char)
- end
- function SCHEMA:CharacterLoaded(id)
- -- legacy support
- -- for modernRP users
- local char = nut.char.loaded[id]
- local legacy = false
- if (char:getData("reserve")) then
- local restore = char:getData("reserve", 0)
- char:setReserve(tonumber(restore))
- char:setData("reserve", nil)
- legacy = true
- end
- nut.db.query("SELECT _reserve FROM nut_reserve WHERE _charID = "..id, function(data)
- if (data and #data > 0) then
- for k, v in ipairs(data) do
- local money = tonumber(v._reserve)
- if (!legacy) then
- char:setReserve(money)
- end
- end
- else
- nut.db.insertTable({
- _reserve = 0,
- _charID = id,
- }, function(data)
- if (!legacy) then
- char:setReserve(0)
- end
- end, "reserve")
- end
- end)
- end
- function SCHEMA:PreCharDelete(client, char)
- nut.db.query("DELETE FROM nut_reserve WHERE _charID = "..char:getID())
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement