Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
8 years ago
Auto-translated
How does the SetObjectiveProgress function work?
When you create a quest in the map properties tree, you can define stages. Right-click on a certain item (I don't remember the exact name), press "add," and for each stage, specify the path to the description text. In the quest log, the main description will be displayed first, followed by the additional description corresponding to the current stage.
So, if a quest has these stages, it will start at stage zero, and you can use the function to advance it further, for example, to move to stage 1:
SetObjectiveProgress('quest_name', 1);
8 years ago
Auto-translated
Thank you, I understand.
User Avatar
8 years ago
Auto-translated
How can I remove the faction circles that appear under neutral creatures? And is it possible to place creatures from a hero's army onto the map?
User Avatar
8 years ago
Auto-translated
How do I remove the faction circles under neutral creatures?
Here is the code I provided earlier. The documentation states that before disabling the circles, you need to disable interaction with the creatures (so they cannot be attacked). I haven't checked if it's possible not to disable this.
Is it possible to place creatures on the map from a hero's army?
I implemented similar functionality in the "Hero's Path" map, but it took several hundred lines of code because there are questions about how to initiate the placement, how to select how many creatures to deploy, and so on. In the simplest case, this involves calling two functions: remove specific creatures from the hero's army (RemoveCreatures) and place them in the same quantity on the map (CreateMonster).
User Avatar
8 years ago
Auto-translated
Thank you very much!
8 years ago
Auto-translated
Another question arose. How can I make it so that one function is triggered the first time a region is visited, and a different function is triggered the second time? Someone already asked about this on the forum, but I couldn't find it. It worked! I did it using if and else. And yet, another question. Is there another way to do this? :)
User Avatar
8 years ago
Auto-translated
Is there a way to disable cheats on a map?

Added after 37 seconds
For example, a script that kills the main hero when cheats are used?
In reply to AstralLein
User Avatar
8 years ago
Auto-translated
AstralLein
Is it possible to disable cheats on a map?

Added 37 seconds ago
For example, a script that kills the main hero when cheats are used?
You can try removing the changes that make it possible to open the console and enter commands into it, using the consoleCmd function.
Something like
consoleCmd('unbind show_console')
or
consoleCmd('setvar dev_console_password = ')
and do this, for example, in an infinite loop.
I haven't tested this, but in theory, it should work.

And most importantly: such an anti-cheat script can also be easily removed from the map's main script if desired.

Added 1 hour 8 minutes ago
Cirillo
Another question arose. How can I make it so that one function is triggered the first time a region is visited, and a different one the second time? Someone already asked about this on the forum, but I couldn't find it.

It worked! I did it using if and else.

But still, is it possible to do this in another way? :)
I think using if is the most correct and logical option. But you can also set a trigger to call the first function and, already in it, reassign it to the second.
User Avatar
8 years ago
Auto-translated
Could you write the script itself in an infinite loop?
8 years ago
Auto-translated
In my opinion, using an if statement is the most correct and logical approach. However, you could also set a trigger to call the first function and, within that function, reassign it to the second.

How can I correctly write this in Lua? Could you provide a small example?

And here's another issue. Why does a map with a dialogue scene work normally the first time, but when the map is launched again, the game crashes when the dialogue starts playing. If you remove the script that starts the dialogue, everything works fine. I don't know what to do.
User Avatar
8 years ago
Auto-translated
Could you write the script in an infinite loop?
function foo()
  while 1 do
    -- insert code here
    sleep(10);
  end
end

startThread(foo)
How can I make it so that one function is triggered the first time a region is visited, and another function is triggered the second time?
region_visit_counter = 0;

function foo()
  region_visit_counter = region_visit_counter + 1;
  if (region_visit_counter == 1) then
    -- first visit, call the appropriate function
  else
    -- all subsequent visits, call a different function
  end
end
8 years ago
Auto-translated
Thank you!
In reply to Ment
8 years ago
Auto-translated
Is it possible to create a script so that an enemy hero stays in a castle and builds up an army? And also, so that when you enter a certain territory, a battle starts with the creatures that the hero has deployed, but these creatures remain on the map as individual units, while in battle, they form large stacks. And one more thing: disable the purchase of heroes in castles for everyone and remove the Astral Gate and Portal to Town spells from the map.

Added 3 minutes later
Also, I set a quest in the Oracle's Hut, chose the reward type as "army," but where do I specify which creatures to give?

Added 6 minutes later
And also, how do I set a specific number of creatures in the Crypt?
User Avatar
8 years ago
Auto-translated
The anti-cheat script isn't working. I tried both options.

Added 2 minutes ago
Moreover, the issue seems to be with the script itself, as I substituted the "enable_cheats" command into the script for testing purposes. And nothing happened.

Added 2 minutes ago
Also, here's another script. Every last day of the month, the hero gains 2 points in magic. How can I implement this condition?
User Avatar
8 years ago
Auto-translated
Each hero gains 2 points to magic at the very last day of the month. How do I implement this condition?
Do you mean checking if it's currently the last day of the month? For example, like this:
if ((GetDate(WEEK) == 4) and (GetDate(DAY_OF_WEEK) == 7)) then ...
I want these creatures on the map to appear as single units but have larger stacks in battle.
In the editor, disable their weekly growth; remove the standard touch handler from the scripts and replace it with your own. I recently provided a link explaining how to do this. In your custom handler, launch any kind of battle using StartCombat(). This function also has the ability to specify a callback (the name of another function that will be called after its completion, i.e., after the battle). In this callback, check if the hero won and delete the corresponding unit.
How can I disable Astral Gate and Portal to Town spells on the map?
In the map settings within the editor, there is a "Spells" tab where you can remove unnecessary ones.
I set up a quest at the Seer's Hut and chose "Army" as the reward type. Where do I enter which creatures to give?
Try right-clicking on the item related to the reward type or the one following it; there should be an "Add" option in the menu. All of this was described in great detail in one of the official manuals included with the game files.
Also, how do I set a specific number of creatures in a Crypt?
Crypt, are you referring to a treasure chamber? Either through modding by editing the game resources, or again, remove the standard handler, implement your own, and trigger any desired battle via StartCombat().

Statistics

Welcome our newest member: recijeb