I've written a function as a part of party.lua and I hope it is not difficult to understand
Code: Select all
function PartyHealsEvent()
-- return the average party health
local function getpartyHP()
local cupartyHP = 0
local numPartyPawns = 0
for i,v in ipairs(partymemberpawn) do
v:update()
local hp = v.HP/v.MaxHP*100
-- cumulate partyHP
cupartyHP = cupartyHP + hp
numPartyPawns = numPartyPawns + 1
end
return cupartyHP/numPartyPawns
end
-- return partymemberpawn Index with the lowest health
local function getlowestHpIndex()
local lowestHpIndex
for i,v in ipairs(partymemberpawn) do
v:update()
local lowestHp
local hp = v.HP/v.MaxHP*100
-- get the lowestHP index number
if lowestHp == nil or hp < lowestHp then
lowestHp = hp
lowestHpIndex = i
end
end
return lowestHpIndex
end
PartyTable()
local saveTargetPawn = player:getTarget()
local targetLost
while( getpartyHP() < 95 ) do
local lowestHpIndex = getlowestHpIndex()
player:target(partymemberpawn[lowestHpIndex])
targetLost = true
player:cast("PRIEST_URGENT_HEAL")
end
if targetLost then
player:target(saveTargetPawn)
end
end
Code: Select all
if GetPartyMemberName(i) then
table.insert(partymemberName,i + 1, GetPartyMemberName(i))
table.insert(partymemberObj,i + 1, player:findNearestNameOrId(partymemberName[i + 1]))
if partymemberObj[i + 1] then
table.insert(partymemberpawn,i + 1, CPawn(partymemberObj[i + 1].Address))
end
end
Code: Select all
<onSkillCast><![CDATA[
-- Additional Lua code to execute when casting a skill
-- Note: arg1 contains the skill being used.
-- i.e. arg1.Name will be the name of the skill being cast
PartyHealsEvent()
]]></onSkillCast>