I’m trying to get the Paladin to heal my hero while I fight. I also don’t understand and couldn’t find any info on how close the paladin needs to be to the target of the healing spell.
I’m getting an error. It would be line 8 in the code below. “Find the distance to a target unit”
def commandPaladinHeal():
currentHealth = self.health
healingThreshold = self.maxHealth - 150
paladins = self.findByType("paladin")
if paladin:
if paladin.canCast("heal"):
if currentHealth < healingThreshold:
self.command(paladin, "cast", "heal", "self")
pass
else:
self.command(paladin, "shield")
So, I changed it to this and still got the same error.
if paladin.canCast("heal"):
if currentHealth < healingThreshold:
distance = paladin.distanceTo(self)
if distance < 12:
self.command(paladin, "cast", "heal", "self")
not sure, I am also stuck at the paladin introductory level. But I can get paladins to heal my allies.
Try self.command(paladin, “cast”, “heal”, self) instead of self.command(paladin, “cast”, “heal”, “self”).
In short: substitute “self” by self.
Cheers
that solved the error. Thanks. They still aren’t healing my hero but it’s a step in the right direction.
Getting closer but how come that code only gets one of the paladins to move? One follows my hero and heals and the other stays at it’s starting point.
Did you loop over all the paladins? I think code should be like (notice additional for loop over paladins):
Treat the dots like empty spaces
def commandPaladinHeal():
…currentHealth = self.health
…healingThreshold = self.maxHealth - 150
…paladins = self.findByType(“paladin”)
…for paladin in paladins:…#New addition to the code
…if paladin:
…if paladin.canCast(“heal”):
…if currentHealth < healingThreshold:
…self.command(paladin, “cast”, “heal”, “self”)
…pass
…else:
…self.command(paladin, “shield”)
(edit i see this was answered already.)
I use this
me = self.id
self.command(paladin, "cast", "heal", me)
You’re not looping on your paladins. You checked whether there are multiple paladins then issued one command.
if len(paladins) > 0:
for i in range(len(paladins)):
paladin = paladins[i]