Skip to content

Posts from Scripts for beginners.

4.5 (2 ratings)
In reply to Азгалор
Auto-translated
Azgalor
Killer5029, for convenience, you can assign any Necromancer hero, and then select him and, on the left, in the object properties, go to his Shared settings, and in the list of Necropolis heroes, select the hero Nikolay, click OK, and the hero will change to Nicholas the vampire.

Thank you very much!
User Avatar
Auto-translated

Hello everyone!

My search for answers led me to the forum; I was also in a VK group and found a guide on battle commands. It's more or less clear what to do with hooks. The problem is understanding whether this script even runs. I suspect it doesn't because the simple print statement in the file isn't displayed in the console.

Briefly, here's the goal: The map is designed for faster battles. But it has grown in detail; for example, the first player chooses the stage of the game through dialog boxes (I will rework them later; I found instructions that you can enter choices with a large number of options). Then they explore the map, equip themselves with dropped items, level up, and finally meet in a battle on a special arena. There's a small plot woven into it. I want to add a couple of Easter eggs and traps to the map. For instance, there's a place where, tempted by seemingly unguarded treasures, the player should go. Upon entering the area via a trigger, a script starts, where they are attacked by a Lord or dragons. I haven't figured out how to make two human players and a neutral hero attacking one or the other exist on the same map yet. I read about reserves but am still having some trouble using them. However, so far, only an evening was spent specifically on this, while more questions arise regarding the combat script. There's a simple command "StartCombat" which initiates the battle. It might be enough if I just use dragon attacks. But my idea goes further. I want either the attacking hero or the hero who fell into the trap (the trapped hero) to come under AI control and cast Armageddon 2-3 times against the black dragons. And then the opponent surrenders. Or perhaps there is a command after the battle ends that determines who wins. I also tried delving deeper into this topic, but couldn't find answers, or maybe I wasn't searching properly. In general, for now, I can only implement it with a text pop-up saying something like, "You greedy thief will pay," and that's it. With great difficulty, I managed to figure out how to add a script file in the game, accidentally breaking the link between the mapscript and the map at the same time. I fixed it by opening the necessary file in Notepad and restoring the reference to the map script. At least the error message disappeared, indicating that the script could not be found at the specified path. But it still doesn't run. I don't understand what I'm doing wrong. I've hit a creative dead end.

I would appreciate it if you could explain step-by-step how it works correctly. I am attaching my map draft. Some of the logic is commented out because I was testing the start of the battle right away (it starts when interacting with a skeleton near the starting castle). So, I need advice on how to write the interaction so that StartCombat launches the battle script, where I want to specify casting an area spell and then retreating attackers. Maybe I'm writing something incorrectly in the wrong place or the script file is somehow incomplete. It looks identical to the MapCsript file. In general, there's a clear lack of knowledge here. I tried assigning the Lord directly to player 3 under AI control, but the script didn't recognize him as an opponent in any way, even for a regular battle without additional scripts for casting spells. When creating the additional script file, print from DragonCombat.lua ran, meaning the map can access it. However, I haven't mastered the mechanics of connecting it yet. I'm looking for what's missing.

A separate thank you to everyone who posted instructions online; the map will undergo major changes. I placed some creatures just to test the balance... everything will be corrected and refined repeatedly. I keep track of versions; there are many lines of code! Currently, the DragonCombat.lua file only contains a draft of my idea. I experimented and debugged it on the fly. After a day, I couldn't figure it out, so I came to ask for advice. Before this, I was working on the map for a couple of weeks in the evenings, just watching what you had here. On the map, according to someone's post, there is an implemented parallel infinite turn. The plan is that everything should happen within one day. And I feel like I'll come back here more than once... Based on new information about the possibilities, I have more ideas, and it might become quite interesting with some references. Hello to the grave in the dungeon, then I'll make a bridge (I read how), and then a battle with a creature. And something else near the pyramids, I'll add that too.

Thank you in advance!

P.S. I remembered another question: I struggled for a couple of days searching the forum but didn't find a good way to add Arantir alongside Markal, Giovanni, and Ornella when creating a map. In the map settings, I enabled all heroes from the campaign. Arantir can be added to the map, but not as a starting hero during creation. My idea is to put him in reserve (I haven't figured out how to do this correctly yet) and summon him through dialogue, such as approaching a prison or interacting somehow. I'll figure out how to implement it.

23.03.2024 01:20 upd: I tried doing it as found in this post /topic/at/1225989/.
Step by step, the only difference is in the file name. Is it really necessary? Can't all combat script files in the map have the same name? O_o). Instead of CombatScript, I have DragonCombat. The main difference I noticed is that in the map settings, the full path to the script file was specified, while previously I just entered the name without the path. Encouraged, I went to test again, and the print statement still didn't display any indication that the script had started. On the positive side, I found a way to add available heroes for player 3 to choose from, although there wasn't a Lord among them. But at least I could pull a hero from the reserve, move him nearby, and activate a battle with him. I noticed that the hero's army doesn't appear; only the creatures I specified when calling StartCombat are present. However, neither by setting the script for the hero and the player or AI, nor by specifying the script in the start of the battle, does the unfortunate print message appear, indicating that the game has entered the script.

  DeployReserveHero("Inagost", 115, 290, 0);
