Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
#1277
Auto-translated
How can I use a script to check the number of creatures that died in a battle against a specific hero and output the result to a variable?

Whatever
In reply to Heroist
User Avatar
#1278
Auto-translated
Heroist
How can I use a script to check the number of creatures that died in a battle with a specific hero and output the result to a variable?
There is a whole series of functions designed for this. An example of their use can be found in the campaign script for "Escape to Salvation," mission "Deeds and Paths of Darkness."
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1279
Auto-translated
okay, thanks, I'll take a look.

Added 1 hour 24 minutes ago
and another question: Is it possible to change the progress of a quest without using a large number of progress texts?

For example, I want to create a 15-turn quest. But it would be enough if its progress simply shows a number, changing from 0 to 15 accordingly. Do I really need to create 15 separate txt files inside the progress folder, named after each number? Can I get by with one progress file with a <changing variable>?

Whatever
User Avatar
#1280
Auto-translated
I asked earlier today what you were interested in; is that not what you meant?
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
#1281
Auto-translated
So, if I understand you correctly, you were asking about a flying sign, and there you can assign a variable directly within the function call, as the respected RedHeavenHero showed. But I need something similar, but when writing a quest. And quests can only be created directly in the editor, without the help of a script. So, even if I write in the quest:

"Notes collected" < value=zapiski > , it won't help, because I'm not calling this record through a flying sign, but through SetObjectiveProgress... And there's nowhere to insert the magic line {zapiski=zapiski}. I know I'm writing confusingly, but what can I do =).

Whatever
In reply to Dyrman
User Avatar
#1282
Auto-translated
Dyrman
Does anyone have a suggestion for how to determine via scripts whether the game is running in Multiplayer or Singleplayer mode?
function IsMultiplayer()
local p=0
for i=1,8 do
if IsAIPlayer(i) == 0 then
p=p+1
end
if p > 1 then
return 1
end
end
for i,hero in GetObjectNamesByType('HERO') do
if IsAIPlayer(GetObjectOwner(GetHeroTown(hero) or hero)) == 1 then
SetHeroCombatScript(hero, '/mult.xdb#xpointer(/Script)')
sleep()
local ind = GetLastSavedCombatIndex()
StartCombat(hero,nil,1,1,1)
repeat sleep() until ind ~= GetLastSavedCombatIndex()
ResetHeroCombatScript(hero)
if GetGameVar('single') ~= '1' then return 1 end
break
end
end
return nil
end
/mult.xdb contains a link to the file /mult.lua. Both are located in the root directory, without any intermediate folders.
The content of /mult.lua:
SetGameVar('single', '1')


Added 23 minutes later
Heroist
okay, thanks, I'll take a look.

Added 1 hour 24 minutes later
and another question: Is it possible to change the progress of a quest without using a large number of progress texts?

For example, I want to create a 15-turn quest. But it would be enough if its progress simply shows a number, changing from 0 to 15 accordingly. Do I really need to create 15 separate txt files inside the progress folder, with names corresponding to the number? Can I get by with one progress with a <changing variable>?
Most likely not. In any case, I am not aware of such a possibility.
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1283
Auto-translated
Recently, I implemented an increase in the heroes' vision range using scripts (it didn't work through DefaultStats and types). This was done through the OpenCircleFog script, attached to a trigger emulator that activates when heroes move. And now, a question: Is it possible to hide part of the map from the player using scripts? And a second question: Is it possible to build a city twice in one turn? In other words, is it possible to unlock a city? And a third question: Is it possible to detect when a hero interacts with a caravan?
Разработчик Heroes 5.5 WarGame Edition.
Сайт проекта - пока неактивен
Автор Асимметричных шахмат
User Avatar
#1284
Auto-translated
Is it possible to use scripts to block off a part of the map from the player?
I was interested in this myself, but it seems like it's not possible.
Is it possible to build twice in a city in one turn? I.e., is there a way to unlock a city?
You can forcibly build a building in a city. Regarding unlocking: I haven't seen a special function for this, but who knows, maybe locking it using IsObjectEnabled and then unlocking it with the same function will reset some settings and allow you to build the building a second time? I think it's worth trying.
Is it possible to track when a hero interacts with a caravan?
Redhaven is our expert in getting the names of objects of a given type. If you create a caravan using scripts, you can choose a name for it, and then it will be no problem at all.
 

