• 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!

Solved Players lose their skills on logout/death

bubblanfranck

New Member
Joined
Jun 17, 2011
Messages
51
Reaction score
1
Location
Sweden
Anyone got a solution how to fix this problem? my players lose their skills if they logout or die.
it's only they lose all skills except the magic level!
i also get this error in my console:
[10/06/2017 23:12:56] [Error - CreatureScript Interface]
[10/06/2017 23:12:56] data/creaturescripts/scripts/playerdeath.lua:eek:nDeath
[10/06/2017 23:12:56] Description:
[10/06/2017 23:12:56] data/creaturescripts/scripts/playerdeath.lua:32: attempt to call field 'Query' (a nil value)
[10/06/2017 23:12:56] stack traceback:
[10/06/2017 23:12:56] data/creaturescripts/scripts/playerdeath.lua:32: in function <data/creaturescripts/scripts/playerdeath.lua:9>

C++:
local config = {
    deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
    sqlType = getConfigInfo('sqlType'),
    maxDeathRecords = getConfigInfo('maxDeathRecords')
}
config.sqlType = config.sqlType == "mysql" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
    if(config.deathListEnabled ~= TRUE) then
        return
    end
    local hitKillerName = "field item"
    local damageKillerName = ""
    if(lastHitKiller ~= FALSE) then
        if(isPlayer(lastHitKiller) == TRUE) then
            hitKillerName = getPlayerGUID(lastHitKiller)
        else
            hitKillerName = getCreatureName(lastHitKiller)
        end
        if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
            if(isPlayer(mostDamageKiller) == TRUE) then
                damageKillerName = getPlayerGUID(mostDamageKiller)
            else
                damageKillerName = getCreatureName(mostDamageKiller)
            end
        end
    end
    db.Query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")
    local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
    if(rows:getID() ~= -1) then
        local amount = rows:getRows(true) - config.maxDeathRecords
        if(amount > 0) then
            if(config.sqlType == DATABASE_ENGINE_SQLITE) then
                for i = 1, amount do
                    db.Query("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
                end
            else
                db.Query("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
            end
        end
    end
end
 
Solution
Try changing this line

Code:
db.Query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

With one of these.

Code:
db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

or

Code:
db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" ...
Try changing this line

Code:
db.Query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

With one of these.

Code:
db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

or

Code:
db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

or

Code:
db.storeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

So it will be one of these: db.query, db.storeQuery, db.executeQuery

Which ever one works you will want to replace all of the db.Query with.
 
Solution
still doesnt seem to work, getting this error in the console now while using the last one u send.
mysql_real_query(): INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (24, 1497132206, 44, '', ''); - MYSQL ERROR: Unknown column 'killed_by' in 'field list' (1054)

and still this one:
[11/06/2017 00:03:26] [Error - CreatureScript Interface]
[11/06/2017 00:03:26] data/creaturescripts/scripts/playerdeath.lua:eek:nDeath
[11/06/2017 00:03:26] Description:
[11/06/2017 00:03:26] data/creaturescripts/scripts/playerdeath.lua:39: attempt to call field 'Query' (a nil value)
[11/06/2017 00:03:26] stack traceback:
[11/06/2017 00:03:26] data/creaturescripts/scripts/playerdeath.lua:39: in function <data/creaturescripts/scripts/playerdeath.lua:9>

I've never had this problem before, i had my server running as a beta few days ago and there was nothing wrong with it then , but it might have something to do with the database change :s
 
Last edited by a moderator:
That error is saying: In your database in the table player_deaths there is no column or value name killed_by.....To fix that you can add a new column in that table...

Name it: killed_by
Make it: varchar(11)

You will probably have to do the same with: altkilled_by
 
Last edited by a moderator:
Added that and now i dont get the error in the console anymore, but people still losing all the skills down to 10 when logout :/

Problem solved!!
For those of you with the same error, use one of the codes Itutorial sent above. for me it worked with!

db.storeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")

Then i found this one that made everything work again >Recover default player skills [Gesior]
 
Last edited by a moderator:
Back
Top