2013-11-17 03:03:31 +01:00
local deathListEnabled = true
local maxDeathRecords = 5
2013-07-07 02:30:08 +02:00
2023-04-29 03:40:33 -07:00
local function getKiller ( killer )
if not killer then
return false , " field item "
end
if killer : isPlayer ( ) then
return true , killer : getName ( )
end
local master = killer : getMaster ( )
if master and master ~= killer and master : isPlayer ( ) then
return true , master : getName ( )
end
return false , killer : getName ( )
end
2020-06-08 22:07:08 -03:00
function onDeath ( player , corpse , killer , mostDamageKiller , lastHitUnjustified , mostDamageUnjustified )
2015-02-08 15:37:46 +01:00
local playerId = player : getId ( )
2017-12-17 18:03:57 -02:00
if nextUseStaminaTime [ playerId ] then
2015-02-08 15:37:46 +01:00
nextUseStaminaTime [ playerId ] = nil
end
2014-03-27 12:09:04 +01:00
player : sendTextMessage ( MESSAGE_EVENT_ADVANCE , " You are dead. " )
2013-11-17 03:03:31 +01:00
2023-04-29 03:40:33 -07:00
local byPlayer , killerName = getKiller ( killer )
local byPlayerMostDamage , killerNameMostDamage = getKiller ( mostDamageKiller )
2013-07-09 05:13:39 +02:00
2023-12-14 15:08:52 -03:00
player : takeScreenshot ( byPlayer and SCREENSHOT_TYPE_DEATHPVP or SCREENSHOT_TYPE_DEATHPVE )
if byPlayer then
killer : takeScreenshot ( SCREENSHOT_TYPE_PLAYERKILL )
end
if mostDamageKiller and mostDamageKiller : isPlayer ( ) then
mostDamageKiller : takeScreenshot ( SCREENSHOT_TYPE_PLAYERKILL )
end
if not deathListEnabled then
return
end
2014-03-27 12:09:04 +01:00
local playerGuid = player : getGuid ( )
2023-04-29 03:40:33 -07:00
db.query ( " INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES ( " .. playerGuid .. " , " .. os.time ( ) .. " , " .. player : getLevel ( ) .. " , " .. db.escapeString ( killerName ) .. " , " .. ( byPlayer and 1 or 0 ) .. " , " .. db.escapeString ( killerNameMostDamage ) .. " , " .. ( byPlayerMostDamage and 1 or 0 ) .. " , " .. ( lastHitUnjustified and 1 or 0 ) .. " , " .. ( mostDamageUnjustified and 1 or 0 ) .. " ) " )
2014-03-27 12:09:04 +01:00
local resultId = db.storeQuery ( " SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. playerGuid )
2013-07-07 02:30:08 +02:00
2013-11-17 03:03:31 +01:00
local deathRecords = 0
local tmpResultId = resultId
2022-02-24 17:44:05 -03:00
while tmpResultId do
2013-11-17 03:03:31 +01:00
tmpResultId = result.next ( resultId )
deathRecords = deathRecords + 1
end
2013-07-07 02:30:08 +02:00
2022-02-24 17:44:05 -03:00
if resultId then
2013-11-17 03:03:31 +01:00
result.free ( resultId )
end
2013-07-09 05:13:39 +02:00
2014-12-04 18:28:08 +01:00
local limit = deathRecords - maxDeathRecords
if limit > 0 then
db.asyncQuery ( " DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit )
2013-11-17 03:03:31 +01:00
end
2013-07-07 02:30:08 +02:00
2023-04-29 03:40:33 -07:00
if byPlayer then
2014-11-03 19:42:40 +01:00
local targetGuild = player : getGuild ( )
targetGuild = targetGuild and targetGuild : getId ( ) or 0
2013-11-17 03:03:31 +01:00
if targetGuild ~= 0 then
2014-11-03 19:10:51 +01:00
local killerGuild = killer : getGuild ( )
2014-10-24 15:18:34 +02:00
killerGuild = killerGuild and killerGuild : getId ( ) or 0
2015-02-08 15:37:46 +01:00
if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar ( playerId , killer : getId ( ) ) then
2013-11-17 03:03:31 +01:00
local warId = false
resultId = db.storeQuery ( " SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. " ) OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. " )) " )
2022-02-24 17:44:05 -03:00
if resultId then
2019-10-14 19:28:33 -03:00
warId = result.getNumber ( resultId , " id " )
2013-11-17 03:03:31 +01:00
result.free ( resultId )
end
2013-07-07 02:30:08 +02:00
2022-02-24 17:44:05 -03:00
if warId then
2014-12-04 18:24:25 +01:00
db.asyncQuery ( " INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES ( " .. db.escapeString ( killerName ) .. " , " .. db.escapeString ( player : getName ( ) ) .. " , " .. killerGuild .. " , " .. targetGuild .. " , " .. os.time ( ) .. " , " .. warId .. " ) " )
2013-07-07 02:30:08 +02:00
end
end
end
end
end