Ir para conteúdo
  • Cadastre-se

(Resolvido)Talkaction Deathlist [TFS1.X]


Ir para solução Resolvido por Snowsz,

Posts Recomendados

Boa tarde. Venho tentando já há algum tempo modificar o meu script de Deathlist para que apareçam os nomes de vários players que participaram na Kill.

 

PS: Uso TFS 1.2

 

Atualmente, só o player que fraggou a kill (apenas um dos players entre o que deu mais dano e o que deu o ultimo hit, sendo aleatório qual deles) aparece. Gostaria de mudar isso para que aparecessem vários nomes, mas sem que todos fraggem.

 

Agradeço desde já. Vou deixar meu deathlist aqui, juntamente com o playerdeath.lua

 

 

 

local function getArticle(str)
	return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
end

local function getMonthDayEnding(day)
	if day == "01" or day == "21" or day == "31" then
		return "st"
	elseif day == "02" or day == "22" then
		return "nd"
	elseif day == "03" or day == "23" then
		return "rd"
	else
		return "th"
	end
end

local function getMonthString(m)
	return os.date("%B", os.time{year = 1970, month = m, day = 1})
end

function onSay(player, words, param)
	local resultId = db.storeQuery("SELECT `id`, `name` FROM `players` WHERE `name` = " .. db.escapeString(param))
	if resultId ~= false then
		local targetGUID = result.getNumber(resultId, "id")
		local targetName = result.getString(resultId, "name")
		result.free(resultId)
		local str = ""
		local breakline = ""

		local resultId = db.storeQuery("SELECT `time`, `level`, `killed_by`, `is_player` FROM `player_deaths` WHERE `player_id` = " .. targetGUID .. " ORDER BY `time` DESC")
		if resultId ~= false then
			repeat
				if str ~= "" then
					breakline = "\n"
				end
				local date = os.date("*t", result.getNumber(resultId, "time"))

				local article = ""
				local killed_by = result.getString(resultId, "killed_by")
				if result.getNumber(resultId, "is_player") == 0 then
					article = getArticle(killed_by) .. " "
					killed_by = killed_by:lower()
				end

				if date.day < 10 then date.day = "0" .. date.day end
				if date.hour < 10 then date.hour = "0" .. date.hour end
				if date.min < 10 then date.min = "0" .. date.min end
				if date.sec < 10 then date.sec = "0" .. date.sec end
				str = str .. breakline .. " " .. date.day .. getMonthDayEnding(date.day) .. " " .. getMonthString(date.month) .. " " .. date.year .. " " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. "   Morto no Level " .. result.getNumber(resultId, "level") .. " por "  .. killed_by .. "."
			until not result.next(resultId)
			result.free(resultId)
		end

		if str == "" then
			str = "Sem mortes."
		end
		player:popupFYI("Mortes do personagem, " .. targetName .. ".\n\n" .. str)
	else
		player:sendCancelMessage("O jogador com esse nome não existe.")
	end
	return false
end

 

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
	local playerId = player:getId()
	if nextUseStaminaTime[playerId] ~= nil then
		nextUseStaminaTime[playerId] = nil
	end

	player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
		player:removeBlessing(6)
	player:removeBlessing(7)

	if not deathListEnabled then
		return
	end

	local byPlayer = 0
	local killerName
	local killerid
	if killer ~= nil then
		if killer:isPlayer() then
		   killerid = killer:getGuid()
			byPlayer = 1
		else
			local master = killer:getMaster()
			if master and master ~= killer and master:isPlayer() then
				killer = master
				killerid = killer:getGuid()
				byPlayer = 1
			end
		end
		killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
	else
		killerName = 'field item'
	end

	local byPlayerMostDamage = 0
	local mostDamageKillerName
	if mostDamageKiller ~= nil then
		if mostDamageKiller:isPlayer() then
			byPlayerMostDamage = 1
		else
			local master = mostDamageKiller:getMaster()
			if master and master ~= mostDamageKiller and master:isPlayer() then
				mostDamageKiller = master
				byPlayerMostDamage = 1
			end
		end
		mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
	else
		mostDamageName = 'field item'
	end

	local playerGuid = player:getGuid()
	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 .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ')')
	local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)

	local deathRecords = 0
	local tmpResultId = resultId
	while tmpResultId ~= false do
		tmpResultId = result.next(resultId)
		deathRecords = deathRecords + 1
	end

	if resultId ~= false then
		result.free(resultId)
	end

	local limit = deathRecords - maxDeathRecords
	if limit > 0 then
		db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
	end

	if byPlayer == 1 then

		local targetGuild = player:getGuild()
		targetGuild = targetGuild and targetGuild:getId() or 0
		if targetGuild ~= 0 then
			local killerGuild = killer:getGuild()
			killerGuild = killerGuild and killerGuild:getId() or 0
			if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
				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 .. '))')
				if resultId ~= false then
					warId = result.getNumber(resultId, 'id')
					result.free(resultId)
				end

				if warId ~= false then
					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 .. ')')
				end
			end
		end
	end
