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

TFS 0.3.4 when player die!

Swimmi

♥Inactive♥
Joined
Jan 15, 2008
Messages
791
Reaction score
2
Location
Germany
hey i get this error when a player go ded...

Code:
[23/07/2009 03:31:29] Lua Script Error: [CreatureScript Interface] 
[23/07/2009 03:31:29] data/creaturescripts/scripts/playerdeath.lua:onDeath

[23/07/2009 03:31:29] data/creaturescripts/scripts/playerdeath.lua:7: attempt to index global 'luasql' (a nil value)
[23/07/2009 03:31:29] stack traceback:
[23/07/2009 03:31:29] 	data/creaturescripts/scripts/playerdeath.lua:7: in function <data/creaturescripts/scripts/playerdeath.lua:3>

here is my playerdeath.lua

Code:
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
any can help me :(??? rep ofc!
 
You are using playerdeath.lua script from 0.2 in your 0.3 server. LuaSQL was removed from 0.3

Take the playerdeath script from the thread TFS 0.3.4 Patch 2 from Elf. I cant copy you the link, Im on the iPod...


Regards.
 
i use the playerdeath.lua from tfs 0.3.4 and get this error again....but not so much :D!!

Code:
[23/07/2009 14:28:20] Lua Script Error: [CreatureScript Interface] 
[23/07/2009 14:28:20] data/creaturescripts/scripts/playerdeath.lua:onDeath

[23/07/2009 14:28:20] luaGetCreatureName(). Creature not found

[23/07/2009 14:28:20] Lua Script Error: [CreatureScript Interface] 
[23/07/2009 14:28:20] data/creaturescripts/scripts/playerdeath.lua:onDeath

[23/07/2009 14:28:20] luaGetCreatureName(). Creature not found
 
Last edited:
playerdeath.lua:
Lua:
local config = {
	deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
	sqlType = getConfigInfo('sqlType'),
	maxDeathRecords = getConfigInfo('maxDeathRecords')
}

config.sqlType = config.sqlType == "sqlite" 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.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:getRows(true) - config.maxDeathRecords
		if(amount > 0) then
			if(config.sqlType == DATABASE_ENGINE_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

In creaturescripts.xml:
Lua:
<event type="death" name="PlayerDeath" event="script" value="playerdeath.lua"/>

In login.lua, below another registerCreatureEvent:
Lua:
registerCreatureEvent(cid, "PlayerDeath")

It must work LoL. I'm using TFS 0.3.4PL2 too and I don't get any error when I die.
 
Back
Top