Auto-translated
serovoy, when creating a new hero, you need to assign it a unique system name, which is then used to reference it in scripts.
New here? I'm Roha — want a quick tour?
function offlich()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", nil);
ShowFlyingSign(GetMapDataPath().."offli.txt");
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", "offlich");
function mostFF()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "most", nil);
MessageBoxForPlayers(PLAYERFLT_1, GetMapDataPath().."most11.txt");
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "most", "mostFF");
ShowFlyingSign(messageName, objectName, targetPlayerID = -1, time = 1.0);
ShowFlyingSign("GetMapDataPath().."offli.txt","offlich", "targetPlayerID = -1", "time = 1.5");
ShowFlyingSign({path.."slavescaptured.txt";totalcost=tc},hero,PLAYER_1,5);
ShowFlyingSign(GetMapDataPath().."offlich.txt", off, Player_1, 5);
function offlich()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", nil);
ShowFlyingSign(GetMapDataPath().."offlich.txt", off, Player_1, 5);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", "offlich");
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
for i=1,100 do
startThread(Func);
end
As a result, multiple instances of the function Func may be launched, even though the previous one might not have finished executing.
Is there a script that determines whether a given function is currently running or not? (without using a flag within the function itself)
For example, consider this:As a result, several Func functions may start, even though the previous one might not have finished.
for i=1,100 do
startThread(Func);
end
local threads = {}
local startExec = function(func)
local threads = threads
errorHook(function()
%threads[%func] = nil
end)
threads[func] = 1
func()
threads[func] = nil
end
function startThreadOnce(func)
if not %threads[func] then
startThread(%startExec, func)
end
end
function isFunctionRunning(func)
return %threads[func]
end
In this example, startThreadOnce starts the function only if it is not currently running. isFunctionRunning checks whether the function is currently running.
StartCombat('Brem', nil, 2, CREATURE_PEASANT, 15, CREATURE_ARCHER, 6)
serovoy, when you create a new hero, you need to assign a unique system name to him, which is then used to reference him in scripts.