Your check is only performed once - at the beginning of the game.
To have the check run throughout the game, you need to place the condition in a loop.
Added after 11 hours and 45 minutes
A new question has appeared:
I set the path for the computer:
MoveHeroRealTime( "Hero1", 82, 216);
But in the game, the console says that it cannot find a path to that cell. How can I show it the path? If needed, 82, 216 is the cell at the entrance to the city.