end

 

Como aparece atualmente:

 

 Tibia_2019-09-01_15-57-04.png.c1af062964c3af449317178aa8b6fe7f.png

 

 

Editado por MatCollier (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Execute isso no MySQL:

ALTER TABLE player_deaths ADD player_killers TEXT NOT NULL

 

Talkaction:

local function getArticle(str)
	return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
end

local function getMonthDayEnding(day)
	if day == "01" or day == "21" or day == "31" then
		return "st"
	elseif day == "02" or day == "22" then
		return "nd"
	elseif day == "03" or day == "23" then
		return "rd"
	else
		return "th"
	end
end

local function getMonthString(m)
	return os.date("%B", os.time{year = 1970, month = m, day = 1})
end

function onSay(player, words, param)
	local resultId = db.storeQuery("SELECT `id`, `name` FROM `players` WHERE `name` = " .. db.escapeString(param))
	if resultId ~= false then
		local targetGUID = result.getNumber(resultId, "id")
		local targetName = result.getString(resultId, "name")
		result.free(resultId)
		local str = ""
		local breakline = ""

		local resultId = db.storeQuery("SELECT `time`, `level`, `killed_by`, `is_player`, `player_killers` FROM `player_deaths` WHERE `player_id` = " .. targetGUID .. " ORDER BY `time` DESC")
		if resultId ~= false then
			repeat
				if str ~= "" then
					breakline = "\n"
				end
				local date = os.date("*t", result.getNumber(resultId, "time"))

				local article = ""
				local killed_by = result.getString(resultId, "killed_by")
				if result.getNumber(resultId, "is_player") == 0 then
					article = getArticle(killed_by) .. " "
					killed_by = killed_by:lower()
				end
                local killers = (result.getString(resultId, "player_killers") or ""):gsub(";", ", ")
                killers = killers:sub(1, #killers-2)

				if date.day < 10 then date.day = "0" .. date.day end
				if date.hour < 10 then date.hour = "0" .. date.hour end
				if date.min < 10 then date.min = "0" .. date.min end
				if date.sec < 10 then date.sec = "0" .. date.sec end
				str = str .. breakline .. " " .. date.day .. getMonthDayEnding(date.day) .. " " .. getMonthString(date.month) .. " " .. date.year .. " " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. "   Morto no Level " .. result.getNumber(resultId, "level") .. " por "  .. killers .. "."
			until not result.next(resultId)
			result.free(resultId)
		end

		if str == "" then
			str = "Sem mortes."
		end
		player:popupFYI("Mortes do personagem, " .. targetName .. ".\n\n" .. str)
	else
		player:sendCancelMessage("O jogador com esse nome não existe.")
	end
	return false
end

 

Creaturescript:

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
	local playerId = player:getId()
	if nextUseStaminaTime[playerId] ~= nil then
		nextUseStaminaTime[playerId] = nil
	end

	player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
		player:removeBlessing(6)
	player:removeBlessing(7)

	if not deathListEnabled then
		return
	end

	local byPlayer = 0
	local killerName
	local killerid
	if killer ~= nil then
		if killer:isPlayer() then
		   killerid = killer:getGuid()
			byPlayer = 1
		else
			local master = killer:getMaster()
			if master and master ~= killer and master:isPlayer() then
				killer = master
				killerid = killer:getGuid()
				byPlayer = 1
			end
		end
		killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
	else
		killerName = 'field item'
	end

	local byPlayerMostDamage = 0
	local mostDamageKillerName
	if mostDamageKiller ~= nil then
		if mostDamageKiller:isPlayer() then
			byPlayerMostDamage = 1
		else
			local master = mostDamageKiller:getMaster()
			if master and master ~= mostDamageKiller and master:isPlayer() then
				mostDamageKiller = master
				byPlayerMostDamage = 1
			end
		end
		mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
	else
		mostDamageName = 'field item'
	end


    local KillersArray = {}
    for k, v in pairs(player:getDamageMap()) do
        local CreatureMT = Creature(k)
        if CreatureMT and CreatureMT:isPlayer() then
            table.insert(KillersArray, v:getName())
        end
    end
	local playerGuid = player:getGuid()
	db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`, `player_killers`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ', ' .. table.concat(KillersArray, ";") .. ')')
	local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)

	local deathRecords = 0
	local tmpResultId = resultId
	while tmpResultId ~= false do
		tmpResultId = result.next(resultId)
		deathRecords = deathRecords + 1
	end

	if resultId ~= false then
		result.free(resultId)
	end

	local limit = deathRecords - maxDeathRecords
	if limit > 0 then
		db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
	end

	if byPlayer == 1 then

		local targetGuild = player:getGuild()
		targetGuild = targetGuild and targetGuild:getId() or 0
		if targetGuild ~= 0 then
			local killerGuild = killer:getGuild()
			killerGuild = killerGuild and killerGuild:getId() or 0
			if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
				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 .. '))')
				if resultId ~= false then
					warId = result.getNumber(resultId, 'id')
					result.free(resultId)
				end

				if warId ~= false then
					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 .. ')')
				end
			end
		end
	end
end

 

 

Não testei então tenta aí.

A identação saiu meio bugada umas partes mas não importa.

                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

Primeiramente, agradeço MUITO pela disposição em ajudar, faz dias que tento resolver isso sem sucesso. Acabei de testar, algo não deu certo:

 

Não entendo suficiente pra corrigir sozinho essa parte.

theforgottenserver_2019-09-01_16-32-00.thumb.png.d33836ef2e91c9e3e7cb789b9bd61ded.png

 

EDIT:  Fiz uma alteração na linha 60 do playerdeath.lua em creaturescripts, mudei v:getName para CreatureMT:getName.

 

ficou assim: 

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
	local playerId = player:getId()
	if nextUseStaminaTime[playerId] ~= nil then
		nextUseStaminaTime[playerId] = nil
	end

	player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
		player:removeBlessing(6)
	player:removeBlessing(7)

	if not deathListEnabled then
		return
	end

	local byPlayer = 0
	local killerName
	local killerid
	if killer ~= nil then
		if killer:isPlayer() then
		   killerid = killer:getGuid()
			byPlayer = 1
		else
			local master = killer:getMaster()
			if master and master ~= killer and master:isPlayer() then
				killer = master
				killerid = killer:getGuid()
				byPlayer = 1
			end
		end
		killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
	else
		killerName = 'field item'
	end

	local byPlayerMostDamage = 0
	local mostDamageKillerName
	if mostDamageKiller ~= nil then
		if mostDamageKiller:isPlayer() then
			byPlayerMostDamage = 1
		else
			local master = mostDamageKiller:getMaster()
			if master and master ~= mostDamageKiller and master:isPlayer() then
				mostDamageKiller = master
				byPlayerMostDamage = 1
			end
		end
		mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
	else
		mostDamageName = 'field item'
	end


    local KillersArray = {}
    for k, v in pairs(player:getDamageMap()) do
        local CreatureMT = Creature(k)
        if CreatureMT and CreatureMT:isPlayer() then
            table.insert(KillersArray, CreatureMT:getName())
        end
    end
	local playerGuid = player:getGuid()
	db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`, `player_killers`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ', ' .. table.concat(KillersArray, ";") .. ')')
	local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)

	local deathRecords = 0
	local tmpResultId = resultId
	while tmpResultId ~= false do
		tmpResultId = result.next(resultId)
		deathRecords = deathRecords + 1
	end

	if resultId ~= false then
		result.free(resultId)
	end

	local limit = deathRecords - maxDeathRecords
	if limit > 0 then
		db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
	end

	if byPlayer == 1 then

		local targetGuild = player:getGuild()
		targetGuild = targetGuild and targetGuild:getId() or 0
		if targetGuild ~= 0 then
			local killerGuild = killer:getGuild()
			killerGuild = killerGuild and killerGuild:getId() or 0
			if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
				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 .. '))')
				if resultId ~= false then
					warId = result.getNumber(resultId, 'id')
					result.free(resultId)
				end

				if warId ~= false then
					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 .. ')')
				end
			end
		end
	end