ChangeHeroStat("Inagost", 0, 90000);
--SetHeroCombatScript('Inagost', pathScript.."DragonCombat.xdb#xpointer(/Script)");
--SetHeroCombatScript(p1heroname[0], pathScript.."DragonCombat.xdb#xpointer(/Script)");
StartCombat(p1heroname[0], "Inagost", 1, 84, 10, pathScript.."DragonCombat.xdb#xpointer(/Script)", nil, nil, nil);

I tried invoking the script like this, commenting out lines 3 alternately and completely without them, and in StartCombat, I put nil and left the path to the script. It doesn't work. I'm lost in guessing where the mistake is. So that I can move forward with developing my ideas.

Attachments 1
1 file attached • Total size: 444.4 KB
Ещё только учусь =)
User Avatar
Auto-translated
FataLisT, regarding StartCombat, it's possible that a `sleep(1)` is missing after `DeployReserveHero`. Usually, all functions that modify the map itself are not executed instantaneously when the command is called; a delay is needed before the hero actually appears from the reserve.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
User Avatar
Auto-translated

Jack_of_shadows, thanks! I tried adding sleep(1), but it didn't help. The hero appeared even without the delay; it was visible, although the command was executed. But in general, the command will probably be useful; I'll keep that in mind for the future. I also need to figure out why there's a slight lag when the game starts. Removing the blocking of certain areas from the startup function made it a bit easier.

+ Without calling the hero from the reserve and simply using StartCombat with only mobs and adding a script to the corresponding parameter, there is no call to it.

 

Ещё только учусь =)
User Avatar
Auto-translated

I tested it, and in the map settings within Mapscript, if I set it to DragonScript, it displays the print statement I entered for testing in the game console, confirming that it's accessing the script file. However, as soon as I change it and try to use a command to load the desired combat script to see if the game can access and execute it, it doesn't work.
The lines I'm changing in the map settings are:
Script:Maps\Multiplayer\Grand_Duel\MapScript
Script:Maps\Multiplayer\Grand_Duel\DragonCombat
Therefore, I conclude that DragonCombat.xdb correctly recognizes its *.lua file. But, for some reason that I don't understand yet, it refuses to access the specified script under normal conditions, even though the address seems correct. Otherwise, the corresponding commands would complain about an incorrect parameter.

I need help from an expert).

I also have a couple more questions:
1) I reviewed the instructions for pop-up messages and searched the forum. I couldn't find information on how to create a custom title instead of the "Message" text. I suspect there's an additional argument needed.

2) At the very beginning, when I was dividing the map, I made a mistake and placed wall objects outside the area. I can't select them in any way to delete them. They're just sitting there as a silent reproach). Is there a way to remove these extra objects without having to redo the entire map? I simply moved the current map layout within the visible area and marked everything with convenient squares from the arena object menu.

As soon as a solution is found for correctly accessing the combat script file, I will continue working on creating my own battle scene. Because the thematic element on the map really requires me to bring it to perfection and make the reference to the battle arena on the narrow bridge in the dungeon complete).

Attachments 1
1 file attached • Total size: 39.1 KB
Ещё только учусь =)
User Avatar
Auto-translated
Try specifying the full path without concatenations. Starting with a forward slash. Specifically, "/Maps/SingleMissions/...". Without using GetMapDataPath(). I remember encountering this issue because in S.T.A.L.K.E.R., the main combat script is linked in this way.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
Auto-translated
1) MessageBoxes do not allow you to configure anything via script except for the main text. For more interesting features, it is better to use TalkBoxForPlayers (version 3.1 and later); a description can be found in the FAQ by Jack_of_Shadows.

2) All objects are stored in the objects list in map.xdb. Using a text editor, find the objects with negative coordinates (or exceeding the map size) and delete the corresponding block in the form .... If you know the path to the Shared object, you can find it that way.
С уважением, }{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
Auto-translated

}{0TT@6bI4
Try specifying the full path without concatenations, starting with a forward slash. Specifically, "/Maps/SingleMissions/..." Without using GetMapDataPath(). I remember encountering this issue because in S.T.A.L.K.E.R., the main combat script is linked in this way.
I tried moving this section directly into MapScript.lua. The result is as follows:
DeployReserveHero("Inagost", 115, 290, 0);
sleep(1);
p3heroname = GetPlayerHeroes(3)[0];
print(p3heroname);
ChangeHeroStat("Inagost", 0, 90000);
SetHeroCombatScript(p1heroname, "/Maps/Multiplayer/Grand_Duel/DragonCombat.xdb#xpointer(/Script)");
sleep(1);
StartCombat(p1heroname, "Inagost", 1, 84, 10, nil, nil, nil, nil);

I commented out the other starting functions. As a result, the hero is moved from the reserve, but it still doesn't enter the script. There's a print("open DragonScript") statement for testing. The console is silent, but this line warning: script are not allowed is concerning; the screenshot is attached. Perhaps something is missing, or some settings are needed for the script to work? I'm at a loss (But generally, some warnings kept popping up, and everything else worked.

Regarding the answers to points 1) and 2), thank you very much! I edited the map in map.xdb and quickly found the lines with the incorrect coordinates using the object names. Now everything is aligned, and it looks great. Regarding TalkBoxForPlayers, I'm currently studying how it works and have tested the output; I've implemented it. I just need to finalize it; this option looks much better and more elegant for my purposes.

