There are still some problems. During a hero's turn, instead of performing the action once, the archer starts shooting a huge number of times without stopping until the ammunition runs out. I can't figure out how to stop it.
Here's the script again:
Title
function DefenderHeroMove (unit)InitRandom()
for n, creature in GetDefenderCreatures() do
local id = GetCreatureType(creature)
if id == CREATURE_ARCHER then
local targets = GetAttackerCreatures()
chosen_target = targets[random(length(targets)+1)]
sleep (50)
commandShot (creature, chosen_target, not nil)
sleep (1)
end
end
Yes, indeed, with the expert call, Heavenly Shield started to be cast. And random also started to generate numbers. But now there is such a problem: the script complains about the second argument of your function, i.e., the variable chosen_target (screenshot attached). Maybe I misunderstood it somehow and, accordingly, I'm writing it incorrectly?
P.S. Everything was resolved; I just needed to add sleep so that everything would work correctly. Thank you very much.The function itself:
Title
function DefenderHeroMove (unit)
InitRandom()
for n, creature in GetDefenderCreatures() do
local id = GetCreatureType(creature)
if id == CREATURE_ARCHER then
local targets = GetAttackerCreatures()
local chosen_target = targets[random(length(targets)+1)]
commandShot (creature, chosen_target, nil)
end
end