• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Lost Database Connection(?) - Players Can't LOG IN/OUT - CAN'T SAVE THEM

Gabriel Tibiano

New Member
Joined
Nov 21, 2009
Messages
420
Reaction score
4
Hey!
My server is returning this error and when i get this (usually 4 to 4 hours), players can't log in or out, i can't execute save, my connection to database just get lost(?), but xampp still running and website is perfectly working (accounts can log in and log out).
I dont know, i really need your help guys,


oZ8Ka.png



exp_worst.lua
Lua:
function onLogout(cid)
local play = db.getResult("SELECT * FROM `players` WHERE `id` = ".. getPlayerGUID(cid) ..";")
local exp_today = (getPlayerExperience(cid)-(play:getDataInt("exphist_lastexp"))) 
if (exp_today < (play:getDataInt("exp_worst"))) then
db.executeQuery("UPDATE `players` SET `exp_worst` = " .. exp_today .. ", `expw_data`=" .. os.time() .. ", `expw_lv`=" .. getPlayerLevel(cid) .. " WHERE `id` = '" .. getPlayerGUID(cid) .. "';")
end  
return true
end

exp_record.lua
Lua:
function onLogout(cid)
local play = db.getResult("SELECT * FROM `players` WHERE `id` = ".. getPlayerGUID(cid) ..";")
local exp_today = math.max((getPlayerExperience(cid)-(play:getDataInt("exphist_lastexp"))),(play:getDataInt("exphist1")),(play:getDataInt("exphist2")))  

if (exp_today - (play:getDataInt("exp_record"))) > 0 then
db.executeQuery("UPDATE `players` SET `exp_record` = " .. exp_today .. ", `expr_data`=" .. os.time() .. ", `expr_lv`=" .. getPlayerLevel(cid) .. " WHERE `id` = '" .. getPlayerGUID(cid) .. "';")
end  
return true
end

004-database.lua
Lua:
if(result == nil) then
    print("> WARNING: Couldn't load database lib.")
    return
end

Result = createClass(nil)
Result:setAttributes({
    id = -1,
    query = ""
})

function Result:getID()
    return self.id
end

function Result:setID(_id)
    self.id = _id
end

function Result:getQuery()
    return self.query
end

function Result:setQuery(_query)
    self.query = _query
end

function Result:create(_query)
    self:setQuery(_query)
    local _id = db.storeQuery(self:getQuery())
    if(_id) then
        self:setID(_id)
    end

    return self:getID()
end

function Result:getRows(free)
    local free = free or false
    if(self:getID() == -1) then
        error("[Result:getRows] Result not set!")
    end

    local c = 0
    repeat
        c = c + 1
    until not self:next()

    local _query = self:getQuery()
    self:free()
    if(not free) then
        self:create(_query)
    end

    return c
end

function Result:getDataInt(s)
    if(self:getID() == -1) then
        error("[Result:getDataInt] Result not set!")
    end

    return result.getDataInt(self:getID(), s)
end

function Result:getDataLong(s)
    if(self:getID() == -1) then
        error("[Result:getDataLong] Result not set!")
    end

    return result.getDataLong(self:getID(), s)
end

function Result:getDataString(s)
    if(self:getID() == -1) then
        error("[Result:getDataString] Result not set!")
    end

    return result.getDataString(self:getID(), s)
end

function Result:getDataStream(s)
    if(self:getID() == -1) then
        error("[Result:getDataStream] Result not set!")
    end

    return result.getDataStream(self:getID(), s)
end

function Result:next()
    if(self:getID() == -1) then
        error("[Result:next] Result not set!")
    end

    return result.next(self:getID())
end

function Result:free()
    if(self:getID() == -1) then
        error("[Result:free] Result not set!")
    end

    self:setQuery("")
    local ret = result.free(self:getID())
    self:setID(-1)
    return ret
end

Result.numRows = Result.getRows
function db.getResult(query)
    if(type(query) ~= 'string') then
        return nil
    end

    local ret = Result:new()
    ret:create(query)
    return ret
end
 
Back
Top