К А
Стикеры GBF в Telegram
User Avatar
#1285
Auto-translated
RedHeavenHero
Most likely not. At least, I'm not aware of such a possibility.

Damn, that's a shame. Is it really impossible to influence the quest using scripts? Maybe at least its description or title? I saw somewhere that it's possible to change the hero's description, although, with my knowledge of English, I might have translated it incorrectly.

I actually thought it wouldn't be that difficult... Too bad. Okay, I'll go do 100 progress quests. =)

Whatever
User Avatar
#1286
Auto-translated
A player, perhaps, can do that. In any case, it seemed to me that I saw something like that on one of the developer maps. Quests like "collect 100 peasants" definitely work that way.
 

К А
Стикеры GBF в Telegram
User Avatar
#1287
Auto-translated
by the way, yes. But I've already made 50 =_)

by the way, how do you prevent multiple fly signs from overlapping each other?

Added 6 minutes later
[/U]regarding the developers - I'll take a look now. Yesterday, on RedHeavenHero's advice, I found a great script there to determine the number of killed creatures. Most likely, this function still affects the quest, because there were several variables, such as assasins_dead, which then didn't appear anywhere else. I suspect that they "appeared" not in the script, but in the quest progress description. In any case, thank you for the advice.

Added 33 minutes later
no, I didn't find any progress update anywhere. Even in the quest for 1000 heads =)

Whatever
In reply to Heroist
User Avatar
#1288
Auto-translated
Heroist
by the way, how do you prevent multiple fly signs from overlapping each other?

Add pauses between them.
502 Bad Gateway
__________________________________
nginx/0.8.54
User Avatar
#1289
Auto-translated
yes, I had to do it that way. ..

Added 15 minutes ago
here's another question:

I want to reset a hero's mana. I'm writing this:
ChangeHeroStat ('Berein' , 8 , GetHeroStat ('Berein' , 8) - 1000)

1)
ChangeHeroStat ('Berein' , 8 , 0) -- doesn't work


2) and how do I reduce a hero's mana by 10?
ChangeHeroStat ('Berein' , 8 , GetHeroStat ('Berein' , 8) - 10) -- doesn't work

Whatever
In reply to Heroist
User Avatar
#1290
Auto-translated
ChangeHeroStat doesn't set a stat, it modifies it.
ChangeHeroStat('Berein', 8, -GetHeroStat('Berein', 8)) -- all
ChangeHeroStat('Berein', 8, -10) -- ten
Карты для Героев Меча и Магии 5
Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога

Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
User Avatar
#1291
Auto-translated
aaa... damn, I messed up. Thanks.
By the way, I've made some changes to the campaign function that recalculates the number of defeated enemies. But now it works strangely. Can you tell me what's wrong?

Trigger( COMBAT_RESULTS_TRIGGER, "combat_results" );

combat_result_last = -1;
c = 1
i = 0

function combat_results( c )
local we = -1
if GetSavedCombatArmyPlayer(c,1) == PLAYER_1 then
we = 1

if we == 1 then
if GetSavedCombatArmyHero(c,we) == 'Berein' then
local stackscount = GetSavedCombatArmyCreaturesCount(c,0);
creature,creaturescount,died = GetSavedCombatArmyCreatureInfo(c,0,i);
AddHeroCreatures('Berein' , 29 , died)
end;
end;

end
if GetSavedCombatArmyPlayer(c,0) == PLAYER_1 then
we = 0
end;
combat_result_last = c;
end;


--------

Whatever

Statistics

Welcome our newest member: Emil