Page 1 of 1

party healing on the fly

Posted: Thu Aug 18, 2011 7:19 am
by SpiralV
I usually let my bots under the control of the wp files, but there is no real possibility to let one of them healing the party.
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
a small correction to partymemberpawn Table because findNearestNameOrId returns nil if the party character is too far away

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
and finally calling the function

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>
It works perfectly for me :P

Re: party healing on the fly

Posted: Thu Aug 18, 2011 10:47 am
by lisa
Had to read over it a few times to fully understand how it works =)

I see you want to heal party while still following a WP file instead of just following a party member, I like it =)

I am going to test the adjustment you made to partymemberpawn and see how it goes, I never had any issues with it myself but others may have I guess.

If I might add one suguestion, instead of using the

Code: Select all

player:cast("PRIEST_URGENT_HEAL")
to go with the 95 > hp you could use

Code: Select all

player:checkSkills(true);

Which will use the skills in profile and the profile settings aswell, so it can work with all priest skills and also druid skills, the "true" means friendly skills, such as heals and buffs. I notice you don't update buffs though. Since you target the player anyway it wouldn't take much to check buffs, just need to add in a

Code: Select all

 partymemberpawn[lowestHpIndex]:updateBuffs() 
So I guess it would look like this

Code: Select all

  while( 95 > getpartyHP() ) do
      local lowestHpIndex = getlowestHpIndex()                  
      player:target(partymemberpawn[lowestHpIndex])
      targetLost = true
      partymemberpawn[lowestHpIndex]:updateBuffs() 
      player:checkSkills(true)
   end

Re: party healing on the fly

Posted: Tue Aug 23, 2011 11:42 pm
by azzi_x
hi lisa!

i tried searching for a bot script that follows me around and auto heal / buff me but no luck. wonder if u could share coz it looks like you have it. :)

Re: party healing on the fly

Posted: Wed Aug 24, 2011 12:12 am
by lisa
Just to follow and heal?

just start MM with

Code: Select all

rom/bot path:partyhealer
It's part of the default bot, so you have all the code required already.

It's all explained here

Re: party healing on the fly

Posted: Wed Aug 24, 2011 4:42 am
by azzi_x
no wonder i couldnt find that coz im still using 473. thanks a bunch!