Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
I would suggest an even shorter version:
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)
Нет войне.
Auto-translated

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
User Avatar
Auto-translated
to create an infinite loop of checks, obviously.
Нет войне.
In reply to Gerter
Auto-translated
Gerter
to create an infinite loop of verification, obviously
Okay, let me rephrase the question. What is the purpose of this infinite verification?
User Avatar
Auto-translated
constantly check for the existence of stacks and update the task 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.
Нет войне.
In reply to Gerter
Auto-translated
Gerter
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.
I understand. It just caused me some confusion, but overall it's a perfectly workable solution.
User Avatar
Auto-translated
Go ahead and suggest your version; it will be interesting to see.
Нет войне.
In reply to Gerter
Auto-translated
Gerter
Why don't you suggest your own version? It would be interesting to see.
It's best not to use additional infinite loops. As an alternative, you could tie the check to COMBAT_RESULT, OBJECT_TOUCH, or NEW_DAY.
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)
Auto-translated
By the way, these are also interesting scripts, thank you. They can be applied in many places. However, for a task that requires waiting for a new day, when you need to update the task in real time, it might be critical.
User Avatar
Auto-translated
There are too many unnecessary actions, in my opinion, for such simple tasks. But it doesn't really matter here; both options work, and the user will choose whichever one is clearer and more convenient for them. And if we're talking about it on a larger scale, triggers are simply not applicable in some situations, unlike similar event chains.
Нет войне.
User Avatar
Auto-translated
Is there any documentation on how to use the advanced map editor? You can do a lot of interesting things 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?

Thank you for providing the codes above.
In reply to Gerter
Auto-translated
Gerter
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.
I agree. If we're moving away from the example, it's better to use scripts only when other options are not suitable. The more checks (conditions), the more laggy the map becomes.
User01322342
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?
...
There doesn't seem to be anything particularly special that you need to learn. I don't remember the exact differences, but it seems to allow you to open game resources, select the necessary windows (?), pack changes into a map archive, and maybe something else. As for the licensed version, it probably doesn't matter.
In reply to JonnyP
User Avatar
Auto-translated
JonnyP
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.
In reply to John_Lock
Auto-translated
User01322342
That's the problem. I don't know how to add objects from the advanced editor to the map.
Which "advanced editor" are you referring to? It doesn't offer the ability to add objects.
Or are you talking about a mod?
Is there a way to get what object is on specific coordinates?

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?

Statistics

Welcome our newest member: Emil