• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

bug with playerdeath.lua :s Help please

Serginov

Onkonkoronkonk
Joined
Jun 28, 2008
Messages
1,321
Reaction score
18
Location
Sweden - Dalarna
Hello :p

When someone dies on my Open Tibia server this error comes up in the server console:
PHP:
29/12/2008 15:35:20] Lua Script Error: [CreatureScript Interface] 
[29/12/2008 15:35:20] data/creaturescripts/scripts/playerdeath.lua:onDeath

[29/12/2008 15:35:20] data/creaturescripts/scripts/playerdeath.lua:7: attempt to index global 'luasql' (a nil value)
[29/12/2008 15:35:20] stack traceback:
[29/12/2008 15:35:20]     data/creaturescripts/scripts/playerdeath.lua:7: in function <data/creaturescripts/scripts/playerdeath.lua:3>


and it doesn't register the death in phpmyadmin: player_deaths.
So on my website it just says Noone has died

This is my playerdeath.lua script:
PHP:
dofile("./config.lua")

function onDeath(cid, corpse, killer)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You are dead.")
    if deathListEnabled == "yes" then
        if sqlType == "mysql" then
            env = assert(luasql.mysql())
            con = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))
        else -- sqlite
            env = assert(luasql.sqlite3())
            con = assert(env:connect(sqliteDatabase))
        end
        local byPlayer = FALSE
        if killer == FALSE then
            killerName = "field item"
        else
            if isPlayer(killer) == TRUE then
                byPlayer = TRUE
            end
            killerName = getCreatureName(killer)
        end
        assert(con:execute("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", '" .. escapeString(killerName) .. "', " .. byPlayer .. ");"))
        local cursor = assert(con:execute("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";"))
        local deathRecords = numRows(cursor)
        if sqlType == "mysql" then
            while deathRecords > maxDeathRecords do
                delete = assert(con:execute("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1;"))
                deathRecords = deathRecords - 1
            end
        else
            while deathRecords > maxDeathRecords do
                delete = assert(con:execute("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);"))
                deathRecords = deathRecords - 1
            end
        end            
        con:close()
        env:close()
    end
end

and:
PHP:
    <event type="death" name="PlayerDeath" script="playerdeath.lua"/>

EDIT: I use TFS 0.3 Alpha 4

Can someone help me?



Thanks in advance
 
Last edited:
Code:
local config = {
	deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
	sqlType = getConfigInfo('sqlType'),
	maxDeathRecords = getConfigInfo('maxDeathRecords')
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
	if(config.deathListEnabled == TRUE) then
		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.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) .. ");")
		local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
		if(rows:getID() ~= -1) then
			local amount = (rows:numRows(true) - config.maxDeathRecords)
			if(amount > 0) then
				if(config.sqlType == "sqlite") then
					for i = 1, amount do
						db.executeQuery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
					end
				else
					db.executeQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
				end
			end
		end
	end
end

Try this, it's from my TFS.
 
I get an error :/
PHP:
[29/12/2008 23:27:52] data/creaturescripts/scripts/playerdeath.lua:2: attempt to call global 'getBooleanFromString' (a nil value)
[29/12/2008 23:27:52] Warning: [Event::loadScript] Can not load script. data/creaturescripts/scripts/playerdeath.lua
 
Back
Top