Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
#2069
Auto-translated
Knight of the Abyss, if you have one, please share a script guide. The last parameter of triggers is the name of the function that should be called when the trigger is activated. To clear it, you need to insert nil instead of the name:
setting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1","Question");
deleting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);

A similar error exists in your first example with the message box.
User Avatar
#2071
Auto-translated
Jack_of_shadows
Knight of the Abyss, if you have it, please refer to the script guide. The last parameter of triggers is the name of the function that should be called when the trigger is activated. To disable it, you need to insert "nil" instead of the name:
setting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1","Question");
deleting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);

A similar error in your first example with the message box.

Thank you for pointing out the errors, I will take them into account. Apparently, either I wasn't reading carefully enough, or the trigger manual didn't catch my eye... I didn't know.

But in the second case, the trigger still doesn't want to be disabled; it constantly demands money when passed. I've tried everything, inserting Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil); after QuestionBox, at the end of the "yes" function, and even tried creating a separate OBJECT_CAPTURE_TRIGGER so that when "gar1" is transferred to the first player, Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil); would be executed along with this OBJECT_CAPTURE_TRIGGER, but nothing helps...

Added 6 minutes later
Of course, there is an option to press "cancel" and calmly continue without paying, but this trigger that cannot be disabled is still very annoying...
User Avatar
#2072
Auto-translated
Use the console, try simply typing this into it before entering the region:
@Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);
and check if the trigger activates. Perhaps some error will appear, for example, due to a typo.
In reply to Jack_of_shadows
User Avatar
#2073
Auto-translated
Jack_of_shadows
Use the console, try simply typing this into it before entering the region:
@Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);
and check if the trigger activates. Perhaps some error will appear, for example, due to a typo.

Thank you very much for the advice. Strangely, neither the console nor the HOMM5 script editor reported any errors, but the reset didn't work. I placed sleep(5) after the question box and then the reset, and it started working, although I don't understand why sleep was needed there...

And one more question. How can I create a function that checks whether a player has visited a region? I don't want to write 5 different quests for 5 regions and do everything through REGION_ENTER_AND_STOP_TRIGGER. I would like to do everything through one quest... Thank you very much in advance.
User Avatar
#2074
Auto-translated
Abyssal Knight, using additional flags. I used to do similar things like this (the code isn't complete, but it illustrates the principle):
-- table storing region names and visit flags
region_table =
{
{name = 'NAME_OF_THE_FIRST_REGION', visited = 0},
{name = 'NAME_OF_THE_SECOND_REGION', visited = 0},
...
};

-- initialization function
function RegionInit()
for i, region in region_table do
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, 'RegionVisit');
end
end

-- unified visit function
function RegionVisit(hero)
-- check which region we are in
for i, region in region_table do
if(IsObjectInRegion(hero, region.name)) then
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, nil);
region.visited = 1;
-- here you can do what you need, depending on the region number (variable i is the number in the region_table table)
end
end
end

-- returns true if the region with the name name has been visited
function IsRegionVisited(name)
for i, region in region_table do
if((region.name == name) and (region.visited == 1)) then
return true
end
end
return nil
end
In reply to Jack_of_shadows
User Avatar
#2075
Auto-translated
Jack_of_shadows
Abyss Knight, using additional flags. I used to do similar things like this (the code isn't complete, but it illustrates the principle):
-- table storing region names and visit flags
region_table =
{
{name = 'NAME_OF_THE_FIRST_REGION', visited = 0},
{name = 'NAME_OF_THE_SECOND_REGION', visited = 0},
...
};

-- initialization function
function RegionInit()
for i, region in region_table do
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, 'RegionVisit');
end
end

-- unified visit function
function RegionVisit(hero)
-- check which region we are in
for i, region in region_table do
if(IsObjectInRegion(hero, region.name)) then
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, nil);
region.visited = 1;
-- here you can do what you need, depending on the region number (variable i is the number in the region_table table)
end
end
end

-- returns true if the region with the name name has been visited
function IsRegionVisited(name)
for i, region in region_table do
if((region.name == name) and (region.visited == 1)) then
return true
end
end
return nil
end

I would never have come up with that myself, thank you so much!

I apologize, but what can I do, I'm just a newbie... My last question.

