Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to }{0TT@6bI4
User Avatar
Auto-translated
}{0TT@6bI4
You can only transfer data through SetGameVar, though.

There is a trigger for the end of the battle, which passes the battle index to the function. And using the battle index, you can get all the information about the destroyed creatures using GetSavedCombat.... It's in the tutorial and also on the forum, Jack of Shadows explained it (searching for GetSavedCombatArmy site:heroesworld.ru should give you results).
Wow, thanks! I didn't even notice this functionality in the guide before. Listen, I wanted to find out something. In the developer maps, I saw quest skeletons that save the main heroes by tracking their existence through loops (IsHeroAlive), or through their loss through a trigger (PLAYER_REMOVE_HERO_TRIGGER). So, I became curious, which of these would be less resource-intensive for the map? Which approach should be preferred for script optimization?

Added 1 hour 50 minutes ago
I don't understand how these functions work. I wrote the script:
enemieskilledcounter = 0;
SetTrigger( COMBAT_RESULTS_TRIGGER, "WR_Revenge" );

function WR_Revenge( combatIndex )
print("Function started")
if ( GetSavedCombatArmyHero( combatIndex, 1, "WR" ) == true ) and ( GetSavedCombatArmyCreaturesCount( combatIndex, 2, 112 ) == true ) then
print("Passed the checks")
local revenge_target, count, died = GetSavedCombatArmyCreatureInfo( combatIndex );
print("Passed local")
if revenge_target == 112 and died >= 1 then
print("Passed the check for the death of at least one angel")
enemieskilledcounter = enemieskilledcounter + died;
print("Hero killed ", enemieskilledcounter ," angels");
end
end
end

However, "print("Passed the checks")" is not displayed, which means the checks are not working. How should I write them then? The developers described everything vaguely in the document, i.e., not at all.

In reply to Азгалор
User Avatar
Auto-translated
Azgalor
So, it becomes interesting, which of these will be less demanding on the map? What should be prioritized for script optimization?

If the developers aren't incompetent (and they aren't), then it should be done through a trigger. Because a trigger that's not active doesn't execute until the corresponding event is called. But a loop constantly executes, which puts more load on the map.
In your script, in
GetSavedCombatArmyCreatureInfo( combatIndex );

you only passed 1 argument, but you also need to specify 0 as the second parameter (0 for the losing side, 1 for the winning side), and the third argument should be the index of the army slot to check. Accordingly, it's better to write a loop that checks all slots.
That's why it's not working. The manual doesn't explain it very well, but as Khottabych already pointed out, it was discussed on the forum.



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

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


                                                                                       
In reply to Jewily
User Avatar
Auto-translated
Jewily
If the developers aren't incompetent (which they aren't), then it's done through a trigger. Because a pending trigger doesn't execute until the corresponding event is called. And a loop constantly executes, which puts more load on the map.
In your script, in
GetSavedCombatArmyCreatureInfo( combatIndex );

you only passed 1 argument, but you also need to specify 0 as the second parameter (0 for the losing side, 1 for the winning side), and the third argument should be the index of the army slot to check. Therefore, it's better to write a loop that checks all slots.
That's why it's not working. The manual doesn't explain it very well, but as Khottabych pointed out, it was discussed on the forum.

Thank you for the answer. Unfortunately, I only found messages that Khottabych and I left ourselves when searching.

Regarding my script, I rewrote it a bit and it started working! However, after checking the stacks and finding the first one occupied by any creature, the script complains about "Invalid creature index" and displays some number. For example, 2 (as I understand it, this is the occupied stack that was in combat with the hero). Is this a critical error? Or can I ignore it, thinking "Well, it's good enough!"? :D

The script now looks like this (everything works, print outputs the correct number of fallen enemies)

function WR_Revenge( combatIndex )
print("Function started") --Delete
if GetSavedCombatArmyHero( combatIndex, 1 ) == "WR" then
print("Hero checked")
if GetSavedCombatArmyCreaturesCount( combatIndex, 0, 112 ) >= 1 then
print("Creatures checked")
for i=0,6 do
local revenge_target, count, died = GetSavedCombatArmyCreatureInfo( combatIndex, 0, i );
print("Local passed")
if revenge_target == 112 and died >= 1 then
print("Check for at least one angel's death passed")
enemieskilledcounter = enemieskilledcounter + died;
print("WR killed ", enemieskilledcounter ," angels");
end
end
end
end
end
In reply to Азгалор
User Avatar
Auto-translated
Basically, if there are no creatures in a particular index, it will throw an error. I don't know of a way to catch this error other than using error hooks or pCall, so for now, just ignore it; I don't see the point in you worrying about catching errors right now. If it becomes a problem, feel free to reach out. It's annoying, but I don't know how to determine which indices contained creatures. P.S. Don't slots start at 1?


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

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


                                                                                       
In reply to Jewily
User Avatar
Auto-translated

Jewily
Basically, if there are no creatures in that index, it will give you an error. I don't know of a way to catch this error other than using error hooks or pCall, so for now, just ignore it; I don't see the point in you worrying about catching errors right now. If it becomes a problem, let me know. It's annoying, but I don't know how to determine which indices contained creatures.
P.S.
Don't slots start at 1?
Got it. I'll try adjusting the text to fit this function now. I hope it works as intended and without any issues, and I don't really care about console errors that don't break the game :D

