Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
1 year ago
Auto-translated
Write to me in PM, and we'll figure it out.
I'll give you a hint about the main parts of the script:
1. A message displayed in a MessageBox with a callback – your transformation function.
2. The transformation function itself consists of:
- a table with creature correspondences
- removing creatures using RemoveObjectCreatures
- adding corresponding creatures using AddObjectCreatures.

Try to implement it yourself, and if you have any specific questions, write them!
In reply to }{0TT@6bI4
1 year ago
Auto-translated
So far, I’ve only managed to implement this idea on a limited scale, using the most essential creatures as an example. Since I’m not very good at coding, I often have to avoid loops and tables, but here the amount of data is such that it’s impossible to avoid iterating through the table elements using a loop. Here’s what I don’t understand:
1. In addition to creating a table for the creatures, I need to create a table for the conversion cost, which includes gold and other resources. How can I ensure that the values from the first table correspond to the values from the second table, and combine all of this within a loop? Or is there a function that returns the necessary resources for purchasing a creature?
2. How can I implement the ability to select the creature that will be obtained as a result of the conversion? I had the idea to use the GetObjectArmySlotCreature function, but as it turned out, it doesn’t work on my exe.
In short, I would like to see this script working with a few creatures as an example.
User Avatar
1 year ago
Auto-translated
In the second table, the creature ID will be the key, and the fields will represent the conversion cost. After determining, based on the first table, which creature needs to be converted into (we obtain its ID), we find the conversion cost in the second table using that ID.

If the window with multiple answer options doesn't work for you (see the FAQ by Jack_of_Shadows), then it won't be possible to implement a proper selection between multiple options.
In reply to }{0TT@6bI4
1 year ago
Auto-translated
Thank you for your help; I managed to figure it out somehow. I had to implement the creature selection option by checking for the presence of specific creatures in the garrison. It's a workaround, but it works.
User Avatar
9 months ago
Auto-translated
Hello! Starting today, I've begun creating specializations for my mod. I've implemented three:
1. Valeria - gains +1 defense for every two levels.
2. Bertrand - receives 1 zealot of faith daily.
3. Duncan - receives artifacts from the "Lionheart" set at levels 6, 10, and 16, and the morale of creatures is always 5.

I wanted to create a specialization for Alaric - when the hero learns a light spell, he receives an equivalent dark magic spell, but it didn't work...

function AlaricSpec()
if KnownHeroSpell("Alaric", SPELL_HASTE) then
TeachHeroSpell("Alaric", SPELL_SLOW)
end
end

but it doesn't work.
User Avatar
9 months ago
Auto-translated
temnyrizar, since there are no triggers for obtaining spells, it's obvious that you need to run the function in a loop in a separate thread, with all sorts of checks to ensure that the hero exists and that it's only given once. That is, the function's overhead is much more complex than the function itself and can be implemented in many different ways (for example, always run a separate thread, or only when the hero appears for the player).
User Avatar
9 months ago
Auto-translated
You need to write a loop that checks for the presence of a spell with a certain periodicity and outputs the corresponding one:
function AlaricSpec()
  while 1 do
    if ... then

    end
  sleep(1)
  end
end
In reply to }{0TT@6bI4
User Avatar
9 months ago
Auto-translated
}{0TT@6bI4
We need to write a loop that periodically checks for the presence of a spell and outputs the corresponding message:
function AlaricSpec()
while 1 do
if ... then

end
sleep(1)
end
end

Okay, progress is being made... now it writes "Trigger not found" in the console, and before that, it just said that the hero has no army.
User Avatar
9 months ago
Auto-translated
Please provide the code. Otherwise, it's unclear how you wrote the trigger and what the army has to do with casting spells. 😅
In reply to }{0TT@6bI4
User Avatar
9 months ago
Auto-translated
}{0TT@6bI4
Please provide the code. Otherwise, it's unclear how you wrote the trigger and what the army has to do with casting spells?

When you place a hero without an army in the editor, the console displays a message saying that he has no army.

I simply added what you wrote to the code...
when i do
my code
end
sleep (1)
User Avatar
9 months ago
Auto-translated
Well, this isn't an error, but a warning that can be ignored. Regarding the "Trigger not found" message, please provide the complete code. The error is clearly related to triggers, which are not present in the example.
In reply to }{0TT@6bI4
User Avatar
9 months ago
Auto-translated
}{0TT@6bI4
Well, this isn't an error, but a warning that can be ignored.

Regarding "Trigger not found," please provide the entire code. The error is clearly related to triggers, which are not present in the example.

function AlaricSpec()
  while 1 do
    if KnownHeroSpell("Alaric", SPELL_HASTE) then
TeachHeroSpell("Alaric", SPELL_SLOW)
    end
  sleep(1)
  end
end
In reply to temnyrizar
User Avatar
9 months ago
Auto-translated
temnyrizar

function AlaricSpec()
  while 1 do
    if KnownHeroSpell("Alaric", SPELL_HASTE) then
TeachHeroSpell("Alaric", SPELL_SLOW)
    end
  sleep(1)
  end
end

The function **Know**HeroSpell, not Known. The following code works, I checked it:
function AlaricSpec()
while 1 do
if KnowHeroSpell("Alaric", SPELL_HASTE) then
TeachHeroSpell("Alaric", SPELL_SLOW)
end
sleep(1)
end
end

startThread(AlaricSpec)

The "Trigger not found" error in the console is not related to this code. You probably have an error in the trigger somewhere earlier, which interrupts the further execution of the script - including Alaric's specialization. Look for where you made a mistake in the trigger name!

In reply to }{0TT@6bI4
User Avatar
9 months ago
Auto-translated
}{0TT@6bI4
The KnowHeroSpell function is not working as expected. The following code works, I have verified it:
function AlaricSpec()
    while 1 do
      if KnowHeroSpell("Alaric", SPELL_HASTE) then
        TeachHeroSpell("Alaric", SPELL_SLOW)
      end
    sleep(1)
    end
end

startThread(AlaricSpec)

The "Trigger not found" error in the console is not related to this code. It is likely that you have an error in a trigger earlier in the script, which is interrupting the further execution of the script, including Alaric's specialization. Look for where you made a mistake in the trigger name!



The error appeared specifically when Alaric's specialization was in the code. After removing it from the code, the error disappeared. I will check it later.
In reply to temnyrizar
8 months ago
Auto-translated
Hello, could you please tell me if it's possible to use scripts to block the ability to acquire a specific skill or two when choosing a skill?

Statistics

Welcome our newest member: recijeb