Skip to content
User Avatar
#1328
Auto-translated
Heroist
Thank you, it helped.

Added 7 minutes ago
Well, and (I really hope) this is my last question for today:

Dear RedHeavenHero, here is a slightly modified version of your function for transforming human dwellings.
Basically, I would like all this to start working when a small and modest variable, let's call it 'dwel' in the script, is equal to a proud and rebellious one (dwel = 1). However, due to my poor understanding and complete lack of knowledge of these script functions, I cannot seem to manage and control the rebellious loop with 'for' and so on. I am attaching the code of the current function and hope for a quick solution. =)
function starthut()
if dwel == 1 then
for i,hut in GetObjectNamesByType('PEASANT_HUT') do
SetObjectEnabled(hut, nil)
Trigger(4, hut, 'replace_hut')
end
end
end
startThread(starthut)

function replace_hut(hero, hut)
if hero == 'Berein' and dwel == 1 then
Trigger(4, hut, nil)
SetObjectEnabled(hut, 1)
ReplaceDwelling(hut, 4)
sleep (1)
MakeHeroInteractWithObject (hero , hut)
end
end

----------------------------------------

function starthut2()
if dwel == 1 then
for i,hut2 in GetObjectNamesByType('ARCHERS_HOUSE') do
SetObjectEnabled(hut2, nil)
Trigger(4, hut2, 'replace_hut2')
end
end
end
startThread(starthut2)

function replace_hut2(hero, hut2)
if hero == 'Berein' and dwel == 1 then
Trigger(4, hut2, nil)
SetObjectEnabled(hut2, 1)
ReplaceDwelling(hut2, 4)
sleep (1)
MakeHeroInteractWithObject (hero , hut2)
end
end

----------------------------------------

function starthut3()
if dwel == 1 then
for i,hut3 in GetObjectNamesByType('BARRACKS') do
SetObjectEnabled(hut3, nil)
Trigger(4, hut3, 'replace_hut3')
end
end
end
startThread(starthut3)

function replace_hut3( hero , hut3)
if hero == 'Berein' and dwel == 1 then
Trigger(4, hut3, nil)
SetObjectEnabled(hut3, 1)
ReplaceDwelling(hut3, 4)
sleep (1)
MakeHeroInteractWithObject (hero , hut3)
end
end
--------------------------------------

function starthut4()
if dwel == 1 then
for i,hut4 in GetObjectNamesByType('HEAVEN_MILITARY_POST') do
SetObjectEnabled(hut4, nil)
Trigger(4, hut4, 'replace_hut4')
end
end
end
startThread(starthut4)

function replace_hut4(hero, hut4)
if hero == 'Berein' and dwel == 1 then
Trigger(4, hut4, nil)
SetObjectEnabled(hut4, 1)
ReplaceDwelling(hut4, 4)
sleep (1)
MakeHeroInteractWithObject (hero , hut4)
end
end
If you remove the check for this variable (dwel) in all the starting functions (starthut), the buildings will only transform if this condition is met. Before that, the hero will not be allowed in.
You could use a reference to one function in the triggers, instead of 4 identical ones.

Added 4 minutes ago
Nargott
Am I right in understanding that Lua in Heroes 5 is limited to a certain set of functions defined by the game developers and does not support built-in functions such as setmetatable, package, and module? That is, at best, you can create static classes without supporting the creation of types (object instances of a class)? And simulate modules using the doFile function?
Well, yes, you can say that.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

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