Ir para conteúdo
  • 0

Ajuda em creaturescript


dearthpoenix

Pergunta

Eu tenho esse script aqui:


local rewards = {
{id = 2160, count = 1},
{id = 2152, count = 20},
}

function onDeath(cid, corpse, killers)

local partiesDamageRatio, mostDamage, winners = {}, {0, 0, false}, {}

for _, player in pairs (killers) do
local percentDealt = getPlayerStorageValue(cid, getPlayerGUID(player))
if isInParty(player) then
partiesDamageRatio[getPlayerParty(player)] = (partiesDamageRatio[getPlayerParty(player)] or 0) + percentDealt
elseif mostDamage[1] < percentDealt then
mostDamage = {percentDealt, player, false}
end
end

for guildId, damageRatio in pairs (partiesDamageRatio) do
if damageRatio > mostDamage[1] then
mostDamage = {damageRatio, guildId, true}
end
end

if mostDamage[3] then
winners = getPartyMembers(mostDamage[2])
else
winners = {mostDamage[2]}
end

for _, winId in pairs (winners) do
for _, itemInfo in pairs (rewards) do
doPlayerAddItem(winId, itemInfo.id, itemInfo.count or 1)
end
end

return true
end

function onStatsChange(cid, attacker, type, combat, value)

if not isCreature(attacker) or not isPlayer(attacker) or type ~= STATSCHANGE_HEALTHLOSS then return true end

local percentToAdd = math.abs(value) / getCreatureMaxHealth(cid) * 100
local currentPercent = math.max(getPlayerStorageValue(cid, getPlayerGUID(attacker)), 0)
setPlayerStorageValue(cid, getPlayerGUID(attacker), currentPercent + percentToAdd)

return true
end




Ele faz com que o monstro em questão quando ele morre, a party que tirar mais dano dele ganha itens e se o player não estiver na party que tirar mais dano ele não ganha o prêmio.

Eu gostaria que editasse esse script so para um detalhe, que no lugar de party fosse a guild que tirar mais dano e tal.

Alguém para me ajudar por favor??? Valendo 3 REP!


Esperando respostas!

Editado por dearthpoenix
Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0

Testa desse jeito aqui:

 

 

local rewards = {
{id = 2160, count = 1},
{id = 2152, count = 20},
}

function isInGuild(cid)
	return getPlayerGuildId(cid) > 0 and true or false
end

function getGuildMembers(cid)
	local members = {}
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == getPlayerGuildId(cid) then
			table.insert(members, pid)
		end
	end
	return members
end

function onDeath(cid, corpse, killers)

local guildDamageRatio, mostDamage, winners = {}, {0, 0, false}, {}

for _, player in pairs (killers) do
     local percentDealt = getPlayerStorageValue(cid, getPlayerGUID(player))
     if isInGuild(player) then
        guildDamageRatio[getPlayerGuildId(player)] = (guildDamageRatio[getPlayerGuildId(player)] or 0) + percentDealt
     elseif mostDamage[1] < percentDealt then
         mostDamage = {percentDealt, player, false}
     end
end

for guildId, damageRatio in pairs (guildDamageRatio) do
     if damageRatio > mostDamage[1] then
         mostDamage = {damageRatio, guildId, true}
     end
end

if mostDamage[3] then
     winners = getGuildMembers(mostDamage[2])
else
     winners = {mostDamage[2]}
end

for _, winId in pairs (winners) do
     for _, itemInfo in pairs (rewards) do
         doPlayerAddItem(winId, itemInfo.id, itemInfo.count or 1)
     end
end

return true
end

function onStatsChange(cid, attacker, type, combat, value)

if not isCreature(attacker) or not isPlayer(attacker) or type ~= STATSCHANGE_HEALTHLOSS then return true end

local percentToAdd = math.abs(value) / getCreatureMaxHealth(cid) * 100
local currentPercent = math.max(getPlayerStorageValue(cid, getPlayerGUID(attacker)), 0)
setPlayerStorageValue(cid, getPlayerGUID(attacker), currentPercent + percentToAdd)

return true
end

 

 

Link para o comentário
Compartilhar em outros sites

  • 0

Testei e deu esse erro aqui:

 

[11/09/2013 09:44:39] [Error - CreatureScript Interface]
[11/09/2013 09:44:39] data/creaturescripts/scripts/varralha.lua:onDeath
[11/09/2013 09:44:39] Description:
[11/09/2013 09:44:39] (internalGetPlayerInfo) Player not found when requesting player info #11


pra ajudar a solucionar esse script eu pedir ele nesse post aqui: http://www.xtibia.com/forum/topic/194958-ganha-item-a-party-que-tirar-mais-damage-do-monstro/

 

Ai veja ai se consegue deixa no lugar de party seja a guild.


por favor alguem pode responder?

 

Link para o comentário
Compartilhar em outros sites

  • 0

Refiz aqui e deu certo (testei com um char em 8.6)

 

 

function isInGuild(cid)
	return getPlayerGuildId(cid) > 0 and true or false
end

function getPlayerGuildMembersOn(cid)
	if not isInGuild(cid) then return false end
	local members = {}
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == getPlayerGuildId(cid) then
			table.insert(members, pid)
		end
	end
	return members
end

function onStatsChange(cid, attacker, type, combat, value)
	if isPlayer(attacker) and type == 1 then
		local percentDealt = getPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541) > -1 and getPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541) or 0
		local addPercent = math.floor(value) / getCreatureMaxHealth(cid) * 100
		setPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541, percentDealt + addPercent)
	end
	return true
