Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
Guys, I need some help:
How can I make it so that when a hero enters a region, the number of all their creatures is reduced by half? Thanks in advance.

The simplest solution is to apply something like this to the region:
for slot = 0, 6 do
local creature, count = GetObjectArmySlotCreature(hero, slot)
if not (creature == 0 or count == 0) then
RemoveHeroCreatures(hero, creature, count/2)
end
end
Нет войне.
User Avatar
Auto-translated
Hello everyone! Can you help me figure out how to increase the number of action points for a hero?
User Avatar
Auto-translated
It is known that the "RazeTown" spell can be used to destroy a town. But can it be used in reverse? For example, if there are ruins on the map initially, and upon fulfilling a certain condition, the ruins are replaced with a functioning town.
Лишь тот в советах – солнце, в битвах – лев, кто разумом смирять умеет гнев.
In reply to Valkar
Auto-translated
I need the reserved hero to appear at the beginning of the second week of the month, but a quest should also be triggered at the same time. The quest is triggered, but the hero (as I already mentioned) does not appear.
function Blue ()
SetObjectiveState("blue", OBJECTIVE_ACTIVE);
local MONTH=GetDate (2)
if day == 0
then DeployReserveHero ("Maeve", 66, 3, 0, 0)
sleep (5)
MoveCamera (66, 3, 0, 50, 0, 0, 1, 1)
end ;
end;
User Avatar
Auto-translated
Is there a way to enable/disable object highlighting (the one that appears when Alt is held down) through code? I'm sure there's no script for it, but maybe there's a console command?
Нет войне.
In reply to Gerter
User Avatar
Auto-translated
Gerter
Is there a way to enable/disable object highlighting (the one that appears when you hold down Alt) using code? I know there's no script for it, but maybe there's a console command?

If such a cheat existed, we would have known about it long ago, and frankly, it's a necessary evil in a game like Heroes, especially in its 3D iteration.

I'm having a different issue, though. I'm trying to implement a quest with two possible solutions: one involves paying gold and waiting a certain number of days, and the other involves finding and destroying a specific creature. The waiting period isn't working correctly; the script just won't execute, no matter how I try to modify it, and there are no errors in the console.
Script:
centHero = ""

SetObjectEnabled("cent0", nil);
SetDisabledObjectMode("cent0", DISABLED_INTERACT);
sleep(1);

function Centaurquest(heroname)
if GetCurrentPlayer()==1 and centavr == 0 then
StartAdvMapDialog( 2 );
sleep(5);
centavr = 1;
trader = 1;
MessageBox("Maps/SingleMissions/orcs2/centtext10.txt");
elseif GetCurrentPlayer()==1 and centavr == 1 and trader == 1 then
MessageBox("Maps/SingleMissions/orcs2/centtext1.txt");
elseif GetObjectOwner( heroname ) == PLAYER_1 and centavr == 1 and trader == 3 then
centHero = heroname
QuestionBox("Maps/SingleMissions/orcs2/centtext4.txt", "Centaurquestcomplite");
elseif GetCurrentPlayer()==1 and centavr == 2 then
MessageBox("Maps/SingleMissions/orcs2/centtext2.txt");
end;
end;

function Centaurquestcomplite()
if HasArtefact( centHero, 17 ) == true then
StartAdvMapDialog( 3 );
sleep(1);
PlayObjectAnimation( "cent0", "happy", ONESHOT );
sleep(1);
RemoveArtefact( centHero, 17 );
SetTownBuildingLimitLevel("port", TOWN_BUILDING_DWELLING_2, 2);
centavr = 2;
elseif HasArtefact( centHero, 17 ) == false then
MessageBox("Maps/SingleMissions/orcs2/centtext3.txt");
end;
end;

function Centaurquesttrader()
if GetCurrentPlayer()==1 and centavr == 1 and trader == 1 then
QuestionBox("Maps/SingleMissions/orcs2/centtext5.txt", "Traderyes", "Traderno");
end;
end;

function Traderyes()
if GetPlayerResource(PLAYER_1, GOLD) >= 10000 then
dealtime = GetDate(ABSOLUTE_DAY);
SetPlayerResource(PLAYER_1, GOLD, GetPlayerResource(PLAYER_1, GOLD) - 10000 );
sleep(1);
trader = 2;
RemoveObject("thief");
sleep(1);
elseif GetPlayerResource(PLAYER_1, GOLD) < 10000 then
MessageBox("Maps/SingleMissions/orcs2/ubivectext6.txt");
end;
end;

Trigger(NEW_DAY_TRIGGER, 'TradeDay');
function TradeDay()
if ((GetDate(ABSOLUTE_DAY) - dealtime) == 4) then
MessageBox("Maps/SingleMissions/orcs2/centtext8.txt");
GiveArtifact("главныйгерой", 17);
trader = 3;
end;
end;