So, please tell me how to make it so that when all 5 regions from the table are visited, the quest to visit these regions is completed? I understand that this needs to be done using NEW_DAY_TRIGGER and startThread, but I don't have enough brainpower to figure out how to implement it all...
User Avatar
#2076
Auto-translated
Abyssal Knight, it would probably be most logical to check this directly during the visit, i.e., add a global variable storing the number of visits: `
region_visit_cnt = 0;
` increment it and check it after the line `region.visited = 1;`
region_visit_cnt = region_visit_cnt + 1;
if(region_visit_cnt >= 5) then
SetObjectiveState(QUEST_NAME, OBJECTIVE_COMPLETED);
end
User Avatar
#2077
Auto-translated
Jack_of_shadows Thanks!). Could you tell me how to make an event in NEW_DAY_TRIGGER happen once every two weeks? I understand how to make it happen once a week or once a month, but I think I need a formula to make it happen once every two weeks...
#2079
Auto-translated
Hello! I'm a complete beginner and don't understand anything about scripts, so I would like to know... How can I make enemies automatically attack a town? That is, so that they don't gather resources, fight monsters, etc., but go straight to the town.
In reply to Pert17
User Avatar
#2080
Auto-translated
Pert17
Hello! I'm a complete beginner, I don't understand anything about scripts, so I would like to know... How can I make enemies automatically attack a city? That is, so that they don't collect resources, don't fight with mobs, etc., but immediately go to the city.

Well, there are a few options.

You can paint over all the resources and mobs in the regions and prevent the computer from attacking these regions using the SetRegionBlocked script. This is time-consuming, but it guarantees 100% that it will not touch these resources, and it will have no choice but to run to the city. But there is no guarantee that it will 100% run to the city; if it is too dangerous for it, it will simply stand still or run around its territory. This is the most dubious option.

You can place a hero on the map and use EnableHeroAl and MoveHero to direct him to the city. This is a good option; the hero will not collect resources and will definitely attack the city, even if he has only 1 skeleton in his army, but it is not universal because after the hero dies, he will not attack again. This is a good option if you need to make an attack on your city at the start of the map.

You can place the hero in reserve and use NewDayTrigger, EnableHeroAl, and MoveHero to make the enemy's reserved hero attack your castle after a certain period of time (for example, attack every week).
Pros: it will definitely attack the castle and will not collect resources along the way; it is a universal option; after the hero dies, the attack will be guaranteed to repeat after a certain period of time.
Cons: it requires the most work.

Which option do you like best?

Added after 15 minutes
RedHeavenHero
mod(GetDate(), 14) == 1

Thank you very much.

And could you also tell me:

1) Is it possible to make it so that when a hero's mana drops below 10, the player loses? (well, as if the hero is a Necromancer and needs to have 10 mana to sustain his life, otherwise he will die). There is a similar script in the campaign for Ilia, where the player loses when the black dragon is lost; maybe it is possible to do the same for a decrease in the amount of mana...

2) What script can be used to transfer all the AI's property to the player's control? For example, in the last mission for Frida, when you save Duncan, all the turquoise property is transferred to the blue. I searched through the manuals, but I didn't see anything about this. Thank you very much in advance!
In reply to Рыцарь Бездны
User Avatar
#2081
Auto-translated
1)
function CheckMana()
while GetHeroStat("hero_name", STAT_MANA_POINTS) >= 10 do
sleep(5)
end
Loose()
end

startThread(CheckMana)
2) You can see it in the map itself. It uses the functions GetObjectNamesByType and SetObjectOwner.

Added 2 hours 37 minutes ago
function change_all_owners()
local types = {'BUILDING', 'TOWN', 'HERO', 'DWELLING'}
for i, type in types do
for j, object in GetObjectNamesByType(type) do
if GetObjectOwner(object) == OLD_OWNER then
SetObjectOwner(object, NEW_OWNER)
end
end
end
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
#2082
Auto-translated
RedHeavenHero
1)
function CheckMana()
while GetHeroStat("hero_name", STAT_MANA_POINTS) >= 10 do
sleep(5)
end
Loose()
end

startThread(CheckMana)
But what if the mana decreases during a battle and then is replenished with a spell? Wouldn't the script not work then?
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
User Avatar
#2083
Auto-translated
In such a situation, it really won't work.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
#2084
Auto-translated
Knight of the Abyss, In general, the third option seems to be the best, but I don't really understand scripts; I only started working with them a few days ago. The only thing I can do is create a script with the player's starting capital... So, could you write out exactly what the script would look like? I would be very grateful... And also, here's another thing... If a hero (even an enemy hero) is without a castle, the player loses after a week. Is there a way to remove this function? So that there wouldn't be a mission like "Capture any town within a week." And how do I make the AI attack on day 2, 3, 4, etc.? That is, not immediately.

Statistics

Welcome our newest member: Emil