red_squads = {["red1"] = 1, ["red2"] = 1, ["red3"] = 1, ["red4"] = 1, ["red5"] = 1, ["red6"] = 1, ["red7"] = 1, ["red8"] = 1, ["red9"] = 1, ["red10"] = 1,
["red11"] = 1, ["red12"] = 1, ["red13"] = 1, ["red14"] = 1, ["red15"] = 1};
rednumber = 0
function CheckRedStacks()
while 1 do
for stack, exists in red_squads do
if exists and (not IsObjectExists(stack)) then
red_squads[stack] = nil
rednumber = rednumber + 1
if GetObjectiveState('desired_quest') == OBJECTIVE_ACTIVE then
SetObjectiveProgress('desired_quest', rednumber)
end
end
end
sleep()
end
end
startThread(CheckRedStacks)
Posts from Scripts
function CheckRedStacks() --specifically, this is where I check for existence
while 1 do
for i, stack in red_squads do
if IsObjectExists(stack) == nil then
rednumber = 0 + 1;
end;
end;
end;
end;
function Checking()
while 1 do
sleep(5);
if rednumber == 1 then
SetObjectiveProgress('sec1', 1);
elseif rednumber == 2 then
SetObjectiveProgress('sec1', 2);
end;
end;
end;
...
function CheckRedStacks()
while 1 do
for stack, exists in red_squads do
if exists and (not IsObjectExists(stack)) then
red_squads[stack] = nil
rednumber = rednumber + 1
if GetObjectiveState('desired_quest') == OBJECTIVE_ACTIVE then
SetObjectiveProgress('desired_quest', rednumber)
end
end
end
sleep()
end
end
...
Why add a construct like "while 1 do ... end"?
I have nothing against it, I'm just curious
to create an infinite loop of verification, obviously
constantly check for the existence of stacks and update the quest progress when they are destroyed. of course, my loop needs to be supplemented with an exit condition when the progress is equal to 15, but that's a minor detail now.
Why don't you suggest your own version? It would be interesting to see.
But overall, this isn't particularly important for map scripts.
...
I've sketched out the code in general terms (3-in-1). I haven't tested it.
-- Squad names in the map editor
squadList = {
"squad01", "squad02", -- ... "squad99"
}
function connect()
Trigger(NEW_DAY_TRIGGER, "onDateUpdate")
Trigger(COMBAT_RESULTS_TRIGGER, "onCombatFinish")
for i, squad in squadList do
setSquadDisabled(squad)
Trigger(OBJECT_TOUCH_TRIGGER, squad, "onObjectTouch")
end
end
function setSquadDisabled(squad)
SetObjectEnabled(squad, nil)
-- SetDisabledObjectMode(squad, DISABLED_INTERACT) -- changes the cursor
-- SetMonsterSelectionType(squad, 0) -- removes the skirt
end
-- If it's not critical to wait for the next day (due to the plot or design)
function onDateUpdate()
-- ...
check()
end
-- Here, you can additionally find out the hero's name,
-- the number of creatures, the battle result, etc.
-- The essence of the method is additional extended capabilities.
function onCombatFinish(index)
-- local heroWinner = GetSavedCombatArmyHero(index, 1)
-- local heroLooser = GetSavedCombatArmyHero(index, 0)
check()
end
-- Here, you will additionally have to find out the stacks and their number for the object,
-- or completely rely on the script, excluding the editor settings.
-- The essence of the method is to launch a controlled check after the battle.
function onObjectTouch(hero, object)
StartCombat(hero, nil, ..., "check", ...) -- ??? A lot of different parameters, maybe I'm wrong
end
function check()
local count = getSquadCount()
if count == length(squadList) then
-- All squads are killed -> actions ...
else
-- Obviously, all ProgreesFile's should be specified in the editor
-- in a quantity equal to the number of squads in the squadList
SetObjectiveProgress(<имя задания в редакторе>, count)
end
end
function getSquadCount()
local count = 0
for i, squad in squadList do
if IsObjectExists(squad) then
count = count + 1
end
end
return count
end
startThread(connect)
Does the advanced editor require a licensed version?
Thank you for providing the codes above.
Too many unnecessary steps, in my opinion, for such simple tasks. But here, it doesn't really matter; both options work, and the user will choose whichever is clearer and more convenient for them.
And, speaking globally, triggers are simply inapplicable in some situations, unlike these kinds of scripts.
Is there any documentation on how to use the advanced map editor? There's a lot of interesting stuff you can do with it, but I don't know how to work with it. I only know how to enable it.
Does the advanced editor require a licensed version?
...
I agree. If we're deviating from the example, it's better to use streams only when other options aren't suitable. The more checks (conditions), the more laggy the map becomes.
There doesn't seem to be anything particularly special to learn from it. I don't remember the exact differences, but it seems to allow you to access game resources, select the necessary windows (?), package changes into a map archive, maybe something else. As for the licensed version, it probably doesn't matter.
That's the problem. I don't know how to add objects from the advanced editor to the map.
Or are you talking about a mod?
For example GetObjectFromLocation(x,y)
Or the only way is to rotate through all existing objects on the map and check them one by one?