Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
orlan-1, I also haven't encountered any solutions to this problem. I remember when the map editor was first released, it was quite usable, and even if it crashed, it was only occasionally. But then, at some point, with the switch to a different operating system or hardware, it started crashing consistently.
In reply to AstralLein
Auto-translated
What resolution should the image be so that I can create a different avatar for the hero?

Added 34 minutes later
And another question: how do I create a neutral hero? In the Unicorn Empire campaign, there was one in mission 4.
In reply to Годрикова впадина
User Avatar
Auto-translated
And another question - how do you make a neutral hero? In the Unicorn Empire campaign, there was one in mission 4.
SetObjectOwner('hero name', player number that is not on the map);
That is, if you have 2 players on your map, you place the hero in the editor and then write the line above, and instead of "player number that is not on the map," you write PLAYER_3.
User Avatar
Auto-translated
Here is my combat script. It consists of two parts (indicated). The first part is for when the hero is defending, and the second is for when the hero is attacking. I want to fix 3 errors in it: 1) How do I make the human player lose the battle by default? That is, at the beginning, losing/winning is disabled and enabled only when all additional units are summoned. How do I make the human player lose without taking into account the variables dwarf or atdwarf, if all of their units are killed? 2) In the attacking script, the hero first casts a General speed boost. The second spell is not cast on the next turn for some reason. There are no errors in the console. The defending script applies all spells as needed. 3) I noticed that the script gives an error if the hero cannot cast a spell (all creatures are immune to the spell). How can I fix this? That is, so that it does not cast the spell if there is no one to cast it on? diff = GetDifficulty() + 1 dwarf = 0 dwarfspell = 0 atdwarf = 0 atdwarfspell = 0 SetUnitManaPoints(GetDefenderHero(), GetUnitMaxManaPoints(GetDefenderHero())) SetUnitManaPoints(GetAttackerHero(), GetUnitMaxManaPoints(GetAttackerHero())) EnableDynamicBattleMode(nil) EnableAutoFinish(nil) --start of the defending script function DefenderHeroMove(hero) if IsHuman(DEFENDER) == nil then if dwarfspell == 0 then dwarfspell = 1 commandDoSpell(GetDefenderHero(),235,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 2 elseif dwarfspell == 2 then dwarfspell = 3 commandDoSpell(GetDefenderHero(),43,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 4 elseif dwarfspell == 4 then dwarfspell = 5 commandDoSpell(GetDefenderHero(), 221,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 6 elseif dwarfspell == 6 then dwarfspell = 7 commandDoSpell(GetDefenderHero(),216,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 8 elseif dwarfspell == 8 then dwarfspell = 9 commandDoSpell(GetDefenderHero(),212,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 10 elseif dwarfspell > 9 and dwarfspell < 16 then dwarfspell = dwarfspell + 1 SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = dwarfspell + 1 elseif dwarfspell == 16 then dwarfspell = 17 commandDoSpell(GetDefenderHero(),210,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) dwarfspell = 0 end end end sleep(4) function DefenderCreatureDeath(hero) if IsHuman(DEFENDER) == nil then if dwarf == 0 then dwarf = 1 playAnimation(GetDefenderHero(), "cast", ONESHOT) combatSetPause(1) sleep(60) SummonCreature(DEFENDER, CREATURE_DEFENDER, 900 * diff, 15, -1) sleep(70) dwarf = 2 combatSetPause(nil) elseif dwarf == 2 then dwarf = 3 playAnimation(GetDefenderHero(), "cast", ONESHOT) combatSetPause(1) sleep(60) SummonCreature(DEFENDER, CREATURE_WARLORD, 45 * diff, 15, -1) sleep(70) dwarf = 4 combatSetPause(nil) elseif dwarf == 4 then dwarf = 5 playAnimation(GetDefenderHero(), "cast", ONESHOT) combatSetPause(1) sleep(60) SummonCreature(DEFENDER, CREATURE_MAGMA_DRAGON, 20 * diff, 15, -1) sleep(70) dwarf = 6 combatSetPause(nil) end end end function finish() while 1 do local att, def = GetAttackerCreatures(), GetDefenderCreatures() if length(att) == 0 or length(def) == 0 then if dwarf == 6 then EnableAutoFinish(1) break end end sleep(20) end end --start of the attacking script function AttackerHeroMove(hero) if IsHuman(ATTACKER) == nil then if atdwarfspell == 0 then atdwarfspell = 1 commandDoSpell(GetAttackerHero(),221,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 2 elseif dwarfspell == 2 then atdwarfspell = 3 commandDoSpell(GetAttackerHero(),216,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 4 elseif dwarfspell == 4 then atdwarfspell = 5 commandDoSpell(GetAttackerHero(),235,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 6 elseif dwarfspell == 6 then atdwarfspell = 7 commandDoSpell(GetAttackerHero(),212,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 8 elseif dwarfspell == 8 then atdwarfspell = 9 commandDoSpell(GetAttackerHero(),43,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 10 elseif dwarfspell > 9 and dwarfspell < 16 then atdwarfspell = dwarfspell + 1 SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = dwarfspell + 1 elseif dwarfspell == 16 then atdwarfspell = 17 commandDoSpell(GetAttackerHero(),210,-1) SetUnitManaPoints(hero, GetUnitManaPoints(hero) + 4 * diff ) atdwarfspell = 0 end end end sleep(4) function AttackerCreatureDeath() if IsHuman(ATTACKER) == nil then if atdwarf == 0 then atdwarf = 1 playAnimation(GetAttackerHero(), "cast", ONESHOT) combatSetPause(1) sleep(60) SummonCreature(ATTACKER, CREATURE_FLAME_KEEPER, 65 * diff, 15, -1) sleep(60) SummonCreature(ATTACKER, CREATURE_STOUT_DEFENDER, 600 * diff, 15, -1) sleep(70) atdwarf = 2 combatSetPause(nil) end end end function atfinish() while 1 do local att, def = GetAttackerCreatures(), GetDefenderCreatures() if length(att) == 0 or length(def) == 0 then if atdwarf == 2 then EnableAutoFinish(1) atdwarf = 0 break end end sleep(20) end end startThread(finish) startThread(atfinish)
Карты для героев 5

"Плата за любовь"
"Путь некроманта"
"Темные грани"
"Рок Гримхейма"
In reply to AstralLein
Auto-translated
Help, I want to create a script that triggers a battle. After you win with the hero's first army, he says something, and then another, unsummoned army appears.
User Avatar
Auto-translated
1) How can I make the human player lose a battle in a standard way? That is, at the beginning, auto-win/lose is disabled and enabled only when all additional units are summoned. How can I make the human player lose, regardless of the "dwarf" or "atdwarf" variables, if all of their units are killed?
2) In the attacking script, the hero first casts a general speed-up spell. However, on the next turn, he doesn't cast the second spell. There are no errors in the console. The defensive script applies all spells as expected.
3) I noticed that the script throws an error if the hero cannot cast a spell (all creatures are immune to the spell). How can I fix this? That is, how can I prevent him from casting if there is no one to cast it on?
1) Instead of `EnableAutoFinish(1)`, use `Finish(winning_side)` if the number of units of the human player is 0.
2) What spells does he cast in the defensive and attacking parts? It's clear that they are different, but which ones specifically? Perhaps the problem lies in the spell being inapplicable.
3) Wouldn't the spell not be cast anyway when an error occurs? What do you want to happen in the end?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
1. And what will it look like?
2. In order of spells:
Attack
1) General Haste
2) General Blessing
3) Summon Phoenix
4) General Slow
5) Summon Elementals
6) Pause, doesn't cast anything for several turns
7) General Curse
8) Starts over
Defense
1) Summon Phoenix
2) Summon Elementals
3) General Haste
4) General Blessing
5) General Slow
6) Pause for several turns
7) General Curse
8) Starts over
3. Well, in principle, the AI stops using spells and gets stuck in this state. But in general, the chances that the player will have only elementals in their army are small.

