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

Heart of death player.

I dont understand you, maybe something like this :)

LUA:
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
local config = {
addItem = 1685 -- heart id
itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
if isPlayer(killer) == TRUE then
sex = getPlayerSex(cid)
if sex == 0 then
"she"
	else
"he"
	doPlayerAddItem(killer, config.addItem)
	doSetItemSpecialDescription(config.addItem, config.itemDesc)
				end
			end
		end
	return TRUE
end
 
Last edited:
It dont work for me,
Code:
[16/05/2009 11:52:31] luaDoPlayerAddItem(). Player not found
But i changed to lastKiller like a variable in function onDeath(something, something,lastKiller,something) and dont work. Why ?
 
PHP:
local config = {
	addItem = 1685, -- heart id
	itemDesc = {
		"You received this when you killed",
		-- Name
		"when", 
		-- Sex
		"was level"
		-- Level
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)	
	if isPlayer(killer) == TRUE then
		sex = getPlayerSex(cid)
	if sex == 0 then
		"she"
	else
		"he"
	end
	doPlayerAddItem(killer, config.addItem)
	doSetItemSpecialDescription(config.addItem, config.itemDesc[1].." "..getPlayerName(cid).." "..config.itemDesc[2].." "..sex.." "..config.itemDesc[3].." "..getPlayerLevel(cid)..".")

	return TRUE
end

rap++??
 
#up
no rep, because not working. :P

PHP:
local config = {
    addItem = 1685, -- heart id
    itemDesc = {
        "You received this when you killed",
        -- Name
        "when", 
        -- Sex
        "was level"
        -- Level
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)    
    if isPlayer(mostDamageKiller) == TRUE then
    if getPlayerSex(cid) == 0 then
        "she"
    else
        "he"
    end
    doPlayerAddItem(mostDamageKiller, config.addItem)
    doSetItemSpecialDescription(config.addItem, config.itemDesc[1].." "..getPlayerName(cid).." "..config.itemDesc[2].." "..sex.." "..config.itemDesc[3].." "..getPlayerLevel(cid)..".")

    return TRUE
end

it works!
 
I dont see problem with may :(

Try this again 1 word changed xD
LUA:
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
local config = {
addItem = 1685 -- heart id
itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
}
if isPlayer(killer) == TRUE then
sex = getPlayerSex(cid)
if sex == 0 then
"she"
	else
"he"
	doPlayerAddItem(killer, config.addItem)
	doSetItemSpecialDescription(config.addItem, config.itemDesc)
			end
		end
	return TRUE
end

or this
LUA:
function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
local config = {
	addItem = 1685 -- heart id
	itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
}
if isPlayer(killer) == TRUE then
sex = getPlayerSex(cid)
if sex == 0 then
	"she"
else
	"he"
end
	
	doPlayerAddItem(killer, config.addItem)
	doSetItemSpecialDescription(config.addItem, config.itemDesc)
		end
	return TRUE
end
 
Last edited:
It won't work Zonet, because:

if isPlayer(killer) == TRUE then
sex = getPlayerSex(cid)
if sex == 0 then
"she"
else
"he"
end

what is it? ;p She he? but what? maybe 'sex = "she"?
 
Integrated into playerdeath.lua For 0.3:
LUA:
local config = {
	deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
	sqlType = getConfigInfo('sqlType'),
	maxDeathRecords = getConfigInfo('maxDeathRecords')
	addItem = 1685 -- heart id
	itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
}

config.sqlType = config.sqlType == "sqlite" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL

function onDeath (cid, corpse, lastHitKiller, mostDamageKiller)
sex = 0
	if isPlayer(lastHitKiller) == TRUE then
		if getPlayerSex(cid) == 0 then
			sex = "she"
		else
			sex = "he"
		end
        doPlayerAddItem(lastHitKiller, config.addItem)
        doSetItemSpecialDescription(config.addItem, config.itemDesc)
        end
	
	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

And for 0.2:
LUA:
dofile("./config.lua")

local config = {
addItem = 1685 -- heart id
itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
}

function onDeath(cid, corpse, killer)
sex = 0
	if isPlayer(killer) == TRUE then
		if getPlayerSex(cid) == 0 then
			sex = "she"
		else
			sex = "he"
		end
        doPlayerAddItem(killer, config.addItem)
        doSetItemSpecialDescription(config.addItem, config.itemDesc)
        end
	
	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

Haven't tested either.
 
Last edited:
Zonet i dont try your second script coz Azi's script work in 50% ( im giving rep right now). Azi descripe dont work, killer is getting heart but hear with nothing. No erros in gui :(
 
Cykotitan, you need to read about scopes. You have declared the variables local within the if-statments scope and will not be available outside it. You have to declare the variable sex above the if-statement, and then redeclare it inside of the statements.
 
PHP:
local config = {
    addItem = 1685, -- heart id
    itemDesc = {
        "You received this when you killed",
        -- Name
        "when", 
        -- Sex
        "was level"
        -- Level
}

function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)    
    if isPlayer(mostDamageKiller) == TRUE then
    if getPlayerSex(cid) == 0 then
        sex = "she"
    else
        sex = "he"
    end
    doPlayerAddItem(mostDamageKiller, config.addItem)
    doSetItemSpecialDescription(config.addItem, config.itemDesc[1].." "..getPlayerName(cid).." "..config.itemDesc[2].." "..sex.." "..config.itemDesc[3].." "..getPlayerLevel(cid)..".")

    return TRUE
end
now should work! : )
 
Code:
[17/05/2009 16:46:30] [Warning - Event::loadScript] Can not load script (data/creaturescripts/scripts/2.lua)
[17/05/2009 16:46:30] data/creaturescripts/scripts/2.lua:12: '}' expected (to close '{' at line 1) near 'function'
And i wrote "}" after first "}".
Code:
[17/05/2009 16:46:43] [Warning - Event::loadScript] Can not load script (data/creaturescripts/scripts/2.lua)
[17/05/2009 16:46:43] data/creaturescripts/scripts/2.lua:24: 'end' expected (to close 'function' at line 13) near '<eof>'
And i wrote end before "return true"
And now i have :
Code:
[17/05/2009 16:48:34] Lua Script Error: [CreatureScript Interface] 
[17/05/2009 16:48:34] data/creaturescripts/scripts/2.lua:onDeath

[17/05/2009 16:48:34] luaDoSetItemSpecialDescription(). Item not found
And i cant remake this script : /
Please :D I will give rep's for all replys in this thread for fix this and make heart pillow create in death corpse.
 
It won't work Zonet, because:

if isPlayer(killer) == TRUE then
sex = getPlayerSex(cid)
if sex == 0 then
"she"
else
"he"
end

what is it? ;p She he? but what? maybe 'sex = "she"?

I dont understand you, but he try this
LUA:
  function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
local config = {
        addItem = 1685 -- heart id
        itemDesc = "You received this when you killed "..getPlayerName(cid).." when "..sex.." was level ["..getPlayerLevel(cid).."]."
}
sex = getPlayerSex(cid)
if sex == 0 then
        "she"
else
        "he"
end
if isPlayer(mostDamageKiller) == TRUE then
        doPlayerAddItem(mostDamageKiller, config.addItem)
        doSetItemSpecialDescription(config.addItem, config.itemDesc)
		end
    return TRUE
end
 
Zonet please try to :
Code:
if getPlayerSex(cid) == 0 then
  sex = "she"
else
  sex = "he"
end
And try to make work with item create in corpse, not give to killer.
Pl : Spróbuj zrobić, żeby dodawało item do zwłok, nie dla mordercy.
 
Back
Top