Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated
serovoy, when creating a new hero, you need to assign it a unique system name, which is then used to reference it in scripts.
Auto-translated
I recently started learning scripting, and even the simplest scripts that are explained multiple times cause difficulties, but I think I've figured it out.
I need help with this.
I can't understand how to use the "ShowFlyingSign" command correctly:

function offlich()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", nil);
ShowFlyingSign(GetMapDataPath().."offli.txt");
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", "offlich");
Also, can I add "PLAYERFLT_1" to "ShowFlyingSign"?
Since I'm creating a multiplayer map, I want the message to be displayed to the first player. I used this:

function mostFF()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "most", nil);
MessageBoxForPlayers(PLAYERFLT_1, GetMapDataPath().."most11.txt");
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "most", "mostFF");
User Avatar
Auto-translated
The ShowFlyingSign function has additional parameters: the name of the object from which the message will fly; the player number for whom the message will be visible (-1 if it's for everyone); and the duration of the message's flight in seconds. It's best to check the order in the scripting functions manual.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
Auto-translated
Basically, I found the syntax

ShowFlyingSign(messageName, objectName, targetPlayerID = -1, time = 1.0);
and started writing it, but the "script editor" started giving me errors.
I "changed" it, and it stopped complaining, but my version didn't work and looked like this:

ShowFlyingSign("GetMapDataPath().."offli.txt","offlich", "targetPlayerID = -1", "time = 1.5");
After some time, I realized that I couldn't do it without a "template," so I searched the internet and found

ShowFlyingSign({path.."slavescaptured.txt";totalcost=tc},hero,PLAYER_1,5);
I adjusted it to my needs, and it became

ShowFlyingSign(GetMapDataPath().."offlich.txt", off, Player_1, 5);
However, the script still doesn't work. =) Can you tell me what I'm doing wrong? Maybe it's because I'm giving the "name of the region" instead of the "name of the object"?

Original script:

function offlich()
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", nil);
ShowFlyingSign(GetMapDataPath().."offlich.txt", off, Player_1, 5);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "off", "offlich");

P.s. The script works up to the point where the hero stops in the desired region
User Avatar
Auto-translated
A region is not an object; an object is a hero, a castle, or, say, a bush with a name. The function receives the name of the hero who entered the region, and it's easiest to use that. Player_1 probably won't work because it's not the same as PLAYER_1.
I would recommend downloading any story-driven map that is rich in scripts and simply searching for an example of how to use any unclear function within it.
Auto-translated
Thank you for your answers.
I think I'll look for a map with scripts, but in this situation, I decided not to bother and instead use the template from the "OGO" manual through the "touch object" feature.
User Avatar
Auto-translated
Could you please tell me if it’s possible to make it so that one computer-controlled hero tracks the coordinates of another computer-controlled hero each turn? Basically, the first hero would pay the second hero through a QuestionBox, and with EnableHeroAl and MoveHero, the second hero would run to kill your enemy. How can I make it so that the first hero checks the coordinates of the second hero at the beginning of each turn and moves towards them? Until the first hero dies. There are no towns or garrisons, and MoveHero works perfectly. Thank you in advance.
User Avatar
Auto-translated
Here's a shortened version from my map; only the computer-controlled unit chases the player, so it might not look exactly as you'd expect. `hero` is the computer's hero, and `player_hero` is the player's hero. Run it as a thread. The computer tries to move towards the player at the beginning of each turn, and if the player moves away quickly during that time, it will also be handled correctly.
function MainKnightSavedHeroReturnWithPlayerThread()

local hero = quest_main_knight.AttackParam('hero');
local start_date = GetDate(ABSOLUTE_DAY);
local move_date = 0;
local curr_date;
local hx_last, hy_last, hf_last = -1, -1, -1;
local hx_curr, hy_curr, hf_curr;

while(1) do
if(IsObjectExists(hero)) then

if(IsObjectExists(player_hero)) then
hx_curr, hy_curr, hf_curr = GetObjectPosition(player_hero);
if((hx_last ~= hx_curr) or (hy_last ~= hy_curr) or (hf_last ~= hf_curr)) then
hx_last, hy_last, hf_last = hx_curr, hy_curr, hf_curr;
MoveHeroRealTime(hero, hx_curr, hy_curr, hf_curr);
end
end

-- movement points are added at the beginning of each turn
curr_date = GetDate(ABSOLUTE_DAY);
if(move_date ~= curr_date) then
move_date = curr_date;
ChangeHeroStat(hero, STAT_MOVE_POINTS, 2500);
sleep(1);
if(IsObjectExists(player_hero)) then
hx_curr, hy_curr, hf_curr = GetObjectPosition(player_hero);
MoveHeroRealTime(hero, hx_curr, hy_curr, hf_curr);
end
end

else
break
end
sleep(5);
end

end
User Avatar
Auto-translated
Is there a script that determines whether a given function is currently running or has already finished? (without using a flag within the function itself) For example, consider this:

for i=1,100 do
startThread(Func);
end
As a result, multiple instances of the function Func may be launched, even though the previous one might not have finished executing.
Моды для HeroesV:
NHF 0.90 : NHF - группа в VK

Карты для HeroesV:
Путешествие , Условие крови , Рука судьбы.Часть 1: В поход , Рука судьбы.Часть 2: Отчаянье , Рука судьбы.Часть 3: Восхождение , Стойкость
Абсолютная власть , Иду на Вы! , Корона Ургаша , На задворках
Мир надо уничтожить... Чтобы создать свой...
In reply to Dyrman
User Avatar
Auto-translated
Dyrman
Is there a script that determines whether a given function is currently running or not? (without using a flag within the function itself)
For example, consider this:

for i=1,100 do
startThread(Func);
end
As a result, several Func functions may start, even though the previous one might not have finished.

local threads = {}

local startExec = function(func)
local threads = threads
errorHook(function()
%threads[%func] = nil
end)
threads[func] = 1
func()
threads[func] = nil
end

function startThreadOnce(func)
if not %threads[func] then
startThread(%startExec, func)
end
end

function isFunctionRunning(func)
return %threads[func]
end
In this example, startThreadOnce starts the function only if it is not currently running. isFunctionRunning checks whether the function is currently running.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
Auto-translated
Sorry for the trivial question, but still:

So, please write a 100% working example of the StartCombat script, just one line. I've read so many manuals, but everywhere the description of this script is different, and for some reason none of them work. Thank you in advance.
User Avatar
Auto-translated
Ruther's battle against 15 peasants and 6 archers:
StartCombat('Brem', nil, 2, CREATURE_PEASANT, 15, CREATURE_ARCHER, 6)
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
In reply to Jack_of_shadows
Auto-translated
Jack_of_shadows
serovoy, when you create a new hero, you need to assign a unique system name to him, which is then used to reference him in scripts.
But if I'm playing someone else's custom map with a hero created on it, how can I find out its system name? Is there a console command or something similar?
User Avatar
Auto-translated
serovoy, the fastest way is probably to open the map with an archiver and look at the file containing the hero descriptions.

upd: although, wait a minute, there's GetPlayerHeroes(player_id), which returns an array of hero names by player ID.
Auto-translated
Great! Does it work in single-player mode? I'm starting a campaign, entering this, and there's no effect. :eek:

Statistics