Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Нибрус
User Avatar
Auto-translated
Nibruus
Help me!
As soon as I create a script (a simple one, for attack animation), the map editor crashes.

Are you writing the script inside the editor? I advise you to use a separate program for this, because the editor itself crashes constantly. It's called HoMM5MapScriptsEditor.
Автор карт:
Долина расхитителей
Выбор мира
In reply to OrnsteinDragonslayer
User Avatar
Auto-translated
Personally, I find it inconvenient to use this program. Just copy the text before closing the window, and if it crashes, paste it back in.
User Avatar
Auto-translated
Best regards!

Here is the code:
local slot = -1;
local i_count = 0;
local id, count;
local temp_name = NHF_tempName_F("Nemor");
local count_umertvie = GetHeroCreatures("Nemor", CREATURE_WIGHT);
if count_umertvie > 0 then
for i = 0,6 do
id, count = GetObjectArmySlotCreature(temp_name,i);
if id == CREATURE_WIGHT then
slot = i;
end;
if count == 0 then
i_count = i_count + 1;
end;
end;
if i_count == 6 then
AddHeroCreatures("Nemor", CREATURE_SKELETON , 1);
sleep();
RemoveHeroCreatures("Nemor", CREATURE_WIGHT, count_umertvie);
sleep();
AddHeroCreatures("Nemor", CREATURE_BANSHEE , count_umertvie,slot);
sleep();
RemoveHeroCreatures("Nemor", CREATURE_SKELETON, 1);
sleep();
else
RemoveHeroCreatures("Nemor", CREATURE_WIGHT, count_umertvie);
sleep();
AddHeroCreatures("Nemor", CREATURE_BANSHEE , count_umertvie,slot);
sleep();
end;
end;

In Multiplayer mode, the Wights are immediately replaced with Banshees. In Singleplayer mode, to see the change, you need to exit and re-enter the hero interface. Is it possible to fix this?
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to AlekseyS
User Avatar
Auto-translated
check out the strip mines on the Echo of the Void map; there's a combat script in the city there.
Auto-translated
Here's the code:
function dwellings()
for i, dw_type in {"FAIRIE_TREE", "WOOD_GUARD_QUARTERS", "HIGH_CABINS", "PRESERVE_MILITARY_POST"} do
for j, dw in GetObjectNamesByType(dw_type) do
ELF_DWLS[dw] = "off"
SetObjectEnabled(dw, nil)
Trigger(4, dw, "TransformDwelling")
end
end
startThread(dwellings2)
end

startThread(dwellings)

function dwellings2()
while 1 do
repeat
sleep()
until IsPlayerCurrent(1)
for dwelling, state in ELF_DWLS do
if state == "on" then
ELF_DWLS[dwelling] = "off"
SetObjectEnabled(dwelling, nil)
Trigger(4, dwelling, "TransformDwelling")
end
end
repeat
sleep()
until not IsPlayerCurrent(1)
for dwelling, state in ELF_DWLS do
if state == "off" then
ELF_DWLS[dwelling] = "on"
SetObjectEnabled(dwelling, 1)
Trigger(4, dwelling, nil)
end
end
end
end

function TransformDwelling(hero, hut)
if GetCurrentPlayer() == 1 then
QuestionBox (path.."transformd.txt" , 'transformnok("'..hut..'")' );
end
end

function transformnok(hut)
if not (GetPlayerResource(1, CRYSTAL) >= 15 and GetPlayerResource(1,GEM) >= 10) then
ShowFlyingSign(path.."nores.txt",hut,-1,10)
return
end
SetPlayerResource(1,CRYSTAL, (GetPlayerResource(1,CRYSTAL) - 15))
SetPlayerResource(1,GEM, (GetPlayerResource(1,GEM) - 10))
PlayVisualEffect('/Effects/_(Effect)/Spells/Bless.xdb#xpointer(/Effect)', hut)
sleep(5)
Trigger(4, hut, nil)
ELF_DWLS[hut] = nil
ReplaceDwelling(hut,TOWN_HEAVEN)
sleep(1)
SetObjectOwner(hut,1)
SetObjectEnabled(hut,true)
sleep(1)
return function()
end
end

