Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
Auto-translated

temnyrizar, you can do it like this. Before the function, add a variable with a number. When the function starts, it will play the scene, display a message box, trigger a quest, and then fill the variable with a number, so that this part of the code will no longer run because the condition is not met:

golemhouse_scene = 0

function golemhouse()
if golemhouse_scene == 0 then
StartDialogScene("/DialogScenes/DefiantMage/S1/DialogScene.xdb#xpointer(/DialogScene)");
MessageBox(quest1);
SetObjectiveState("sec1", OBJECTIVE_ACTIVE, p1);
golemhouse_scene = 1
end
local gems = GetPlayerResource(p1, GEM)
if gremlins >= 1000 and gems >= 100 then
QuestionBox(pyramidpath, "yes", "no");
end
end

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

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

In reply to Азгалор
Auto-translated
Dear experts! I really need your help. I'm currently playing the "Throne of the King" add-on for Heroes 5. At some point, I added a skill to a hero using the command `add_skill 142` in the console. The "LUCKY WIZARD" skill appeared. Now I need to remove this skill, and I tried to use the command `unlearn_skill 142`, but it doesn't work. The console displays an error in red and shows this:
      Unknown command name "unlearn_skill 142"
      Type "help" to list available commands.
I enter "help", and it displays something completely incomprehensible. I'm a novice in this, but maybe someone can help me figure out this problem? How can I remove an unnecessary skill or ability without a mentor? Thank you in advance.
Auto-translated
Good day! Is it possible to create a self-expanding table if I don't initially know the number of rows or if it is large enough that declaring it entirely in code with 100 rows would be impractical? For example: Table = {}; -- declare a global variable as an array (table) for i = 1, 100 do Table[i]["a"] = 'a'; Table[i]["b"] = i; ... end; With the current structure, the game freezes completely. The same thing happens if you try to add another row to an existing table (i.e., you are referencing a non-existent index). Lua guides contain constructs that the game doesn't even recognize!
User Avatar
Auto-translated
landw1rt, sure, you can, just try adding one dimension at a time, like this:

Table = {};

for i = 1, 100 do
    Table= {};
    Table["a"] = 'a';
    Table["b"] = i;
    ...
end
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
Auto-translated
Jack_of_shadows
landw1rt, sure, you can; just try adding one dimension at a time, like this: end

You're welcome!
Auto-translated
Is there a way to add icons of creatures to custom messages that appear when units leave a hero’s army, similar to how the Necromancer displays creature summoning after battles using Dark Energy?
User Avatar
Auto-translated
Good day, I can't get the script to write correctly.
I need all Sorceress units in the army of the red opposing player to be removed by 25% of their count if the blue player has Alaric.
I've tried a million options (set conditions for both red and blue - the code works super glitchy, it only works when there are only 2 different tier-2 creatures, or when there are 3 creatures all upgraded; I moved the request to get the creature count before and after the if statement and added "and" checks and ">=0" checks, but it just won't work as intended.
My console doesn't turn on, so I can't check why it's breaking.
I also can't try combat scripts; the code doesn't see the link to them from the main mapscript.lua.
I'm writing this from a phone and not copying, so I'll only convey the essence of the code:

I'll write an example for human Sorceress units, but I wrote it for all races

Tried it like this:
if GetObjectOwner ("Alaric") ==2 and I put checks >=0 and "and" and "or"
then
RemoveHeroCreatures(heroname, 10, 0.25*GetHeroCreatures(heroname, 10))
RemoveHeroCreatures(heroname, 110, 0.25*GetHeroCreatures(heroname, 110))
RemoveHeroCreatures(heroname, 112, 0.25*GetHeroCreatures(heroname, 112))
end and I put elseif and else, everything is off or glitchy
trigger for red

I also wrote a trigger for blue where I checked like this:
if heroname alaric
then
for i ,hero in hero1 do
I wrote the request for creatures here and before/after the "for i" lines
remove creatures(hero, id, 25% of count)

and I named them in all variations, for example inkviz=getherocreatures(tried both heroname and hero)

The code works either on some of the creatures or when all 2-3 types of creatures are present; in short, I'm asking for help.
In reply to green belly
User Avatar
Auto-translated
green belly, what's the deal with your console? Have you tried enabling it using guides from the internet by modifying files in the profile parameters folder? And could you provide more details regarding the attempt to work with the combat script? If, of course, all this is still relevant to you

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

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

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