Attachments 1
1 file attached • Total size: 27.0 KB
Ещё только учусь =)
User Avatar
Auto-translated
FataLisT, have you tried placing the combat script in the root directory of the map? It works for me that way, but I don't remember why it was done like that.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated

Jack_of_shadows
FataLisT, have you tried placing the combat script in the root directory of the map? It works for me that way, but I don't remember why it was done like that.
Jack_of_shadows, if I understand correctly, are you talking about this arrangement? (Attached a screenshot) Currently, both the *.xdb and *.lua files are located in the root folder, as they were originally created. I only moved a bunch of text files into a folder today for testing purposes. And I also rewrote some functions, reducing the number of lines.

Essentially, it doesn't work in this form. I tried enclosing the path in both " and ' quotes. It still won't access the combat script. Again, when I replaced MapScript with DragonCombat, the *.lua script ran from the script when launching the map. The connection within it is properly defined, so that seems to be the issue).

I've attached the current version of the map just in case. Maybe I missed something in the additional settings. At first glance, everything is set up the same way as in other messages I found here.

Attachments 2
2 files attached • Total size: 595.5 KB
Ещё только учусь =)
User Avatar
Auto-translated
FataLisT, no, I meant the root directory, the topmost level, next to the Maps and MapObjects folders. And in the xdb file, the path would simply be "/DragonCombat.lua".
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
FataLisT, no, I meant the root directory, the topmost level, next to the Maps and MapObjects folders. And in the xdb file, the path should simply be "/DragonCombat.lua".
I tried placing it next to Maps and MapObjects, and I changed the path in the *.xdb file using MapEditor - it still doesn't work.
Ещё только учусь =)
In reply to FataLisT
User Avatar
Auto-translated
FataLisT

 

p3heroname = GetPlayerHeroes(3)[0];
print(p3heroname);
SetHeroCombatScript(p1heroname, "/Maps/Multiplayer/Grand_Duel/DragonCombat.xdb#xpointer(/Script)");
StartCombat(p1heroname, "Inagost", 1, 84, 10, nil, nil, nil, nil);

 

The first two lines are related to p3heroname, but the combat script is assigned and the combat is started for a hero named p1heroname. Does the hero p1heroname actually exist?

Update: I opened your map, checked the script, and p1heroname is not mentioned anywhere. So, the question from our (somehow silent in this case) script is: "Who is this p1heroname?!"

Всякое/карты:

Добавление недостающей музыки гномам

In reply to Азгалор
User Avatar
Auto-translated
Azgalor

The first 2 lines are related to p3heroname, and the combat script is attached and the combat is launched for the hero named p1heroname. Does the hero p1heroname actually exist?

Update: I opened your map, checked the script, and p1heroname is not mentioned anywhere. So, the question from our (somehow silent in this case) script is: "Who is this p1heroname of yours?!"

p1heroname is defined in other functions, and the links in "doFile(path.. "Grand_Duel_db.lua");" lead to them. Otherwise, yes, the script would complain, I agree)
p3heroname = GetPlayerHeroes(3)[0];
print(p3heroname);

These 2 lines are only for checking if the game can see the 3rd player's AI hero correctly. They can be commented out, and nothing will change. Also, I inserted this same piece of code into other tests, where the teleport function works through interaction with a skeleton on the map. The result is the same. Now I've moved it to the main MapScript.lua file to quickly check if it works or not. Otherwise, it will be located separately, and it will take a long time to get to it on the map for it to trigger.

I want to attach the combat script to the player's hero, not the AI's. That's why I'm attaching it to p1heroname.

If there is a logical error somewhere, I admit that Lua is very specific. I only have residual knowledge of programming from university).

By the way, I remembered a question: why can't you edit xdb files through MapScriptsEditor?

Ещё только учусь =)
In reply to FataLisT
User Avatar
Auto-translated
FataLisT
p1heroname is defined in other functions, and the references in "doFile(path.. "Grand_Duel_db.lua");" lead to them. Otherwise, yes, the script would throw an error, I agree.
Yes, I noticed that already. Well, I overlooked it a bit. By the way, I launched the map, and the script works. Well... It freezes for about 5 seconds, and then starts a battle with a neutral Sinithar with 10 dragons in his army. That's what happens 👀

Всякое/карты:

Добавление недостающей музыки гномам

Statistics