end

 

 

Mas agora deu esse erro: 

theforgottenserver_2019-09-01_16-50-03.thumb.png.577dc1d3417798e25fc7e1674e1ceb62.png

Editado por MatCollier (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Erro meu kkk, fez bem em mudar lá, tenta agora:

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end
    
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
    player:removeBlessing(6)
    player:removeBlessing(7)
    
    if not deathListEnabled then
        return
    end
    
    local byPlayer = 0
    local killerName
    local killerid
    if killer ~= nil then
        if killer:isPlayer() then
            killerid = killer:getGuid()
            byPlayer = 1
        else
            local master = killer:getMaster()
            if master and master ~= killer and master:isPlayer() then
                killer = master
                killerid = killer:getGuid()
                byPlayer = 1
            end
        end
        killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
    else
        killerName = 'field item'
    end
    
    local byPlayerMostDamage = 0
    local mostDamageKillerName
    if mostDamageKiller ~= nil then
        if mostDamageKiller:isPlayer() then
            byPlayerMostDamage = 1
        else
            local master = mostDamageKiller:getMaster()
            if master and master ~= mostDamageKiller and master:isPlayer() then
                mostDamageKiller = master
                byPlayerMostDamage = 1
            end
        end
        mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
    else
        mostDamageName = 'field item'
    end
    
    
    local KillersArray = {}
    for k, v in pairs(player:getDamageMap()) do
        local CreatureMT = Creature(k)
        if CreatureMT and CreatureMT:isPlayer() then
            table.insert(KillersArray, CreatureMT:getName())
        end
    end
    local playerGuid = player:getGuid()
    db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`, `player_killers`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ', \"' .. table.concat(KillersArray, ";") .. '\")')
    local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)
    
    local deathRecords = 0
    local tmpResultId = resultId
    while tmpResultId ~= false do
        tmpResultId = result.next(resultId)
        deathRecords = deathRecords + 1
    end
    
    if resultId ~= false then
        result.free(resultId)
    end
    
    local limit = deathRecords - maxDeathRecords
    if limit > 0 then
        db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
    end
    
    if byPlayer == 1 then
        
        local targetGuild = player:getGuild()
        targetGuild = targetGuild and targetGuild:getId() or 0
        if targetGuild ~= 0 then
            local killerGuild = killer:getGuild()
            killerGuild = killerGuild and killerGuild:getId() or 0
            if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
                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 .. '))')
                if resultId ~= false then
                    warId = result.getNumber(resultId, 'id')
                    result.free(resultId)
                end
                
                if warId ~= false then
                    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 .. ')')
                end
            end
        end
    end
end

 

                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

Deu certo! Só tem 2 pequenos poréns:

 

1: Ele está cortando as 2 últimas letras no final (exemplo: em vez de "Morto por Lista, Teste.", fica "Morto por Lista, Tes.")

 

2: Quando morre pra monstro não aparece o nome dos monstros, fica só o ponto (aquela última morte level 102 foi pra um Dragon e um Dragon Lord).

 

Tibia_2019-09-01_17-21-01.png.cdbc4ed3aba1e9a752d1da8b53417222.png

Link para o post
Compartilhar em outros sites

Pensei que só queria de player kkk, sobre cortar 2 letras, é falta de prática minha, mesmo mexendo com isso todo dia, me sinto enferrujado sempre, isso deve resolver:

 

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end
    
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
    player:removeBlessing(6)
    player:removeBlessing(7)
    
    if not deathListEnabled then
        return
    end
    
    local byPlayer = 0
    local killerName
    local killerid
    if killer ~= nil then
        if killer:isPlayer() then
            killerid = killer:getGuid()
            byPlayer = 1
        else
            local master = killer:getMaster()
            if master and master ~= killer and master:isPlayer() then
                killer = master
                killerid = killer:getGuid()
                byPlayer = 1
            end
        end
        killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
    else
        killerName = 'field item'
    end
    
    local byPlayerMostDamage = 0
    local mostDamageKillerName
    if mostDamageKiller ~= nil then
        if mostDamageKiller:isPlayer() then
            byPlayerMostDamage = 1
        else
            local master = mostDamageKiller:getMaster()
            if master and master ~= mostDamageKiller and master:isPlayer() then
                mostDamageKiller = master
                byPlayerMostDamage = 1
            end
        end
        mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
    else
        mostDamageName = 'field item'
    end
    
    
    local KillersArray = {}
    for k, v in pairs(player:getDamageMap()) do
        local CreatureMT = Creature(k)
        if CreatureMT then
            table.insert(KillersArray, CreatureMT:getName())
        end
    end
    local playerGuid = player:getGuid()
    db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`, `player_killers`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ', \"' .. table.concat(KillersArray, ";") .. '\")')
    local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)
    
    local deathRecords = 0
    local tmpResultId = resultId
    while tmpResultId ~= false do
        tmpResultId = result.next(resultId)
        deathRecords = deathRecords + 1
    end
    
    if resultId ~= false then
        result.free(resultId)
    end
    
    local limit = deathRecords - maxDeathRecords
    if limit > 0 then
        db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
    end
    
    if byPlayer == 1 then
        
        local targetGuild = player:getGuild()
        targetGuild = targetGuild and targetGuild:getId() or 0
        if targetGuild ~= 0 then
            local killerGuild = killer:getGuild()
            killerGuild = killerGuild and killerGuild:getId() or 0
            if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
                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 .. '))')
                if resultId ~= false then
                    warId = result.getNumber(resultId, 'id')
                    result.free(resultId)
                end
                
                if warId ~= false then
                    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 .. ')')
                end
            end
        end
    end
