Skip to content

Posts from Scripts

4.8 (8 ratings)
Auto-translated
Hi, I've encountered the need to write a script for the first time, but I'm not very good at programming, and I also don't know the limits of what's possible. Specifically, I need to program a gate so that when the entire army inside it is destroyed, the gate transitions under my control, and the guards inside the gate are revived, doubling in number. Perhaps you already have a similar draft, and I would be very grateful for your help.
User Avatar
Auto-translated
What is meant by the word "gate"? A garrison? Then it will become yours anyway after you destroy its entire army.

Whatever
In reply to Heroist
Auto-translated
yes, garrison
no, the point isn't that it becomes mine
but that the entire army I defeated is reborn
but now under my command
and, of course, it's non-removable
plus, it's doubled.
In reply to JORAJAN
User Avatar
Auto-translated
There are many ways to do this. Here is one of them:
SetObjectEnabled("garrison_name", nil);
Trigger(4, "garrison_name", "capture_gar");

function capture_gar(hero)
local a = {};
a[1], a[3], a[5], a[7], a[9], a[11], a[13] = GetObjectCreaturesTypes("garrison_name");
for i = 1, 7 do
if a[i*2-1] ~= 0 then
a[i*2] = 2 * GetObjectCreatures("garrison_name", a[i*2-1]);
end;
end;
SetObjectEnabled("garrison_name", 1);
Trigger(4, "garrison_name", nil);
MakeHeroInteractWithObject(hero, "garrison_name");
local i = GetLastSavedCombatIndex();
while i == GetLastSavedCombatIndex() do
sleep(1);
end;
if not IsHeroAlive(hero) then
SetObjectEnabled("garrison_name", nil);
Trigger(4, "garrison_name", "capture_gar");
return
end;
for i = 1, 7 do
if a[i*2] then
AddObjectCreatures("garrison_name", a[i*2-1], a[i*2]);
end;
end;
DenyGarrisonCreaturesTakeAway("garrison_name", 1);
end;
Here, you only need to replace "garrison_name" with the script name of your garrison. In the script, it should be written in quotes, and in the editor (in the Name field in the object's properties) - without quotes.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to JORAJAN
User Avatar
Auto-translated
JORAJAN
yes, the garrison
no, the point is not that it becomes mine
but that the entire army that I defeated is reborn
but now under my command
naturally, it cannot be taken back
plus, it doubles in size

you give your "gates" a name.
for example, vorota
vorotaF is a function that will be executed when an object is captured
then you declare a trigger
Trigger(OBJECT_CAPTURE_TRIGGER, "vorota", "vorotaF");

then you write the function itself

vorotaF(nPrevOwnerID, nNewOwnerID, sHeroName, sObjectID)
nPrevOwnerID - player number - the former owner
nNewOwnerID - the current owner
sHeroName - the name of the hero who captured the gates
sObjectID - the name of your gates (vorota)

these parameters are passed to the function after the garrison's owner changes. If it doesn't matter who captured the garrison, you can leave the parentheses empty.

to add creatures to the garrison, use the command
AddObjectCreatures( sObjectName, nGreatureID, nCount );

where sObjectName is the name of the gates (specified in quotes!!!)
nGreatureID is the creature ID (there is a document with all IDs in the editor's documentation)
nCount is the number of creatures to be added.

Trigger(OBJECT_CAPTURE_TRIGGER, "vorota", nil ); - resetting the trigger, also in the function body!!!

and don't forget to put end at the end;

that's all. If it is important which player and hero captures, specify all parameters in the function's parentheses and write a conditional statement in the function body if ....... end;
Кампании для Heroes V 3.1 (Трилогия):

Пробуждение зла
Нашествие из Преисподней
Смена эпох

Скачать все кампании одним архивом: Яндекс.Диск Google.Диск

You can download the set of 3 Campaigns (English version) here


Одиночные сценарии Heroes V 3.1:


Незваные гости
Красный кристалл
Синий кристалл
Закат тьмы

Мультиплеерные карты для Heroes V 3.1:

Легендарная война
Сердце вулкана
Передел мира
In reply to MasteR
User Avatar
Auto-translated
Method #2: ```html
gar="garrison name"
gar_army={}
for i = 0, 6 do
local t, n = GetObjectArmySlotCreature(gar, i)
gar_army={t, n}
end

Trigger(5, gar, 'capture_gar')

function capture_gar(oldowner, newowner, hero, gar)
for i = 0, 6 do
if gar_army[1] ~= 0 then
AddObjectCreatures(gar, gar_army[1], gar_army[2]*2)
end
end
DenyGarrisonCreaturesTakeAway(gar, 1)
Trigger(5, gar, nil)
end
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
Auto-translated
What did I do wrong?
I opened the map in the editor.
I found the garrison.
I opened the properties with the spacebar.
I clicked "Edit Script".
I pasted the text.
I clicked "OK".
In reply to JORAJAN
User Avatar
Auto-translated
JORAJAN
what did I do wrong? I opened the map in the editor. I found a garrison. I opened its properties by pressing the spacebar. I clicked "Edit script". I pasted the text. I clicked "OK".
To write a script for the map, open Map properties in the editor (you can do this quickly by pressing the M button). In it, select the Scripts tab, click Edit script, and start writing.
Кампании для Heroes V 3.1 (Трилогия):

Пробуждение зла
Нашествие из Преисподней
Смена эпох

Скачать все кампании одним архивом: Яндекс.Диск Google.Диск

You can download the set of 3 Campaigns (English version) here


Одиночные сценарии Heroes V 3.1:


Незваные гости
Красный кристалл
Синий кристалл
Закат тьмы

Мультиплеерные карты для Heroes V 3.1:

Легендарная война
Сердце вулкана
Передел мира
Auto-translated
another question
how do I name a garrison?
In reply to JORAJAN
User Avatar
Auto-translated
Instead of pressing the spacebar to open properties, you should type in the Name field in the SelectionPropertyWindow. It looks something like this.
Attachments 1
1 file attached • Total size: 6.4 KB
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
Auto-translated
this is what I found. and how do I enter it? in the name field?
In reply to RedHeavenHero
Auto-translated
Thanks to everyone, I barely found it.
It turns out you need to click
in the field to the right of the word "name".
You can also click on "name" to highlight it and then press the spacebar.

It worked!
User Avatar
Auto-translated
Does anyone know how to prevent a super-strong hero-companion from attacking my hero? Judging by the description, the attractor won't help, and I don't want to establish friendship either; I need to be able to attack, but he shouldn't attack back...

Whatever
User Avatar
Auto-translated
Disable it using `SetObjectEnabled("...",nil);` and move it around the map manually. You'll also need to set up a trigger for when another hero touches it, so they can attack.
 

К А
Стикеры GBF в Telegram

Statistics

Welcome our newest member: Emil