Skip to content

Posts from Scripts for beginners.

4.5 (2 ratings)
In reply to Азгалор
User Avatar
Auto-translated
Azgalor
Yes, I noticed it already. Well, I overlooked it. By the way, I launched the map, and the script works. It freezes for about 5 seconds, and then starts a combat with a neutral Sinithar with 10 dragons in his army. That's what's happening 👀
The StartCombat command works, but I want actions to happen inside the battle (the idea was to cast Armageddon in the end). Right now, there's just a simple command in the Start function to increase mana, which doesn't work, and the print statement I added to display in the console confirms that it's being executed within the combat script. The lag probably comes from the function that determines the race and then assigns a castle to half of the players based on that determination. Plus, there's the immediate destruction of the current starting castle, which I think is causing the initial slowdown. I don't know how to optimize it yet.

Added 14 minutes later

Right now, the white text in the console is worrying: Warning: scripts are not allowed - this might be the answer, that some kind of permission is missing for this script to work. And this line appears right at the beginning of the battle.

Ещё только учусь =)
User Avatar
Auto-translated
Perhaps it's a multiplayer map? You can download different scenarios and compare them. I don't see any other significant differences compared to my working version.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
Maybe it's a multiplayer map? You can download different scenarios and compare them. I don't see any major differences compared to my working version.
I had a similar thought... That the combat scripts are not for multiplayer. Then I'll have to settle for using StartCombat on triggers when reaching certain locations.

Added 12 hours 41 minutes ago

In general, I browsed through the map section, specifically those marked as multiplayer, and I didn't find a single combat script in the couple of dozen I downloaded... I don't like this trend. There's still hope that maybe it needs to be specified somewhere in the map.xdb and it will start working.

Another question about sleep arose, based on the information from other users who were looking for answers before me. I suspect that the freezes at the start of the map, where many functions are executed simultaneously without waiting for each other, are due to the specifics of Lua. I found an example:

repeat sleep(1) until GetUnitManaPoints(GetAttackerHero())==200 --Sleep until mana is added

I found this code. How can I attach a wait to the MessageBoxForPlayers function? Or to the completion of the function that adds creatures to the players' castles. For now, I'm thinking of a workaround with some boolean variable and checking it for true|false in the sleep function.

Ещё только учусь =)
User Avatar
Auto-translated
Could you please provide some guidance on building construction? I found a section called "Working with Cities" in the Novic manual, but it doesn't contain information on how to build specific buildings or, conversely, demolish them in a castle. I want my players to be able to determine the stage of the game, and for the very early stages, it wouldn't make sense to have too many buildings; having all magic circles available, for example, would be overkill. Is it possible to use a script to selectively build a city according to specific needs?
Ещё только учусь =)
In reply to FataLisT
User Avatar
Auto-translated
FataLisT
Could you please provide some guidance on building construction? I found a section called "Working with Cities" in Novic's manual, but it doesn't contain information on how to build specific buildings or, conversely, demolish them in a castle. I want my players to be able to determine the stage of the game, and for the very early stages, it wouldn't make sense to have too many buildings; all the magic circles would be an overkill, for example. Is it possible to selectively build a city to suit my needs using a script?
UpgradeTownBuilding(TownName,BuildingID)
DestroyTownBuildingToLevel(TownName,BuildingID,Level,CanRebuild = 1) where CanRebuild = 0 sets a new maximum building level equal to Level.
Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.
User Avatar
Auto-translated
Thanks a lot!
I found the IDs in the corresponding document; there's only missing information for the Orcs. I assume that by trial and error and experimentation, we can figure them out.
I'm on my phone right now; I'll try it out in practice this evening.
Does the first team build, and the second team set the level of that building? Are they used in conjunction?
Ещё только учусь =)
In reply to FataLisT
User Avatar
Auto-translated
FataLisT
Thanks, Dolgiy!
I found the IDs in the corresponding document; there's only missing information for the Orcs. I assume I can figure them out through trial and error.
I'm on my phone right now; I'll try it in practice this evening.)
Does the first team build, and the second team set the level of that building, and are they used in conjunction?