end

Talk:

local function getArticle(str)
    return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
end

local function getMonthDayEnding(day)
    if day == "01" or day == "21" or day == "31" then
        return "st"
    elseif day == "02" or day == "22" then
        return "nd"
    elseif day == "03" or day == "23" then
        return "rd"
    else
        return "th"
    end
end

local function getMonthString(m)
    return os.date("%B", os.time{year = 1970, month = m, day = 1})
end

function onSay(player, words, param)
    local resultId = db.storeQuery("SELECT `id`, `name` FROM `players` WHERE `name` = " .. db.escapeString(param))
    if resultId ~= false then
        local targetGUID = result.getNumber(resultId, "id")
        local targetName = result.getString(resultId, "name")
        result.free(resultId)
        local str = ""
        local breakline = ""
        
        local resultId = db.storeQuery("SELECT `time`, `level`, `killed_by`, `is_player`, `player_killers` FROM `player_deaths` WHERE `player_id` = " .. targetGUID .. " ORDER BY `time` DESC")
        if resultId ~= false then
            repeat
                if str ~= "" then
                    breakline = "\n"
                end
                local date = os.date("*t", result.getNumber(resultId, "time"))
                
                local article = ""
                local killed_by = result.getString(resultId, "killed_by")
                if result.getNumber(resultId, "is_player") == 0 then
                    article = getArticle(killed_by) .. " "
                    killed_by = killed_by:lower()
                end
                local killers = (result.getString(resultId, "player_killers") or ""):gsub(";", ", ")
                
                if date.day < 10 then date.day = "0" .. date.day end
                if date.hour < 10 then date.hour = "0" .. date.hour end
                if date.min < 10 then date.min = "0" .. date.min end
                if date.sec < 10 then date.sec = "0" .. date.sec end
                str = str .. breakline .. " " .. date.day .. getMonthDayEnding(date.day) .. " " .. getMonthString(date.month) .. " " .. date.year .. " " .. date.hour .. ":" .. date.min .. ":" .. date.sec .. " Morto no Level " .. result.getNumber(resultId, "level") .. " por " .. killers .. "."
            until not result.next(resultId)
            result.free(resultId)
        end
        
        if str == "" then
            str = "Sem mortes."
        end
        player:popupFYI("Mortes do personagem, " .. targetName .. ".\n\n" .. str)
    else
        player:sendCancelMessage("O jogador com esse nome não existe.")
    end
    return false