Added 22 minutes later
I've tested the spells again. When defending, everything is perfect, but when attacking, it still doesn't work. And the spell is exactly the same. When defending, it easily casts General Blessing.

Added 2 hours 25 minutes later
Regarding point 2. I identified and fixed the bug. The condition check was being performed using an incorrect variable.
Карты для героев 5

"Плата за любовь"
"Путь некроманта"
"Темные грани"
"Рок Гримхейма"
In reply to AstralLein
Auto-translated
How do I limit the map to only 4 players? I just want to add neutral heroes, but I need to remove the other players first.
In reply to AstralLein
User Avatar
Auto-translated
AstralLein
1. How will this look?
3. Well, basically, the AI stops casting spells and gets stuck in that state. But in general, the chances of the player having only elementals in their army are small.
1. Approximately like this:
function finish()
	local human = IsHuman(ATTACKER) and ATTACKER or DEFENDER
	local computer = 1 - human
	while 1 do
		local hum = GetCreatures(human)
		local comp = GetCreatures(computer)
		if length(hum) == 0 then
			Finish(computer)
			break
		end
		if length(computer) == 0 and (atdwarf == 6 or dwarf == 2) then
			Finish(human)
			break
		end
		sleep(20)
	end
end

startThread(finish)
3. You can call spellcasting functions not directly, but through startThread; then, if an error occurs, the script will not crash but will continue to execute. startThread(commandDoSpell, hero, spell, ...)
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to AstralLein
User Avatar
Auto-translated
AstralLein
Rewrote the two initial finish conditions. Now something strange happens. When attacking Hagnar, the battle ends immediately because creatures disappear from both sides...
Then, place startThread(finish) within the Start function.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4

Statistics