function Traderno()
MessageBox("Maps/SingleMissions/orcs2/centtext7.txt");
end;

function Thiefdead()
while 1 do
sleep(10);
if IsObjectExists ("thief") == nil and trader == 0 then
MessageBox("Maps/SingleMissions/orcs2/centtext9.txt");
trader = 3;
break;
elseif IsObjectExists ("thief") == nil and trader == 1 then
MessageBox("Maps/SingleMissions/orcs2/centtext9.txt");
trader = 3;
break;
elseif IsObjectExists ("thief") == nil and trader == 2 then
MessageBox("Maps/SingleMissions/orcs2/centtext6.txt");
break;
end;
end;
end;

startThread( Thiefdead );
User Avatar
Auto-translated
Grigoriy, it's not a very good idea to post a hundred lines of code and ask people to find the error in it. For starters, just add print statements in each function and inside each if statement.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
Grigoriy, it's not a very good idea to post a hundred lines of code and ask people to find the error in it. For starters, just add print statements in each function and inside each if statement.

I'll keep that in mind for the future, thank you. In the meantime, the script is working as it should; I just needed to place the trigger for the new day after the function, not before it. It's quite interesting.
Auto-translated
Hi, do you remember in the last mission for Arantir, there were cities where you could only upgrade creatures to one level? I have three questions:
1. How do you do that?
2. Can this be done with other factions?
3. Can you only upgrade to the 1st level, and not the 2nd?
In reply to thenekoor
User Avatar
Auto-translated
thenekoor
Hi, do you remember in the last mission for Arantir, there were cities where you could only upgrade creatures to one level? I have three questions.
1. How do I do that?
2. Can this be done for other factions?
3. Can I only allow the 1st upgrade, and not the 2nd?
In the editor, select the city, and on the left in the properties tree, find CreaturesUpgradesFilter, and expand it. To prevent the 1st upgrade, add lines to ForbiddenBasicUpgradeTiers (right-click - Add) and enter the level of the desired creature in them. Accordingly, to prevent the entire upgrade path, you need to add 7 elements and specify levels from 1 to 7 in them. ForbiddenAlterUpgradeTiers - it's all the same, only for preventing the 2nd upgrade. You can also combine them.

Added 23 hours 32 minutes later
Has anyone encountered this, or does anyone have any ideas?
The game crashes when using MoveHeroRealTime or even CalcHeroMoveCost on an adjacent, empty cell. It doesn't crash at the beginning of the map, but in the second half, closer to the end.
Сюжетные карты:
Охотник на чудовищ
Проклятый
User Avatar
Auto-translated
I can assume that the game struggles with a large number of functions, such as the talkbox. And based on my observations, functions related to calculating moves also put a significant load on the game – if, for example, you run CalcHeroMoveCost in an infinite loop, the game will start to noticeably lag. And while the game might still handle it at the beginning, it may run out of resources closer to the end of the map, which could be the cause of the crashes. But these are just assumptions, I can't say for sure.
Нет войне.
User Avatar
Auto-translated
So, what are the terms of use? Could adding values to the table cause a memory leak?
I wouldn't be afraid of Talkbox. It works like a charm.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Gerter
User Avatar
Auto-translated
Jack_of_shadows
So, what are the usage conditions? Maybe adding values to the table causes a memory leak?
If we're talking specifically about CalcHeroMoveCost, you can just write it to the console, and the game will crash.
It's hard to say about the part of the map that has already been traversed; there are many factors involved. I tried to reproduce the bug twice, going to the point of the crash with the same conditions, and it worked normally both times.
Gerter
And based on my observations, the functions related to calculating the turn also put a significant load on the game – if, for example, you run CalcHeroMoveCost in an infinite loop, the game will start to noticeably lag. And if at the beginning the game can still handle it, then closer to the end of the map, it may run out of resources, hence the crashes.
That sounds reasonable; I'll try running MoveHeroRealTime more often at the beginning and in the middle of the map, maybe something will happen.

Added 1 hour 49 minutes ago
No, no matter how hard I tried, I couldn't trigger a crash manually.
Сюжетные карты:
Охотник на чудовищ
Проклятый
In reply to Gerter
User Avatar
Auto-translated
Gerter
Is there a way to enable/disable object highlighting (the one that appears when Alt is held down) through code? There's definitely no script for it, but maybe there's a console command?
If it's still relevant:
the command ui_adventure_hilight_radius 0 disables the highlighting; to re-enable it, replace 0 with a value greater than 0.
It's best to use the value that was originally set.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
If it's still relevant: the command ui_adventure_hilight_radius 0 disables the highlight. To re-enable it, replace 0 with a value greater than 0. It's best to use the value that was originally set.
I tried this command, but it doesn't work, unfortunately. I was interested in the possibility of enabling the highlight effect in the game, i.e., simulating pressing the Alt key, but it seems that this is not possible.
Нет войне.

Statistics

Welcome our newest member: Emil