Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
8 years ago
Auto-translated
once again, does the hero block the only possible path to the desired cell? then everything works according to the mechanics; CanHeroMove considers the hero an impassable obstacle. You can add a check for this situation, and if it occurs, move Erling to the location of your hero, for example.
Нет войне.
In reply to Gerter
8 years ago
Auto-translated
Gerter
once again, does the hero block the only possible path to the desired cell?
Yes, but in other scenarios, it's simply written as MoveHero(...), and the hero goes there, even if another hero with a huge army is blocking the way.
Gerter
then everything works according to the mechanics; CanHeroMove considers the hero an impassable obstacle. You could add a check for this situation, and if it occurs, move Erling to your hero's location, for example.
I can't even imagine how to write that :confused:
User Avatar
8 years ago
Auto-translated
try replacing MoveHero with MoveHeroRealTime, and remove the CanHeroMove check

more precisely, something like this
if(CanMoveHero(Erling, 15, 9, 0)) then
MoveHero(Erling, 15, 9, 0)
else
MoveHeroRealTime(Erling, 15, 9, 0)
end
Нет войне.
In reply to Gerter
8 years ago
Auto-translated
Gerter
try replacing MoveHero with MoveHeroRealTime, and remove the CanHeroMove check

more precisely, something like this
if(CanMoveHero(Erling, 15, 9, 0)) then
MoveHero(Erling, 15, 9, 0)
else
MoveHeroRealTime(Erling, 15, 9, 0)
end

No, that won't work. I have a task to defend the castle, so MoveHeroRealTime won't be suitable. 15,9 is the entry point to the castle; this might help.
User Avatar
8 years ago
Auto-translated
You can perform a series of MoveHero actions, each moving the hero one step at a time, with success checks after each step. The coordinates of each step should be stored in an array.
 

К А
Стикеры GBF в Telegram
In reply to Ment
8 years ago
Auto-translated
Ment
You can perform a series of MoveHero actions, each moving the hero one step, with a check for success after each step. Store the coordinates of each step in an array.
Could you please provide more details?
User Avatar
8 years ago
Auto-translated
x={15,16,17,18}
y={9,9,10,10}
for i=1 to n
if IsHeroAlive("Erling") then
MoveHero("Erling",x,y,0)
end
end

So, hypothetically speaking. In reality, I see a couple of weak points in the code (for example, in the event of a battle and victory in it, Erling will most likely not continue moving, as the script has already completed its execution while the battle was in progress), but the logic is generally like this.
 

К А
Стикеры GBF в Telegram
In reply to Ment
8 years ago
Auto-translated
Ment
x={15,16,17,18}
y={9,9,10,10}
for i=1 to n
if IsHeroAlive("Erling") then
MoveHero("Erling",x,y,0)
end
end

So, hypothetically speaking. In reality, I see a couple of weak points in the code here (for example, in the event of a battle and victory in it, Erling will most likely not continue moving, as by the time the battle is over, the script will have already finished executing), but the logic is generally like this.

The console displays an error (see screenshot). Here is the code:

x={15,16,17,18}
y={9,9,10,10}
for i=1,n do
if IsHeroAlive(Erling) then
MoveHero(Erling,x,y,0)
end
end
Attachments 1
1 file attached • Total size: 26.3 KB
User Avatar
8 years ago
Auto-translated
Ah, yes.
x={15,16,17,18}
y={9,9,10,10}
n=4
for i=1,n do
if IsHeroAlive(Erling) then
MoveHero(Erling,x,y,0)
end
end
The size of the coordinate array should be passed to n.
 

К А
Стикеры GBF в Telegram
8 years ago
Auto-translated
Ah, unfortunately, the problem remains the same: if a hero is at point 15.8, Erling will remain where he stopped.
User Avatar
8 years ago
Auto-translated
well, if the problem is only with this point, then you can simply move to it if the desired one is unavailable.
Нет войне.
In reply to Gerter
8 years ago
Auto-translated
Gerter
well, if the problem is only in this specific location, you can simply move to it if the desired one is unavailable.
Is there a command to check if a hero is located at that point?
User Avatar
8 years ago
Auto-translated
either through GetObjectPosition() or by simply moving the hero to that point if CanHeroMove returns false.
Нет войне.
8 years ago
Auto-translated
Another question arose: if, during the MoveHeroRealTime function, the hero doesn't reach the destination point, will he continue moving towards it on the next turn?
User Avatar
8 years ago
Auto-translated
MoveHeroRealTime moves the hero independently of the turn, even during the opponent's turn.
So the answer is no; if the function doesn't complete for some reason, then that's it.
 

К А
Стикеры GBF в Telegram

Statistics

Welcome our newest member: recijeb