Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to }{0TT@6bI4
User Avatar
#3640
Auto-translated
}{0TT@6bI4
Specifically, after restarting the map? Only using SetGameVar("variable name", value), GetGameVar("variable name").

I haven't heard about "Twilight of Darkness"; could you elaborate?
I'm not denying that I don't fully understand the specifics of the Heroes engine. My logic is simply this: the map script executes when the map is loaded, and it seems there are no tools to pack your local data (e.g., values of global variables that are redefined during the game) into the save file, so that when the game is stopped and then loaded, the variables retain their previous values. In other words, I haven't found an equivalent of a database for a specific map for dynamic data. I repeat, I might just not have fully understood it.
To make it clearer, here's an example: I have an array of arrays (a table in Lua), where the key is the player, and they have, for example, value1 and value2. I want to change these values during the game. This is easily done, but when the map is saved and then loaded, the array is, of course, empty (because I declare it somewhere in the script that runs when the map is loaded, and it, of course, redefines it to its initial state).
Usually, in such cases, the array initialization is written inside a function, and then something like an isset check is done. However, even there, the data is somehow recorded.

Regarding "Twilight of Darkness": it has a reputation system for the races, implemented through a quest. That is, it works like this: there is an objective named "orcs rep", which has an infinite number of progress stages, i.e., it is not completable (because it has a custom condition, as you know, it can only be completed by a script). And, in fact, when it is necessary to give this quest a certain amount of progress, i.e., increasing the reputation by 5 units will move the quest progress by 5 units. Due to this method, it can be conveniently displayed in the standard in-game quest menu. This is a working method (I checked, it is really possible to implement any reputation mechanics this way), but it seems somewhat illogical to use the quest functionality (which is not intended for this).
User Avatar
#3641
Auto-translated
Even the progress stages cannot be endless; if you start a map from the beginning, all progress for all tasks will be reset to zero, but if you load saves, the values of script variables will also be saved, right?

I just don't understand, you're talking about restarting the map, but in Shades of Darkness, does the progress of tasks persist after restarting the map? No, of course not. So, what kind of storage of local data in tasks can we be talking about?
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
#3642
Auto-translated

That's what I meant about script variables when loading a save file. Of course, I'm not talking about restarting (sorry for the unclear explanation, I'm prone to that).
I'll try a couple of experiments with this (different ways to save data) and report back. I'm just not very happy with "it works, and that's good enough"; I want to understand why it works. : )
Thank you for your patience and help.

Added 4 hours 3 minutes ago
Well, you were absolutely right.
Modern technology has clouded my mind. : )
When saving, the map creates its own "snapshot," so yes, all variables do indeed retain their values. I don't know how I tested it before, but I was convinced that there was a completely different principle at play.
Thank you for setting me straight.
User Avatar
#3644
Auto-translated
Good evening again!
Is it possible to increase the army in a garrison using a script?
I couldn't find any documented function, and I haven't come up with a workaround.
I know that you can get the garrison army using GetObjectArmyTypes().
P.S.:
Putting a hero in a garrison passage and giving him an army is certainly a working idea, but it's not very elegant.
By the way, if anyone knows (although I know there's a separate topic for this), is it possible to reserve heroes for any player?
In principle, you can reserve them for a "fictional" player and change their team upon deployment, but maybe this can be done in the editor.
I couldn't find a way.
And does a method for "reverse reservation" exist? That is, can a hero be moved back and forth using a script? I know that you can allow the hiring of a reserved hero, and you can deploy him.
User Avatar
#3645
Auto-translated
function pack(...)
return arg
end

types = pack(GetObjectCreaturesTypes('garrisonName'))
army = {}
for n, id in types do
  if id > 0 then
    army[length(army)+1] = {id, GetObjectCreatures(id)}
  end
end

-->>>army == {{id, number}, {id, number}, etc.}

You can use any algorithm you like for working with the parameters; this is just an example. GetObjectCreaturesTypes returns the types (IDs) of creatures (and zero if it's not a complete set), and GetObjectCreatures(id) retrieves the number of creatures in the object for a given ID.

С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
#3646
Auto-translated
Regarding the configuration of reserve heroes available to any player, it can only be done through a script. However, I recommend trying to add the same hero to the reserve for all players. To do this, in the Map Properties Tree => players => [0] => ReserveHeroes => copy the AdvMapHero link to the reserved hero and, for other players in ReserveHeroes, add a new element (Insert when the ReserveHeroes property is selected or right-click -> Add), and copy the link into the new element. I haven't tested this method, but it might work. It may cause crashes.
You can remove a hero from the reserve using the UnreserveHero command.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
#3647
Auto-translated
Thank you for your answers. I'll look into the script, try the backup, and let you know if it crashes.
In reply to Jewily
User Avatar
#3648
Auto-translated
Jewill

Is it possible to increase the army size in a garrison using a script?
AddObjectCreatures("scripted garrison name", creature ID, quantity)
In reply to Азгалор
User Avatar
#3649
Auto-translated
Azgalor
AddObjectCreatures("scripted garrison name", creature ID, quantity)
Thank you, it's very strange that this function isn't documented in the "out-of-the-box" manual.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
In reply to Jewily
User Avatar
#3650
Auto-translated
Jewill
Thank you, it's very strange that this function isn't documented in the manual that comes with the game.
Page 10 in the HOMM5_A2_Script_Functions.pdf file or page 9 in the HOMM5_Script_Functions.pdf file.
In reply to Азгалор
User Avatar
#3651
Auto-translated
Azgalor
Page 10 in the HOMM5_A2_Script_Functions.pdf file or page 9 in HOMM5_Script_Functions.pdf
It's amazing how people can be so blind. Thank you very much for the hint.


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
User Avatar
#3653
Auto-translated
Good evening. Does anyone know what the easiest way is to check if a player is an AI?
Is there a function related to AI that returns nil when used on a human player?
So far, my searches haven't yielded any results, and it seems like such a simple thing...


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.


                                                                                       
In reply to Jewily
User Avatar
#3654
Auto-translated
Jewill
Good evening. Does anyone know what the easiest way is to check if a player is an AI?
Is there a function related to AI that returns nil when used on a human player?
My searches haven't yielded any results yet, and it's such a small thing...
Among the official ones, I only noticed IsHuman and IsComputer in combat scripts. But, as I understand it, you need functions for a non-combat script?
In reply to Jewily
User Avatar
#3655
Auto-translated
Jewill
Good evening. Does anyone know what the easiest way is to check if a player is an AI?
Is there a function related to AI that returns nil when used on a human player?
My searches haven't yielded any results yet, and it's such a small thing...

IsAIPlayer(Player_ID)

If the player is human, it returns 0; if it's an AI, it returns 1.

Statistics

Welcome our newest member: leyu