Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Grigoriy
User Avatar
Auto-translated
Grigoriy
Is it possible to add travel spells to an Orc through a script? It doesn't work with the standard command.
Most likely not, Orcs (or rather, any hero with Wrath) are not capable of learning spells in any way.
Нет войне.
In reply to OrnsteinDragonslayer
Auto-translated
OrnsteinDragonslayer
Hey guys, I have a question. Can you tell me what's wrong?
The situation: there's an elven city belonging to an elf (player 3). If player 2 captures it, the quest fails, and the game is lost.
...
This team isn't working. After the city is captured, nothing happens. There are no errors. Where could I have made a mistake? Thanks in advance.

In general, using a looped check for this isn't the most optimal solution.
Something like this, perhaps (I haven't tested it in the game)

Attachments 1
1 file attached • Total size: 12.6 KB
Auto-translated
Hello! Please help me. I want it so that after a certain amount of time, a player who has captured a town can buy all the accumulated troops in a neutral town, and the "neutral town" gets the money from somewhere and buys them itself. I even disabled the option to build a town hall in the settings, but it still didn't help.
In reply to JonnyP
User Avatar
Auto-translated
JonnyP
In general, the implementation with a looped check is not the most optimal option.
Something like this, perhaps (haven't checked in the game)


It doesn't help; the problem remains the same – the quest doesn't fail, no one loses, and the console doesn't show any errors.
And the "1" is there because the quest fails for the first player.
function onObjectCapture( prevOwner, newOwner, hero, object )
if prewOwner == PLAYER_3 and newOwner == PLAYER_2 then
Trigger( OBJECT_CAPTURE_TRIGGER, 'houseElf', nil )
SetObjectiveState ('q4', OBJECTIVE_FAILED, PLAYER_1 )
sleep(10)
Loose()
end
end
Trigger(OBJECT_CAPTURE_TRIGGER, 'houseElf', 'onObjectCapture' )
Автор карт:
Долина расхитителей
Выбор мира
In reply to OrnsteinDragonslayer
User Avatar
Auto-translated
OrnsteinDragonslayer
It doesn't help, the problem is still the same – the quest doesn't fail, no one loses, and the console doesn't see any errors.
And the "1" is there because the quest fails for the first player.
function onObjectCapture( prevOwner, newOwner, hero, object )
if prewOwner == PLAYER_3 and newOwner == PLAYER_2 then
Trigger( OBJECT_CAPTURE_TRIGGER, 'houseElf', nil )
SetObjectiveState ('q4', OBJECTIVE_FAILED, PLAYER_1 )
sleep(10)
Loose()
end
end
Trigger(OBJECT_CAPTURE_TRIGGER, 'houseElf', 'onObjectCapture' )


function onObjectCapture(PrevOwner, NewOwner)

if PrevOwner == 3 and NewOwner == 2 then

Trigger(5, 'houseElf', nil)
SetObjectiveState ('q4', 4, 1)
sleep(10)
Loose()

end

end

Trigger(5, 'houseElf', 'onObjectCapture')

You need to be more careful with variable names
Кампании для 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 OrnsteinDragonslayer
Auto-translated
OrnsteinDragonslayer
It doesn't help; the problem remains the same – the task isn't failing, no one is losing, and the console isn't showing any errors.
I've conveyed the essence of the error – the function takes 4 parameters + there's an unnecessary check with an infinite loop. It's possible that the syntax is incorrect (I mentioned that I didn't check it in the game).
Try adding some "print" statements to see what the console shows.

...And the number 1, by the way, is because the task fails for the first player.
...The conditions: there's an elven town belonging to an elf (Player 3). If Player 2 captures it, the task fails, and Player 2 loses.
To avoid confusion, use constants – PLAYER_1, PLAYER_... etc. This is a good and established practice.
There weren't any such conditions, so I considered it an error, but it's not really important.
Master
...You need to be more careful with variable names.
What do you mean? I don't see any differences. If you're talking about the style of writing variables, it doesn't matter (PascalCase or camelCase).
In reply to Killer5029
User Avatar
Auto-translated
Killer5029
Hello! Please help. I want it so that after a certain amount of time, the player who has captured a town can buy all the accumulated troops in the neutral town, and the "neutral town" gets money from somewhere and buys them itself. I even disabled the option to build a town hall in the settings, but it still didn't help.

Maybe there's an easier way to do this, but in this situation, I wouldn't build any buildings with creatures in that town initially. After the town is taken over by a player, scripts can be used to build any buildings in that town, and also (I think) add creatures for recruitment.
Кампании для 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
Auto-translated
MasteR
Maybe there's an easier way to do it, but in this situation, I wouldn't build any creature-producing buildings in that town initially. After the town is transferred to the player, scripts can be used to build any buildings in that town, and also (apparently) add creatures for recruitment.
Don't you remember which command can be used to build buildings in a town?
In reply to Killer5029
User Avatar
Auto-translated
Killer5029
Can't remember which command is used to build structures in a town?
UpgradeTownBuilding(town_name, building_id)

Regarding adding creatures that can be recruited – there's a function for that: SetObjectDwellingCreatures(town_name, creature_id, number).
Нет войне.
In reply to JonnyP
User Avatar
Auto-translated
JonnyP
What do you mean? I don't see any differences. If you're talking about the style of writing variables, it doesn't matter (PascalCase or camelCase).

In the function parameter, it's prevOwner, and in the function body, it's prewOwner.
Кампании для 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 Gerter
Auto-translated
Gerter
UpgradeTownBuilding(town_name, building_id)

regarding adding creatures for recruitment – there is a function for this: SetObjectDwellingCreatures(town_name, creature_id, number)
I wrote the following script (it doesn't work):
local a=0;
function Armia()
local day=GetDate(3);
if day == 0
then a=a+1;
end;
end;

Trigger(NEW_DAY_TRIGGER, "Armia");

function zoloto()
if prewOwner == PLAYER_NOON and newOwner == PLAYER_NAME
then SetObjectDwellingCreatures('houseInferno', 16, 35*a);
SetObjectDwellingCreatures('houseInferno', 18, 34*a);
SetObjectDwellingCreatures('houseInferno', 20, 18*a);
SetObjectDwellingCreatures('houseInferno', 22, 10*a);
SetObjectDwellingCreatures('houseInferno', 24, 7*a);
SetObjectDwellingCreatures('houseInferno', 26, 4*a);
SetObjectDwellingCreatures('houseInferno', 28, 2*a);

end;
end;

Trigger( OBJECT_CAPTURE_TRIGGER, 'houseInferno', "zoloto")

What could be the error? Please advise
In reply to Killer5029
User Avatar
Auto-translated
Killer5029
I wrote this script (it doesn't work):
local a=0;
function Armia()
local day=GetDate(3);
if day == 0
then a=a+1;
end;
end;

Trigger(NEW_DAY_TRIGGER, "Armia");

function zoloto()
if prewOwner == PLAYER_NOON and newOwner == PLAYER_NAME
then SetObjectDwellingCreatures('houseInferno', 16, 35*a);
SetObjectDwellingCreatures('houseInferno', 18, 34*a);
SetObjectDwellingCreatures('houseInferno', 20, 18*a);
SetObjectDwellingCreatures('houseInferno', 22, 10*a);
SetObjectDwellingCreatures('houseInferno', 24, 7*a);
SetObjectDwellingCreatures('houseInferno', 26, 4*a);
SetObjectDwellingCreatures('houseInferno', 28, 2*a);

end;
end;

Trigger( OBJECT_CAPTURE_TRIGGER, 'houseInferno', "zoloto")

What could be the error? Please help.

Firstly, it's better not to write like this:
local a = 0
outside of functions.
Secondly, this line:
if prewOwner == PLAYER_NOON and newOwner == PLAYER_NAME
The neutral player is PLAYER_NONE. What is PLAYER_NAME? You need to use player number constants, for example, PLAYER_1.

Also, in the definition of the zoloto function, you need to specify that it has the parameters prewOwner and newOwner:
function zoloto(prewOwner, newOwner)
Нет войне.
In reply to Gerter
Auto-translated
Gerter
first, here's how it should be:
local a = 0
it's better not to write anything outside of functions.
second, here's this line:
if prewOwner == PLAYER_NOON and newOwner == PLAYER_NAME
a neutral player is PLAYER_NONE. What is PLAYER_NAME, anyway? You need to use constant player numbers, for example, PLAYER_1.

also, in the definition of the zoloto function, you need to specify that it has the parameters prewOwner and newOwner:
function zoloto(prewOwner, newOwner)

PLAYER_NAME is any player. I want the script to work when any player captures this town.
User Avatar
Auto-translated
in that case, there’s no need to check the player number of the one who captures the city.
Нет войне.
In reply to Gerter
Auto-translated
Gerter
then there's absolutely no need to check the player number capturing the city
so, can we leave it like this?
local a = 0
function Armia()
local day=GetDate(3);
if day == 0
then a=a+1;
end;
end;

Trigger(NEW_DAY_TRIGGER, "Armia");

function zoloto()
SetObjectDwellingCreatures('houseInferno', 16, 35*a);
SetObjectDwellingCreatures('houseInferno', 18, 34*a);
SetObjectDwellingCreatures('houseInferno', 20, 18*a);
SetObjectDwellingCreatures('houseInferno', 22, 10*a);
SetObjectDwellingCreatures('houseInferno', 24, 7*a);
SetObjectDwellingCreatures('houseInferno', 26, 4*a);
SetObjectDwellingCreatures('houseInferno', 28, 2*a);

end;


Trigger( OBJECT_CAPTURE_TRIGGER, 'houseInferno', "zoloto")

Added 2 minutes later
Gerter
then there's absolutely no need to check the player number capturing the city
so, can we leave it like this?
local a = 0
function Armia()
local day=GetDate(3);
if day == 0
then a=a+1;
end;
end;

Trigger(NEW_DAY_TRIGGER, "Armia");

function zoloto()
SetObjectDwellingCreatures('houseInferno', 16, 35*a);
SetObjectDwellingCreatures('houseInferno', 18, 34*a);
SetObjectDwellingCreatures('houseInferno', 20, 18*a);
SetObjectDwellingCreatures('houseInferno', 22, 10*a);
SetObjectDwellingCreatures('houseInferno', 24, 7*a);
SetObjectDwellingCreatures('houseInferno', 26, 4*a);
SetObjectDwellingCreatures('houseInferno', 28, 2*a);

end;


Trigger( OBJECT_CAPTURE_TRIGGER, 'houseInferno', "zoloto")

Statistics

Welcome our newest member: Emil