The manual says it starts at 0.

"The stack index number is selected with the "creatureIndex" parameter and counts off from 0."

User Avatar
Auto-translated
The loop will put a load on the map (albeit a small one) constantly. The trigger will spend a noticeable amount of time at the start of the map, but won't put a load on it afterward. The most optimized option is to create a HERO_MUST_SURVIVE task, if, of course, it needs to work from the very beginning. Perhaps, it's possible to organize auto-activation based on conditions using dependencies, but I don't know how.

Regarding the "Invalid creature index" error: it's possible that if a creature is missing in the i-th stack, the GetSavedCombatArmyCreatureInfo function issues a warning. To catch it, you can add a print statement inside the loop after retrieving the information: print(i, "-th iteration passed"), and see what prints are output. If the prints are mixed with the error, then it's just a warning; if one of the 7 prints doesn't appear, then it needs to be fixed.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
Azgalor, you really couldn't Google it; you could only use Yandex. Here’s Jack Shadows’ post about these features:
/topic/at/966879/
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
}{0TT@6bI4, understood. Well, I guess I'll track the death of the main character using a trigger; that's what I was planning to do anyway. Thanks for pointing out the error. I added the following to my script:
n_stacks = GetSavedCombatArmyCreaturesCount(id, COMBAT_LOSER);
for i = 0,(n_stacks-1) do

From the message by Jack_of_shadows, I replaced what was there, and the error stopped occurring. Strange, I used the forum search with keywords (GetSavedCombatArmy) and couldn't find his message. Why is that?

User Avatar
Auto-translated
I don't know... I haven't used the forum's search function; I searched via Yandex, and the first page of results was what I found.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
Hello! I have a question: does the following function exist:
GenerateMonsters(monsterTypeID, countGroupsMin, countGroupsMax, countInGroupMin, countInGroupMax);

The question is whether it is possible to link the generation of names for creatures to this function. For example, I want creatures to be given names when they spawn, so that it is possible to interact with them in some way using scripts. Or will I have to create my own spawner for this?

Auto-translated
Jewily, Hottabych, thank you, everything works.

I've been quite into textures lately, but now I'm getting back to scripts.
Tell me, does anyone know how to create a custom object and apply custom textures to it?
I can create objects, but they are only saved in the map folder, and if I remove such an object from the map, I don't know how to access that folder later.
I have to delete the object from the folder and then recreate it on the map.

And I can only replace the original textures by placing the ones I've drawn in the Data folder (at least I don't have to pack them into the original archive), but that's probably not the right way to do it.
Besides, it doesn't always give the desired result.

For example, there's an object called T-river in the editor
(it's located in Model:_(Model)\TerrainObjects\Grass\Rivers\T-river.(Model))
And this object is buggy; it doesn't have a texture for the stone riverbank, only the water itself.
I could quickly draw a texture, but I don't understand how to apply it.
If, for example, I do it through an xdb file, then, firstly, there is such a file for this model, but it doesn't say anything about the texture.
And secondly, it's not clear where to put this file later. Should I also put it in the Data folder?

Sorry if the question is off-topic (although xdb files are directly related to scripts).
User Avatar
Auto-translated
Azlagor, no, but you can create an identical monster generator using a coordinate randomizer and a loop that calls CreateMonster N times. Marta. I recommend visiting the group in my profile description; there's a post by Matvey Rachinsky with his guide on creating new objects. It's better to create new ones than to ruin the old ones. It's easier to modify textures in the editor: Configure the advanced map editor and select the Texture table. When you open the editor, make sure the Resource => Close MOD button is grayed out (if not, click it). The Texture table will contain a list of all textures by folder; you can open folders and textures by double-clicking. When you open a texture, it will be fully displayed in the black space on the right. In the texture properties (if there are no properties, click View => Selection Properties Window), find SrcFile and click the three dots. Select the desired file from the Complete folder of your game. Of course, before you start, you need to create a Complete folder in the game folder and put the new texture in tga format into it. After you select the texture in SrcFile, right-click on the texture file in the properties tree => Export. That's it, the texture is done. All created files will be located in GameFolder/data/; all that remains is to put them into the map
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
Azgalor, I warn you: when I was testing, none of the functions that dynamically generate objects registered their names in the game, and scripts couldn't be attached to them. Unfortunately, I couldn't solve this problem. But maybe monsters will work: resources and artifacts don't.


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

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


                                                                                       
In reply to Jewily
User Avatar
Auto-translated
Jewily
But perhaps it's the monsters that will work: resources and artifacts don't work.
Can artifacts and resources be respawned? I know that the CreateStatic function wasn't documented, and I haven't seen any information about a resource spawner before. Is something like that available?
In reply to Азгалор
User Avatar
Auto-translated
Azgalor
Is it possible to respawn artifacts and resources? I know that the CreateStatic function wasn't documented, and I haven't seen any information about a resource spawner before. Does something like that exist?
Yes, it exists, but it's also undocumented. CreateTreasure(ScriptName, type, Qty, x, y, floorID, rot) Despite the presence of the first argument, the game won't react in any way to the appearance of such an object. That is, the function can be used once (not assuming, for example, constantly generated resources based on conditions). With artifacts, it's almost the same; the arguments are the same, but instead of type, it will be its ID, and qty will not be used at all. And the function name is CreateArtifact.


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

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


                                                                                       

Statistics