end

function onDeath(cid, corpse, killers)
	local reward = {item1 = 1234, item2 = 1345, quant1 = 1, quant2 = 1}
	local topPercentDealt = 0
	local killer = 0
	
	for _, pid in pairs(killers) do
		local percentDealt = getPlayerStorageValue(pid, getPlayerGUID(pid) + 54541)
		if percentDealt > topPercentDealt then
			killer = pid
			topPercentDealt = percentDealt
		end
	end
	
	if isInGuild(killer) then
		local gmembers = getPlayerGuildMembersOn(killer)
		for _, pid in pairs(gmembers) do
			doPlayerAddItem(pid, reward.item1, reward.quant1)
			doPlayerAddItem(pid, reward.item2, reward.quant2)
		end
	else
		doPlayerAddItem(killer, reward.item1, reward.quant1)
		doPlayerAddItem(killer, reward.item2, reward.quant2)
	end
	return true
end

 

 

 

EDIÇÃO:

Na verdade, esse de cima verifica quem deu mais dano e premia a guild dele. Esse aqui funciona do jeito certo:

 

 

function isInGuild(cid)
	return getPlayerGuildId(cid) > 0 and true or false
end

function getGuildMembersOn(guildID)
	local members = {}
	for _, pid in ipairs(getPlayersOnline()) do
		if getPlayerGuildId(pid) == guildID then
			table.insert(members, pid)
		end
	end
	return members
end

function onStatsChange(cid, attacker, type, combat, value)
	if isPlayer(attacker) and type == 1 then
		local percentDealt = getPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541) > -1 and getPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541) or 0
		local addPercent = math.floor(value) / getCreatureMaxHealth(cid) * 100
		setPlayerStorageValue(attacker, getPlayerGUID(attacker) + 54541, percentDealt + addPercent)
	end
	return true
end

function onDeath(cid, corpse, killers)
	local reward = {item1 = 2160, item2 = 2148, quant1 = 100, quant2 = 100}
	local topPercentDealt = 0
	local soloKiller = 0
	local guildPercentDealt = {}
	
	for _, pid in pairs(killers) do
		local percentDealt = getPlayerStorageValue(pid, getPlayerGUID(pid) + 54541)
		if isInGuild(pid) then
			guildPercentDealt[getPlayerGuildId(pid)] = (guildPercentDealt[getPlayerGuildId(pid)] or 0) + percentDealt
		elseif percentDealt > topPercentDealt then
			topPercentDealt = percentDealt
			soloKiller = pid			
		end
	end
	
	local topGuildDamage = 0
	local topGuild = 0
	for guildID, guildDamage in pairs(guildPercentDealt) do
		if guildDamage > topGuildDamage then
			topGuildDamage = guildDamage
			topGuild = guildID
		end
	end
	
	local winners = {}
	if topPercentDealt > topGuildDamage then
		winners[1] = soloKiller
	else
		for _, player in ipairs(getGuildMembersOn(topGuild)) do
			table.insert(winners, player)
		end
	end
	
	for _, winner in ipairs(winners) do
		doPlayerAddItem(winner, reward.item1, reward.quant1)
		doPlayerAddItem(winner, reward.item2, reward.quant2)
	end
	
	
	
	for _, pid in pairs(killers) do
		setPlayerStorageValue(pid, getPlayerGUID(pid) + 54541, 0)
	end
	return true
end

 

 

Editado por omega blueheaven
Link para o comentário
Compartilhar em outros sites

  • 0

Eu editei ele conseguir fazer de outro jeito que funciona do mesmo jeito

 

local rewards = {
{id = 2160, count = 1},
{id = 2152, count = 20},
}

function isInGuild(cid)
return getPlayerGuildId(cid) > 0 and true or false
end

function getGuildMembers(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, pid)
end
end
return #players > 0 and players or false
end

function onDeath(cid, corpse, killers)

local guildDamageRatio, mostDamage, winners = {}, {0, 0, false}, {}

for _, player in pairs (killers) do
local percentDealt = getPlayerStorageValue(cid, getPlayerGUID(player))
if isInGuild(player) then
guildDamageRatio[getPlayerGuildId(player)] = (guildDamageRatio[getPlayerGuildId(player)] or 0) + percentDealt
elseif mostDamage[1] < percentDealt then
mostDamage = {percentDealt, player, false}
end
end

for guildId, damageRatio in pairs (guildDamageRatio) do
if damageRatio > mostDamage[1] then
mostDamage = {damageRatio, guildId, true}
end
end

if mostDamage[3] then
winners = getGuildMembers(mostDamage[2])
else
winners = {mostDamage[2]}
end

for _, winId in pairs (winners) do
for _, itemInfo in pairs (rewards) do
doPlayerAddItem(winId, itemInfo.id, itemInfo.count or 1)
end
end

return true
end

function onStatsChange(cid, attacker, type, combat, value)

if not isCreature(attacker) or not isPlayer(attacker) or type ~= STATSCHANGE_HEALTHLOSS then return true end

local percentToAdd = math.abs(value) / getCreatureMaxHealth(cid) * 100
local currentPercent = math.max(getPlayerStorageValue(cid, getPlayerGUID(attacker)), 0)
setPlayerStorageValue(cid, getPlayerGUID(attacker), currentPercent + percentToAdd)

return true
end

 

 

O erro era na função getGuildMembers.

 

Mas vlw ai pela ajuda, é teu os Rep!

Editado por dearthpoenix
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...