Skip to content
User Avatar
#2216
Auto-translated
Here's a shortened version from my map; only the computer-controlled unit chases the player, so it might not look exactly as you'd expect. `hero` is the computer's hero, and `player_hero` is the player's hero. Run it as a thread. The computer tries to move towards the player at the beginning of each turn, and if the player moves away quickly during that time, it will also be handled correctly.
function MainKnightSavedHeroReturnWithPlayerThread()

local hero = quest_main_knight.AttackParam('hero');
local start_date = GetDate(ABSOLUTE_DAY);
local move_date = 0;
local curr_date;
local hx_last, hy_last, hf_last = -1, -1, -1;
local hx_curr, hy_curr, hf_curr;

while(1) do
if(IsObjectExists(hero)) then

if(IsObjectExists(player_hero)) then
hx_curr, hy_curr, hf_curr = GetObjectPosition(player_hero);
if((hx_last ~= hx_curr) or (hy_last ~= hy_curr) or (hf_last ~= hf_curr)) then
hx_last, hy_last, hf_last = hx_curr, hy_curr, hf_curr;
MoveHeroRealTime(hero, hx_curr, hy_curr, hf_curr);
end
end

-- movement points are added at the beginning of each turn
curr_date = GetDate(ABSOLUTE_DAY);
if(move_date ~= curr_date) then
move_date = curr_date;
ChangeHeroStat(hero, STAT_MOVE_POINTS, 2500);
sleep(1);
if(IsObjectExists(player_hero)) then
hx_curr, hy_curr, hf_curr = GetObjectPosition(player_hero);
MoveHeroRealTime(hero, hx_curr, hy_curr, hf_curr);
end
end

else
break
end
sleep(5);
end

end

Statistics

Welcome our newest member: leyu