Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
Hmm, that's a shame. So, the problem lies elsewhere...

Whatever
In reply to Heroist
User Avatar
Auto-translated
Heroist
Hmm, that's a shame. So, the problem lies elsewhere...
Why is it a shame? Why does the problem lie elsewhere? The problem is precisely in this. The number, although seemingly non-negative, still causes an error in functions such as AddObjectCreatures, RemoveObjectCreatures, and so on.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
I didn't finish reading your message. I basically expected that. Well, it's fixable. Thank you!

Whatever
User Avatar
Auto-translated
Good people, please help me with some advice. I really want to set up a strong army to guard the dwarven treasure. I made the object inactive and added a trigger on touch with the question "Are you ready to fight the guardian?". If the answer is yes, a message should appear, and a battle should begin. The message appears, but the battle doesn't happen. I would like to understand why. I will be grateful for any help, because I'm tired of tinkering with it. ``` dir = GetMapDataPath() Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F") function tres1F (heroName) number=GetCurrentPlayer() QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF") end function captureF (heroName) number=GetCurrentPlayer() MessageBoxForPlayers(number,dir.."gettreasure.txt") StartCombat (heroName, nil, 2, CREATURE_THANE, 20, CREATURE_WARLORD, 20, nil) end function alreadyCapturedF (heroName) number=GetCurrentPlayer() MessageBoxForPlayers(number,dir.."alreadyCaptured.txt") end function nocaptureF (heroName) number=GetCurrentPlayer() MessageBoxForPlayers(number,dir.."Coward.txt") end SetObjectEnabled("tres1", false)
User Avatar
Auto-translated
The script looks good; it's strange that it doesn't work. Have you checked the console? And this... I doubt it will help, but I would try adding three more "nil" values at the end of StartCombat. There's just this thing where, by default, the value of the variable that comes first in the function is set, and it might be causing a bug where a required variable isn't set, and the default value is set in such a way...
 

К А
Стикеры GBF в Telegram
In reply to metufona
User Avatar
Auto-translated
metufona
Hello everyone, please help me with some advice. I really want to set up a strong army guarding the Dwarven treasure. I made the object inactive and added a trigger on touch with a question: "Are you ready to fight the guardian?". If the answer is yes, a message should appear, and a battle should begin. The message appears, but the battle doesn't start. I would like to understand why. I will be grateful for any help, because I'm tired of tinkering with it.
dir = GetMapDataPath()
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F");
function tres1F (heroName)
number=GetCurrentPlayer();
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF");
end;
function captureF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."gettreasure.txt");
StartCombat (heroName, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil);
end;
function alreadyCapturedF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt");
end;
function nocaptureF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."Coward.txt");
end;
SetObjectEnabled("tres1", false);

I took a quick look and already found the error.
In the QuestionBoxForPlayers function, you specify a function that will be called when the "Yes" answer is given. This function does not take any parameters, i.e.,
in the line function captureF (heroName), the parentheses should be empty. There is a solution, for example, like this: before this entire block, define a global variable, i.e., write a line like hero=''.
Then, in the function where QuestionBox is written, assign the hero's name to this variable like this: hero= heroName. And already in the StartCombat function, use this variable. It will look something like this:
dir = GetMapDataPath()
hero='';
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F");
function tres1F (heroName)
number=GetCurrentPlayer();
hero=heroName;
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF");
end;
function captureF ()
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."gettreasure.txt");
StartCombat (hero, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil);
end;
function alreadyCapturedF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt");
end;
function nocaptureF ()
number=GetCurrentPlayer();
hero='';
MessageBoxForPlayers(number,dir.."Coward.txt");
end;
SetObjectEnabled("tres1", nil);

I would also like to note that it would be good to add a function to the StartCombat function that will be called after the battle. Thanks to it, you can reward the hero, remove the trigger from the building, etc.
Кампании для 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
These functions can be passed parameters in a slightly unconventional way; instead of writing "captureF," you can write "captureF('"..heroName.."')".
Also, MessageBoxForPlayers takes the player's filter GetPlayerFilter(number) as its first parameter, not the player itself. The difference won't be noticeable if there are only 1-2 players, but errors will occur with more than 2. It would also be good to add a check to see if the player is a computer-controlled player or not.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to MasteR
User Avatar
Auto-translated
Juss456
I took a quick look and already found a mistake.
In the QuestionBoxForPlayers function, you define a function that will be called when the "Yes" answer is given. This function does not accept any parameters, i.e., in the line function captureF (heroName), the parentheses should be empty.
There is a solution, for example, like this: before this entire block, define a global variable, i.e., write a line like hero=''.
Then, in the function where QuestionBox is written, assign the hero's name to this variable like this: hero= heroName. And then use this variable in the StartCombat function. It will look something like this:
dir = GetMapDataPath()
hero='';
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F");
function tres1F (heroName)
number=GetCurrentPlayer();
hero=heroName;
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF");
end;
function captureF ()
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."gettreasure.txt");
StartCombat (hero, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil);
end;
function alreadyCapturedF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt");
end;
function nocaptureF ()
number=GetCurrentPlayer();
hero='';
MessageBoxForPlayers(number,dir.."Coward.txt");
end;
SetObjectEnabled("tres1", nil);

I'd also like to note that it would be good to add a function to the StartCombat function that will be called after the battle. Thanks to it, you can reward the hero, remove the trigger from the building, etc.

Thank you very much, now everything works! I will keep in mind for the future that such functions should be written without parameters.
I was already planning to add a function after the battle in StartCombat, I'm just doing everything in stages so as not to get confused.

RedHeavenHero
Yes, and MessageBoxForPlayers takes not the player as the first parameter, but its filter GetPlayerFilter(number). There will be no visible difference if there are 1-2 players, but errors will occur for >2. It is also desirable to add a check to see if the player is a computer or not.
Only one player will have access to this object. Therefore, I'd rather leave it as is. But I will keep it in mind for the future, thank you!
User Avatar
Auto-translated
Only one player will have access to this object. Therefore, I'd rather leave it as is. But I'll keep it in mind for the future, thanks!
Then why not use a regular MessageBox?
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
Then why not use a regular MessageBox?
Because the map is for multiplayer.
User Avatar
Auto-translated
Does the IsHeroAlive function check for the presence of a hero in the city garrison?
Кампании для 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
Juss456
Does the IsHeroAlive function check for the presence of a hero in the city garrison?
Not quite. The function returns 1 if the hero is alive, including if he is in the city garrison; otherwise, it returns nil.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
I didn't quite understand. The function returns 1 if the hero is alive, including if he is in the city garrison, otherwise it returns nil.

Yeah, that's what I meant.
Кампании для Heroes V 3.1 (Трилогия):

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

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

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


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


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

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

Легендарная война
Сердце вулкана
Передел мира

Statistics

Welcome our newest member: Emil