Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
Hmm, that's strange. If I use that code, there's no error. I'll try playing around with the console again and post the entire function. I probably focused on the wrong thing...

Added 32 minutes later
Yes, I understand, the error was probably because I deleted the object and then tried to attach a touch trigger to it.

And here's another question: how do I give a hero specific skills?
First, I spent an hour trying to find "Fire Wars" (Elemental Summoning magic). I think I found it in the demon perk, but I'm not sure. Now I don't know how to install it correctly. I'm writing it like this:
if HasHeroSkill ('Berein' , 12) == nil then
GiveHeroSkill ('Berein' , 12)
GiveHeroSkill ('Berein' , 12)
GiveHeroSkill ('Berein' , 53)
GiveHeroSkill ('Berein' , 97)
end

It only gives the enhanced summoning magic... What should I do?

Whatever
In reply to Heroist
User Avatar
Auto-translated
Heroist
Hmm, that's strange. If you write such code, there is no error. I'll try playing around with the console again and post the entire function. I probably focused on the wrong thing...

Added 32 minutes later
yes, I understand, the error was most likely because I deleted the object and then tried to attach a touch trigger to it.

And here's another question: how to give a hero specific skills?
First, I spent an hour trying to find Fire Wars (Summoning magic for elementals). I think I found it in the demon perk, but I'm not sure. Now I don't know how to set it up correctly. I write like this:
if HasHeroSkill ('Berein' , 12) == nil then
GiveHeroSkill ('Berein' , 12)
GiveHeroSkill ('Berein' , 12)
GiveHeroSkill ('Berein' , 53)
GiveHeroSkill ('Berein' , 97)
end

It only gives advanced summoning magic...What should I do?
Try separating each one with sleep commands.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
thank you, it helped.

Added 7 minutes ago
well, and (I really hope) the 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 magnificence 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 slow thinking and complete lack of knowledge of these script functions, I cannot seem to control and subdue the rebellious loop with 'for' and so on. I am attaching the code of the current function and hope for your prompt help. =)
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

Whatever
User Avatar
Auto-translated
1) Is it possible to block a region for a specific hero? 2) Is it possible to prevent a hero from giving away their army, but allow them to take an army from another hero? And all of this for version 1.6.
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
Auto-translated
for version 1.6???? Why???

1) Well, you could implement a check for that region, and if the desired hero is there, block the region. And when the hero leaves it, unblock it...
2) More complicated... Probably, yes, by constantly determining the number of creatures in the army. Although, no, that's nonsense, the army also loses creatures in battles...

Whatever
User Avatar
Auto-translated
Am I correct in understanding that Lua in Heroes 5 is limited to a specific set of functions defined by the game developers and does not support built-in functions such as setmetatable, package, and module? In other words, at best, can you only create static classes without support for creating types (object instances of a class)? And can modules be emulated through the doFile function?
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
In reply to Heroist
User Avatar
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
User Avatar
Auto-translated
RedHeavenHero - that's exactly the problem, that "they won't let you in before that." There are several huts on the map, each with its own name. I would like the function to start giving names, triggering events, and transforming things only after I have completed all the tasks in the huts - i.e., when dwell = 1.

Added 47 minutes later
by the way, (I always start with this question, yes), what is the fundamental difference between single-player and multiplayer, specifically in terms of scripting? I don't want to know minor details, but something more significant and frequently encountered in single-player that definitely won't work in multiplayer.

Whatever
In reply to Heroist
User Avatar
Auto-translated
Heroist
RedHeavenHero - that's exactly the problem, that they "won't let you in before." There are several huts on the map with their own names; I would like the function to start giving names, triggering, and transforming only when I have completed all the tasks in the huts - i.e., when dwell = 1.

Added 47 minutes later
by the way, (I always start with this question, yes), what is the fundamental difference between single-player and multiplayer, specifically in terms of scripting? I don't want to know minor details, but something more large-scale and frequently found in single-player that definitely won't work in multiplayer.
In other words, before the dwell becomes equal to one, all buildings should work as usual. And, as soon as dwell = 1, all previously captured buildings are transformed, and a trigger is applied to the rest. Am I right?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
What is the fundamental difference between the single-player and multiplayer modes, specifically regarding the scripting? I don't need to know minor details, but something more significant and frequently encountered in the single-player mode that definitely won't work in multiplayer.
The fundamental difference is that combat scripts (those that operate during battles) do not function in multiplayer.
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
User Avatar
Auto-translated
RedHeavenHero - yes, that's absolutely correct. That's exactly what I wanted =)

Nargott - thanks, I suspected, but wasn't sure, and I didn't want to bother checking. And does everything else, like adding an army, artifacts, etc., work?

Whatever
In reply to Heroist
User Avatar
Auto-translated
function start_dwellings()
local t, n = {}, 0
for i, dwelling in GetObjectNamesByType('PEASANT_HUT') do
n = n + 1
t[n] = dwelling
end
for i, dwelling in GetObjectNamesByType('ARCHERS_HOUSE') do
n = n + 1
t[n] = dwelling
end
for i, dwelling in GetObjectNamesByType('BARRACKS') do
n = n + 1
t[n] = dwelling
end
for i, dwelling in GetObjectNamesByType('HEAVEN_MILITARY_POST') do
n = n + 1
t[n] = dwelling
end
for i, dwelling in t do
if GetObjectOwner(dwelling) == 1 then
ReplaceDwelling(dwelling, 4)
else
SetObjectEnabled(dwelling, nil)
Trigger(4, dwelling, 'replace_dwelling')
end
end
end

function replace_dwelling(hero, dwelling)
if hero == 'Berein' then
ReplaceDwelling(dwelling, 4)
SetObjectEnabled(dwelling, 1)
Trigger(4, dwelling, nil)
sleep()
MakeHeroInteractWithObject(hero, dwelling)
end
end
Instead of calling dwell = 1, we call the start_dwellings function.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
startThread(start_dwellings) is that enough?

thank you.

Whatever
In reply to Heroist
User Avatar
Auto-translated
Heroist
startThread(start_dwellings) is that enough?

thank you
Yes, that's enough. Or you can simply write start_dwellings() in this case.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
I'm trying to add a script, and the map stops working!!!!!!!!!!
Two maps crashed. The scripts for these unfortunate maps are:
obs = 0

function a ()
obs = obs + 1
end;

Trigger(NEW_DAY_TRIGGER,"a");

function b ()
QuestionBox(GetMapDataPath().."mrkobsgst","yes",nil);
end;

function yes
SetPlayerResource(1,6,-10000);
obs = obs + 10
end;

function c (heroname)
ShowFlyingSign({GetMapDataPath()..."getobstxt",obs=obs},heroname);
end;

Trigger(OBJECT_TOUCH_TRIGGER,"mrkobs1","b");
Trigger(OBJECT_TOUCH_TRIGGER,"getobs1","c");

The second script wasn't saved.

At the beginning of these maps, there's some strange file called "index.bin".

WHAT DOES ALL OF THIS MEAN?:smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile35: :smile35: :smile35: :smile35: :smile35: :smile35: :smile35: :smile35: :smile35: :smile35: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile51: :smile45: :smile45: :smile45: :smile45: :smile45: :smile45: :smile45: :smile45: :smile45: :smile45: :smile33: :smile33: :smile33: :smile33: :smile33: :smile33: :smile33: :smile33: :smile33:
502 Bad Gateway
__________________________________
nginx/0.8.54

Statistics

Welcome our newest member: Emil