The second team destroys the building down to a certain level. For example, a Mage Guild of level 5 down to level 3 (Level = 3) or completely (Level = 0).
Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.
In reply to FataLisT
User Avatar
Auto-translated
FataLisT
I found the identifiers in the corresponding document; only the ones for the Orcs are missing.

TOWN_BUILDING_STRONGHOLD_HALL_OF_TRIAL = TOWN_BUILDING_SPECIAL_1
TOWN_BUILDING_STRONGHOLD_GARBAGE_PILE = TOWN_BUILDING_SPECIAL_2
TOWN_BUILDING_STRONGHOLD_TRAVELLERS_SHELTER = TOWN_BUILDING_SPECIAL_3
TOWN_BUILDING_STRONGHOLD_PILE_OF_OUR_FOES = TOWN_BUILDING_SPECIAL_4
TOWN_BUILDING_STRONGHOLD_SLAVE_MARKET = TOWN_BUILDING_SPECIAL_5

This is from the advmap-startup.lua file, but if you want to look for something else there, it's best to search for the file in a2p1-data.pak.

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

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

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

TOWN_BUILDING_STRONGHOLD_HALL_OF_TRIAL = TOWN_BUILDING_SPECIAL_1
TOWN_BUILDING_STRONGHOLD_GARBAGE_PILE = TOWN_BUILDING_SPECIAL_2
TOWN_BUILDING_STRONGHOLD_TRAVELLERS_SHELTER = TOWN_BUILDING_SPECIAL_3
TOWN_BUILDING_STRONGHOLD_PILE_OF_OUR_FOES = TOWN_BUILDING_SPECIAL_4
TOWN_BUILDING_STRONGHOLD_SLAVE_MARKET = TOWN_BUILDING_SPECIAL_5

This is from the advmap-startup.lua file, but if you want to look for something else there, it's better to search for the file in a2p1-data.pak

Wow! This is a treasure trove of information! Thank you!
Ещё только учусь =)
Auto-translated
Good evening. I tried to activate the script: `StartCombat (hero, Assasin, 3, CREATURE_SCOUT, 7 * 5, CREATURE_ASSASSIN, 7 * 5, CREATURE_WITCH, 5*4 ,nil, nil, nil, not nil)`
It says: "Value was NIL when getting global with name "Assasin""
The hero is created, and the script name is correct. I tried it both with and without a hero on the map. I added it to "AdventureMapProperties/Heroes". The result is the same. What did I do wrong?
In reply to Shiroyasha2910
User Avatar
Auto-translated
Shiroyasha2910
Good evening. I tried to activate the script: StartCombat (hero, Assasin, 3, CREATURE_SCOUT, 7 * 5, CREATURE_ASSASSIN, 7 * 5, CREATURE_WITCH, 5*4 ,nil, nil, nil, not nil)
It says: Value was NIL when getting global with name "Assasin"
The hero is created, and the script name is correct. I tried it both with and without a hero on the map. I added it to "AdventureMapPropetires/Heroes". The result is the same. What did I do wrong?

You need to put "Assasin" in quotes. "Assasin"
Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.
In reply to Долгий
Auto-translated
Long
Assasin needs to be put in quotes. "Assasin"
I did that too. Then it says: the hero is not in reserve. Okay, but how do I put him in reserve then?
In reply to Долгий
Auto-translated
Long

Ah yes, the enemy hero for StartCombat can only be from the reserve.
And what does that mean? How do I put him there?
In reply to Долгий
User Avatar
Auto-translated
If you need a hero from the map, use MakeHeroInteractWithObject.

Added 3 minutes later
Shiroyasha2910
And what does that mean? How do I put him there?

In the editor, press the English letter M. A window will appear. Go to PlayerProperties. Select the AI player to whom the Assassin hero belongs. At the bottom of the window, there will be an empty list called Reserve Heroes List. Click Add and create the Assassin hero there. An army is not required, as it is assigned in StartCombat.
Мои карты: Белый Храм, Поменяться местами, Судьба королевства, Стихийные острова.

Statistics