I need to make it so that if one quest is active or incomplete, then the building upgrade is allowed, but if it's completed, then it's not. So, could you please tell me where I should add the check?
Карты: Экспедиция ГрувераНаследие ШантириВременной парадоксПоиски рунной сферыПуть возвращения
User Avatar
Auto-translated
function TransformDwelling(hero, hut) local state = GetObjectiveState('required_quest') if GetCurrentPlayer() == 1 and (state == OBJECTIVE_ACTIVE or state == OBJECTIVE_FAILED) then QuestionBox (path.."transformd.txt" , 'transformnok("'..hut..'")' ); end end ``` Something like this, if I understood the conditions correctly.
Нет войне.
In reply to Gerter
Auto-translated
Gerter
function TransformDwelling(hero, hut)
local state = GetObjectiveState('required_quest')
if GetCurrentPlayer() == 1 and (state == OBJECTIVE_ACTIVE or state == OBJECTIVE_FAILED) then
QuestionBox (path.."transformd.txt" , 'transformnok("'..hut..'")' );
end
end

Something like this, if I understood the conditions correctly.

Everything works, thank you.
Карты: Экспедиция ГрувераНаследие ШантириВременной парадоксПоиски рунной сферыПуть возвращения
User Avatar
Auto-translated
Hello. Perhaps someone can help with finding the right solution for a script:
Basically, there is a specific group of creatures that need to be destroyed as part of a task. At the same time, on a specific game day, a check needs to be performed to see if they still exist, in order to indicate whether the task has been completed or not. If some of these creatures are still on the map, they should be transferred to the army of a specific hero. I know that something similar was implemented in the first mission of Frida's campaign, but unfortunately, I don't understand how it was done there.
In reply to Grigoriy
User Avatar
Auto-translated
Grigoriy
Hello. Maybe someone can help me with the script and suggest the right solution:
Basically, there is a certain group of creatures that need to be destroyed as part of a task. At the same time, on a specific game day, a check needs to be performed to see if they still exist, in order to indicate whether the task has been completed or not. And if some of these creatures are still on the map, they should be transferred to the army of a specific hero. I know that something similar was implemented in the first mission of Frida's campaign, but unfortunately, I don't understand how it was done there.

Okay, I don't know what your general knowledge of scripts is, so I'll try to explain it simply:

First, you need to assign script names to the required units in the editor and configure them so that they reliably join the heroes of the player you need (the necessary items are highlighted in the screenshot).



Then, in the script, for convenience, create a table through which the presence of units on the map will be determined:
stacks = {'script_name_of_unit_1', 'script_name_of_unit_2'... and so on

Then, use a new day trigger to check for the existence of units daily:
function NewDay()
if GetDate(DAY) == 'day when the check needs to be performed' then
-- then check for the existence of units and transfer them to the desired hero
for i, stack in stacks do
if IsObjectExists(stack) then
MakeHeroInteractWithObject('Script_name_of_the_desired_hero', stack)
end
end
end
end

Trigger(NEW_DAY_TRIGGER, 'NewDay')
Attachments 1
1 file attached • Total size: 9.9 KB
Нет войне.
In reply to Gerter
User Avatar
Auto-translated
Gerter
Okay, I don't know what your general knowledge of scripts is, so I'll try to explain it simply:

First, you need to assign script names to the desired units in the editor and configure them so that they are guaranteed to join the heroes of the player you want (the relevant items are highlighted in the screenshot).



Then, in the script, for convenience, create a table through which it will determine the presence of units on the map:
stacks = {'script_name_of_unit_1', 'script_name_of_unit_2'... and so on

Then, use a new day trigger to check daily for the existence of units:
function NewDay()
if GetDate(DAY) == 'day when the check needs to be performed' then
-- further check for the existence of units and transfer to the desired hero
for i, stack in stacks do
if IsObjectExists(stack) then
MakeHeroInteractWithObject('Script_name_of_the_desired_hero', stack)
end
end
end
end

Trigger(NEW_DAY_TRIGGER, 'NewDay')

Thank you for the answer.
I didn't know that it is possible to set different attitudes of a creature towards different players.
I created the table of creatures shown above, but the specified creatures may be destroyed before the specified time, according to the quest, which means, as I understand it with my poor mind, I still need a function to check for the existence of these creatures in principle, in order to complete the task before the specified day
User Avatar
Auto-translated
well, it's simple, you create a check thread: ``` function CheckStacks() while 1 do local x for i, stack in stacks do if IsObjectExists(stack) then x = not nil end end if not x then SetObjectiveState('desired_quest', OBJECTIVE_COMPLETED) break end if GetDate(DAY) == desired_day then break end sleep() end end startThread(CheckStacks)
Нет войне.
In reply to Gerter
User Avatar
Auto-translated
Gerter
It's simple, you create a check loop:
function CheckStacks()
while 1 do
local x
for i, stack in stacks do
if IsObjectExists(stack) then
x = not nil
end
end
if not x then
SetObjectiveState('desired_objective', OBJECTIVE_COMPLETED)
break
end
if GetDate(DAY) == desired_day then
break
end
sleep()
end
end

startThread(CheckStacks)

Okay. Thank you very much.

Statistics

Welcome our newest member: Emil