Azgalor
green belly, what's the deal with your console? Have you tried enabling it using internet guides by modifying files in the profile parameters folder? And could you provide more details about the attempt to work with a battle script? If all this is still relevant to you, of course
I tried both the console and the battle script; neither of them works for me. I've reread every possible and impossible guide and even the rarest tutorials I could find on the internet.
In the end, I implemented static creature destruction, but if it's not too much trouble, could you suggest the correct code for percentages? It will definitely be useful for me and other forum members in the future. I am absolutely sure that the code for this effect is super easy for those who know their stuff.
Also, I have a few more questions; maybe someone knows:
1) The idea is a simplified draft: 3-4 random heroes are rolled at the start of the map and you play with them. Question — how do I make it so that at the start of the map, the player is given 3-4 random heroes (including those created from scratch) of the race they chose in the foyer?
The editor doesn't provide this capability, and I haven't found any such scripts in tutorials or across the web.
2) The idea is a special hero ability that gives a stat to a hero if the enemy hero's stat is lower. Similar to Alaric from the message above — request the stats of the enemy heroes (there is always only one there, but it's random), and if my hero's stat is higher, then the rest of the code for increasing the stat is simple. I tried it — the game crashes upon triggering.
3) How do I change spell icons to my own? I use a mod myself, I think by Dreadknight, for mass icons; I did it similarly, including creating a new object in the texture folder and so on with all the links, but the result is always the same — the game won't launch.
4) How do I change the speed of the hero teleportation animation on the adventure map? It's very slow in the Universe mod client.
5) How to properly work with tables and random(). There are no good tutorials for this, only examples with "IT-style" characters that you can't even find on a keyboard, let alone figure out the logic.
The most banal example:
table "artifacts" = {id1, id2... id50}
if hero name is "Alaric"
then
teach "Alaric" a random spell from the table "artifacts"
Something like that, but even here I can't understand the logic: what to write where and what will be taken from where.
P.S. A long time ago on the forum, I asked about the speed of disappearing messages in battle, like "miss", Orc blood points, number of creatures killed, number of resurrected, etc. — this parameter in the autoexec_a2.cfg file is easy to change

User Avatar
Auto-translated
green belly, generally speaking, this isn't the thread where such things are discussed (after all, this thread is specifically for scripts), but still: in what sense are your combat scripts(?) and console not working? Is the system preventing you from editing game files?

Regarding percentages — I haven't actually worked with them, but I assume that since we have a 25% deduction here, which won't always be a whole number (for example, the calculation might yield 0.25 or 0.75), it is advisable to perform this calculation so that a whole number always remains. For instance, let's take the ceil(n) command, which returns the nearest integer rounded up (so that even 1 unit can be removed with this code). It would look something like this:

function procent( heroName )
if heroName == "Alaric" then
RemoveHeroCreatures("Alaric", 110, ceil(0.25*GetHeroCreatures("Alaric", 110)))
RemoveHeroCreatures("Alaric", 111, ceil(0.25*GetHeroCreatures("Alaric", 111)))
RemoveHeroCreatures("Alaric", 112, ceil(0.25*GetHeroCreatures("Alaric", 112)))
end
end

Trigger( PLAYER_ADD_HERO_TRIGGER, PLAYER_2, "procent" )

Alaric somehow becomes the blue player (either hired or transferred via script), and 25% of his units will be subtracted (provided they are already in his army. Otherwise, the script will throw an error due to their absence). But this is simple code that will work specifically for these creatures if they already exist, like if we just need to weaken a conditional map "boss". If you need an actual list of creatures to be cut, and more than once per scenario, it's better to create an array with IDs that is run through a for loop, and then calculate who can be subtracted and who cannot. Something like this:

function procent( heroName )
if heroName == "Alaric" then
units = {106, 107, 108, 109, 110, 111, 112} --тут у нас список ID существ, которых будет проверять и удалять. Для теста вписал всех красных юнитов
procent_units = length(units)
for i = 1, procent_units do
ready_to_reduce = GetHeroCreatures( "Alaric", units)
if ready_to_reduce > 0 then
print("Отнимем ", ceil(0.25*GetHeroCreatures( "Alaric", units)) ," из существ ", units)
RemoveHeroCreatures("Alaric", units, ceil(0.25*GetHeroCreatures( "Alaric", units)))
end
sleep(2)
end
end
end

Trigger( PLAYER_ADD_HERO_TRIGGER, PLAYER_2, "procent" )

It will turn out that even upon repeated hiring by the blue player, Alaric will lose creatures. Well, this is just for your information; you can edit it to suit your needs :)

As for the rest:

1) I think you should put all heroes (that can be hired in the tavern) into reserve, list them in an array, randomly choose which one of them to spawn, and then bring everyone out of reserve. Well, that's probably possible, though I don't know how the tavern will work with such heroes.
2) And what did you write? Stats are checked via GetHeroStat(heroName, STAT_)
3) If the game doesn't launch, most likely you have a texture setting that is incompatible with the game engine. It simply cannot process it and crashes on startup. Open one existing in the game and compare it with yours. Specifically, try saving with different parameters so that your texture size becomes equal to or very close to the original
4) Try editing the spell configs, maybe it'll speed up) Just not in the original resource folder, but in your own, like for a mod. Don't touch the original data and its patched versions)
5) There was info on tables, either here or in general questions about the editor. Perhaps it's in Hottabych's group among the documents) Another option — it's embedded with the script editor files (by the way, I recommend using them, they help)

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

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

Statistics

Welcome our newest member: Emil