end

 

                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

Cara, muito muito muito muito obrigado mesmo! Ajudou demais!!!!

 

Dois pequenos detalhes, aproveitando:

 

Seria possível colocar pra não repetir o nome? Exemplo: 

Pra aparecer Dragon 1x só.

Tibia_2019-09-01_17-42-01.thumb.png.14b3c0e0d2c25816bc9904f012466a6f.png

 

E por fim, vc saberia como fazer pra colocar um "últimas mortes" no site? Eu uso MySQL/Apache. 

Link para o post
Compartilhar em outros sites
  • Solução
2 minutos atrás, MatCollier disse:

Cara, muito muito muito muito obrigado mesmo! Ajudou demais!!!!

 

Dois pequenos detalhes, aproveitando:

 

Seria possível colocar pra não repetir o nome? Exemplo: 

Pra aparecer Dragon 1x só.

Tibia_2019-09-01_17-42-01.thumb.png.14b3c0e0d2c25816bc9904f012466a6f.png

 

E por fim, vc saberia como fazer pra colocar um "últimas mortes" no site? Eu uso MySQL/Apache. 

 

local deathListEnabled = true
local maxDeathRecords = 5

function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
        nextUseStaminaTime[playerId] = nil
    end
    
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Você morreu')
    player:removeBlessing(6)
    player:removeBlessing(7)
    
    if not deathListEnabled then
        return
    end
    
    local byPlayer = 0
    local killerName
    local killerid
    if killer ~= nil then
        if killer:isPlayer() then
            killerid = killer:getGuid()
            byPlayer = 1
        else
            local master = killer:getMaster()
            if master and master ~= killer and master:isPlayer() then
                killer = master
                killerid = killer:getGuid()
                byPlayer = 1
            end
        end
        killerName = killer:isMonster() and killer:getType():getNameDescription() or killer:getName()
    else
        killerName = 'field item'
    end
    
    local byPlayerMostDamage = 0
    local mostDamageKillerName
    if mostDamageKiller ~= nil then
        if mostDamageKiller:isPlayer() then
            byPlayerMostDamage = 1
        else
            local master = mostDamageKiller:getMaster()
            if master and master ~= mostDamageKiller and master:isPlayer() then
                mostDamageKiller = master
                byPlayerMostDamage = 1
            end
        end
        mostDamageName = mostDamageKiller:isMonster() and mostDamageKiller:getType():getNameDescription() or mostDamageKiller:getName()
    else
        mostDamageName = 'field item'
    end
    
    
    local KillersArray = {}
    for k, v in pairs(player:getDamageMap()) do
        local CreatureMT = Creature(k)
        if CreatureMT and not isInArray(KillersArray, CreatureMT:getName()) then
            table.insert(KillersArray, CreatureMT:getName())
        end
    end
    local playerGuid = player:getGuid()
    db.query('INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`, `player_killers`) VALUES (' .. playerGuid .. ', ' .. os.time() .. ', ' .. player:getLevel() .. ', ' .. db.escapeString(killerName) .. ', ' .. byPlayer .. ', ' .. db.escapeString(mostDamageName) .. ', ' .. byPlayerMostDamage .. ', ' .. (unjustified and 1 or 0) .. ', ' .. (mostDamageUnjustified and 1 or 0) .. ', \"' .. table.concat(KillersArray, ";") .. '\")')
    local resultId = db.storeQuery('SELECT `player_id` FROM `player_deaths` WHERE `player_id` = ' .. playerGuid)
    
    local deathRecords = 0
    local tmpResultId = resultId
    while tmpResultId ~= false do
        tmpResultId = result.next(resultId)
        deathRecords = deathRecords + 1
    end
    
    if resultId ~= false then
        result.free(resultId)
    end
    
    local limit = deathRecords - maxDeathRecords
    if limit > 0 then
        db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
    end
    
    if byPlayer == 1 then
        
        local targetGuild = player:getGuild()
        targetGuild = targetGuild and targetGuild:getId() or 0
        if targetGuild ~= 0 then
            local killerGuild = killer:getGuild()
            killerGuild = killerGuild and killerGuild:getId() or 0
            if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer.uid) then
                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 .. '))')
                if resultId ~= false then
                    warId = result.getNumber(resultId, 'id')
                    result.free(resultId)
                end
                
                if warId ~= false then
                    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 .. ')')
                end
            end
        end
    end
end

Isso deve resolver ↑.

 

Sobre o site eu não entendo muito bem, mas posso até tentar.

                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

Cara, não sei nem como agradecer! Deu super certo.

 

Sobre a parte do site, eu ja vi vários sites de ot com uma página de "Últimas Mortes", mas não consegui fazer funcionar no meu porque a minha database é diferente, acho.

Link para o post
Compartilhar em outros sites
1 hora atrás, MatCollier disse:

Cara, não sei nem como agradecer! Deu super certo.

 

Sobre a parte do site, eu ja vi vários sites de ot com uma página de "Últimas Mortes", mas não consegui fazer funcionar no meu porque a minha database é diferente, acho.

 

Isso é assunto pra outro tópico kk

                              _
                          .-'` `}
                  _./)   /       }
                .'o   \ |       }
                '.___.'`.\    {`
                /`\_/  , `.    }                                      ME DA UMA NOZ!
                \=' .-'   _`\  {
                 `'`;/      `,  }
                    _\   @   ;  }
                   /__`;-...'--'

Cluck!

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo