Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
What function is used to change the name and description of an object? Also, could you please tell me how to fix the error: "Value was NIL when getting global with name 'ChangeResource'?" ``` function give_sulfur() ChangeResource(4, 5, 'Biara') Trigger(OBJECT_TOUCH_TRIGGER, 'kotel', nil); end
In reply to WizardNazyr
User Avatar
Auto-translated
WizardNazyr
Which function is used to change the name and description of an object?
Also, can you tell me how to fix the error: Value was NIL when getting global with name 'ChangeResource'?
function give_sulfur()
ChangeResource(4, 5, 'Biara')
Trigger(OBJECT_TOUCH_TRIGGER, 'kotel', nil);
end
1) OverrideObjectTooltipNameAndDescription(object, path_to_name_text, path_to_description_text)
2) There is no such function as ChangeResource; check the manual for functions that modify resources.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to RedHeavenHero
User Avatar
Auto-translated
RedHeavenHero
1) OverrideObjectTooltipNameAndDescription(object, path_to_name_text, path_to_description_text)
2) There is no such function as ChangeResource; refer to the manual to see which functions change resources.
1) Thank you!
2) Interestingly, the function "ChangeResource" is described in the file with function descriptions, which I downloaded from heroesworld.
Attachments 1
1 file attached • Total size: 22.4 KB
Auto-translated
Good day! Let's say I have a hero, let's call him Vinrael, and I want to initiate a battle for him against, for example, 200 Latniks and 150 Gargoyles. Is it possible to do this in single-player mode using the console?
User Avatar
Auto-translated
Please help! I wrote the following script:
while GetObjectiveState('meet_demons', PLAYER_1) == OBJECTIVE_ACTIVE do
sleep(5)
end
SetObjectiveState('hero_from_hell', OBJECTIVE_ACTIVE, PLAYER_1);
MessageBox(GetMapDataPath()..'5.txt');

while 1 do
if GetObjectiveState('kill_daeva', PLAYER_1)== OBJECTIVE_COMPLETED
and
GetObjectiveState('capture_mines', PLAYER_1) == OBJECTIVE_COMLETED
then
sleep(5)
SetObjectiveState('hero_from_hell',OBJECTIVE_COMPLETED, PLAYER_1)
SetObjectiveState('go_throw_dungeon',OBJECTIVE_ACTIVE, PLAYER_1)
end
end
After completing the "meet_demons" quest and closing the "5" message, the game freezes. What did I do wrong?
User Avatar
Auto-translated
WizardNazyr, your code after the message can be described as: `
an infinite loop
{
condition check.
}
`. You need to add a sleep function to the loop. Also, it would be better if it runs in a separate thread (it is not clear from the code whether it is wrapped in a thread or not).
User Avatar
Auto-translated
Okay, now I think I messed something up completely. The game freezes after I close the "2" message.
MessageBox(GetMapDataPath()..'1.txt');
MessageBox(GetMapDataPath()..'2.txt');
Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'Svetlana_Vyacheslav1', 'talk1');
Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'demons', 'talk2');
function talk1 ()
MessageBox(GetMapDataPath()..'3.txt')
Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'Svetlana_Vyacheslav1', nil);
end
function talk2 ()
MessageBox(GetMapDataPath()..'4.txt');
Trigger(REGION_ENTER_AND_STOP_TRIGGER, 'demons', nil);
end
function task1()
while GetObjectiveState('meet_demons', PLAYER_1) == OBJECTIVE_ACTIVE do
sleep(5)
end
SetObjectiveState('hero_from_hell', OBJECTIVE_ACTIVE, PLAYER_1);
MessageBox(GetMapDataPath()..'5.txt');
end;
function task2()
while 1 do
if GetObjectiveState('kill_daeva', PLAYER_1)== OBJECTIVE_COMPLETED
and
GetObjectiveState('capture_mines', PLAYER_1) == OBJECTIVE_COMLETED
then
sleep(5)
SetObjectiveState('hero_from_hell',OBJECTIVE_COMPLETED, PLAYER_1)
SetObjectiveState('go_throw_dungeon',OBJECTIVE_ACTIVE, PLAYER_1)
end
end
end;
startThread(task1);
startThread(task2) ;
Added 14 minutes ago And yes, I didn't quite understand where exactly I need to put the `sleep` and what value should be in the parentheses. :smile35:
User Avatar
Auto-translated
WizardNazyr, the reason for the freeze is the same. You already have the task1 function, which performs a similar function and works correctly. Just rewrite task2 in a similar way to task1. In task2, firstly, the loop will never end (while 1 do), and secondly, you need to add an else statement to the if condition, which will be executed until the condition is met, and include a sleep function in it.
User Avatar
Auto-translated
Jack_of_shadows, thank you very much! I fixed the loop in task2. I added an `else` statement and `sleep`. Now it works!
User Avatar
Auto-translated
Hello, I have a question: If I "dismiss" a hero who is stationed in a castle, will he continue to recruit units for his army? And will other heroes be able to purchase units in that city?
In reply to AstralLein
User Avatar
Auto-translated
AstralLein
It will be. They will be able to.
Thank you.
User Avatar
Auto-translated
Who knows why this script stopped working (it used to work, but maybe I accidentally changed something)? The idea is that on the seventh day of the week, the hero Markel2's army will be joined by ghosts (of a suitable type) equal in number to his level. Another condition is the presence of ghosts in the hero's army.
Карты для героев 5

"Плата за любовь"
"Путь некроманта"
"Темные грани"
"Рок Гримхейма"
User Avatar
Auto-translated
AstralLein, I can only say that it's better to check if a hero exists before performing any operation with him. Otherwise, it looks normal. You should check the debug messages; there might have been an error in the script earlier, and the interpreter simply didn't reach line 158 and didn't trigger the new day.

Statistics

Welcome our newest member: Emil