Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
Azgalor, I had to think about it for a while, but in this case, you definitely need to pass all 5 answer options. If only 2 are used, add , nil, nil, nil after them.

Yes, now everything works as it should. Many thanks! And not just for that, but also for the scripts related to the artifact table.

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

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

User Avatar
Auto-translated
Friends, how can I implement simultaneous animations? Currently, because the lines of code are executed sequentially, there is a slight desynchronization. I also wanted to ask about the pause between animations. I've set it to IDLE for now, but in that case, objects immediately start a new animation after the current one finishes, and I need a pause. I currently have the idea to implement all of this using functions and loops. Am I thinking about this correctly? And if it's too much trouble to explain, maybe someone knows in which scenarios such animations have been implemented? I can look into them myself and see how it's done.
In reply to Madara_X
User Avatar
Auto-translated
Madara_X,
Madara_X
How can I implement simultaneous animations? Currently, because the lines of code are executed sequentially, there is a slight desynchronization. I also wanted to ask about the pause between animations. I've set it to IDLE, but in that case, the objects immediately start a new animation after the current one ends, and I need a pause.
Write PlayObjectAnimation("scripted creature name", "animation", ONESHOT(ONESHOT_STILL if it's a death animation (optional)), then write sleep(desired delay time), and then write PlayObjectAnimation() again, which will execute after the delay from sleep().
Madara_X
In what scenarios have such animations been implemented?
The first mission of the campaign for Freya in Lords, the animations of training creatures in the camps of Randall and Coldwell. To avoid having to run around and reveal the fog of war on the map, you can enter @OpenCircleFog(0, 0, 0, 999, 1); in the console

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

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

In reply to Азгалор
User Avatar
Auto-translated
Hello everyone, I need help writing a script. The idea is that any random hero enters a specific building, and this building checks if the hero has a perk and gives him a bonus for that perk. The problem is that I need to check if the hero has multiple perks and give him multiple bonuses if he has them. I've only learned how to write code to check for one perk, and the game doesn't read any further. I'm asking coders for help; I need a simple script of this type: function perksF(heroname) if "hero has skill" (heroname, for example, the skill "Archery") then "add creatures to hero" (heroname, for example, "Archers," quantity 1) also if "hero has skill" (heroname, for example, "Expert Logistics") then "add artifact to hero" (heroname, for example, "Shackles of Fate," non-transferable) also if "hero has skill" (heroname, for example, "Advanced Logistics") then "change hero stat" (heroname, for example, "Defense," +2) also if "hero has skill" (heroname, for example, "Advanced Light Magic") then "teach hero spell" (heroname, for example, "Slow," expert level) end end Trigger (hero touches object named "tttt," launch function perksF) The examples themselves can be different; the principle and logic of writing the code are important, so that one touch trigger checks a large number of perks and gives the hero creatures, an artifact, or a spell. It also needs to include a "nil" check, so that the touch works only once and doesn't give bonuses a hundred times. I would be grateful for an explanation. Another question: I need a script that will work at the start of a battle. StartCombat: if a Necromancer hero is present in the battle and has the "Leadership" perk, then the enemy hero receives -1 to morale, and similarly for the advanced and expert levels, -2 and -3 morale. Thank you for your help.
In reply to green belly
User Avatar
Auto-translated
green belly
Hello everyone, I need help writing a script code. The idea is that any random hero enters a specific building, and this building checks if the hero has a perk and gives him a bonus for that perk. The problem is that I need to check if the hero has many perks and give him many bonuses if he has them. I only learned how to write code to check for one perk, and the game doesn't read further. I ask coders to help, I need a максимально simple script of this kind: function perksF (heroname) if "hero has skill" (heroname, for example, the skill of archery) then "add creatures to hero" (heroname, for example, archers, in the amount of 1) also if "hero has skill" (heroname, for example, skilled logistics) then "add artifact to hero" (heroname, for example, shackles of fate, non-transferable) also if "hero has skill" (heroname, for example, advanced logistics) then "change hero stat" (heroname, for example, defense, +2) also if "hero has skill" (heroname, for example, advanced light) then "teach hero a spell" (heroname, for example, slow at the skilled level) end end Trigger (hero touches an object called tttt, launch the perksF function) The examples themselves can be different, the principle and logic of writing the code are important, so that one touch trigger checks a large number of perks and gives the hero creatures, an artifact, a spell. It also needs to have a nil condition, and the touch should work once and not give bonuses a hundred times. I will be grateful for the explanation. Another question: I need a script that will work at the start of a battle. Startcombat if there is a necromancer hero in the battle and if he has the leadership perk, then the enemy hero receives -1 to morale, and similarly for the advanced and skilled level, -2 and -3 morale. Thank you for your help.
Here is an example of my code for checking magic skills and giving spells according to the school. You can do the same with creatures and other things.



Added 9 minutes ago
Friends, can you tell me how many simultaneous functions can be executed in the game? I am currently working on character animations: I create separate functions and launch them using startThread(), but I noticed that exactly on the second startThread() command, the game freezes completely. If I combine all the animations into one function, then everything is okay.
User Avatar
Auto-translated
green belly, regarding perks: the most convenient way (probably) would be to create a table where you enter the perks, the type of reward for the perk, and accordingly, the rewards for different levels of mastery. Then, write a function that checks for the presence of the necessary perks and their mastery level, determines the type of reward that should be given, and issues the reward. Regarding stats for combat: I think you can determine which race a hero belongs to using HasHeroSkill(heroName, ID of racial stats (like "master of artifacts" for mages, "counterattack" for knights, "avenger" for elves, "necromancy" for necromancers, etc.), and if the hero has a particular stat (and, by default, a hero can only have one), assign it to the appropriate race. The same applies to leadership, but to check the mastery level, you need to use the function GetHeroSkillMastery(heroName, skill ID), which returns a number from 0 to 4 (0 - does not possess the perk at all, 1-3 - beginner/developed/proficient, 4 - perfect (like only for racial perks, such as "Perfect Counterattack"). I remind you that perfect levels of racial perks are obtained only through the "Pendant of Mastery" artifact), and according to the mastery level, apply GiveHeroBattleBonus(heroName, HERO_BATTLE_BONUS_MORALE, -the required number). P.S. The battle bonus function only works in version 3.1

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

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

In reply to Madara_X
User Avatar
Auto-translated
Madara_X
Friends, could you tell me how many simultaneous functions can be executed in the game? I'm currently working on character animations: I create separate functions and launch them using startThread(), but I noticed that the game freezes completely after the second startThread() command. If I combine all the animations into one function, then everything works fine.
There can be many threads (within reason; perhaps on a few dozen, someone might start experiencing lag). Personally, just to be safe, I only run creature animations if the player is nearby (you can, for example, check the distance between the hero and the creature at the beginning of the turn), but that's just my paranoid mode. Please provide a simple example of how you are launching them and what is happening.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
User Avatar
Auto-translated
Madara X, Azgalor, thank you for your answers. I've figured out how to check multiple perks in one script. But I still can't figure out how to grant bonuses using givebattlebonus.
I need an example of the code. Maybe some forum users have maps or examples where this code is used.
I'm looking for the following examples:
1) If a hero has skill A, then grant THIS HERO a bonus for one battle (e.g., +1 to creature speed, +BD, +stat, or +1% to creature HP).
2) If a hero has skill B, then grant the OPPONENT'S HERO a bonus for one battle (e.g., -1 to creature speed, -1 BD, luck, etc.).
3) If a hero has skill C, then this hero casts spell D at the beginning of all subsequent battles.
Thank you for any examples and help!
In reply to green belly
User Avatar
Auto-translated
green belly
Madara X, Azgalor, thank you for your answers. I figured out how to check multiple perks in one script. But I still can't figure out how to grant bonuses using givebattlebonus.
I need an example of the code. Maybe some forum users have maps or examples where this code is used.
I'm looking for the following examples:
1) If a hero has skill A, grant THAT HERO a bonus for one battle (e.g., +1 to creature speed, +defense, +stats, or +1% to creature HP).
2) If a hero has skill B, grant the OPPONENT'S HERO a bonus for one battle (e.g., -1 to creature speed, -1 defense, luck, etc.).
3) If a hero has skill C, this hero casts spell D at the beginning of all subsequent battles.
Thank you for any examples and help!
Here are the stats you can change for heroes in GiveHeroBattleBonus(heroName, bonusType/bonusID, +-(if you need to add, don't put a + (otherwise the script will give an error)) amount). These are the IDs and names of the bonuses that can be increased or decreased (except for Hitpoints, which can only be increased):
HERO_BATTLE_BONUS_LUCK = 0
HERO_BATTLE_BONUS_MORALE = 1
HERO_BATTLE_BONUS_ATTACK = 2
HERO_BATTLE_BONUS_DEFENCE = 3
HERO_BATTLE_BONUS_HITPOINTS = 4
HERO_BATTLE_BONUS_INITIATIVE = 5
HERO_BATTLE_BONUS_SPEED = 6

Accordingly:
function buffsForbattle()
if HasHeroSkill("Duncan", SKILL_LUCK ) then
GiveHeroBattleBonus("Duncan", HERO_BATTLE_BONUS_SPEED, 1)
elseif...... and so on.
end
end

Regarding spells: you need to use SetGameVar and GetGameVar to pass the information so that the game knows what you want to pass from the adventure script to the battle script.

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

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

User Avatar
Auto-translated

Can anyone help me identify the error in my code? Everything works except for the line that adds a stat to the hero. I wrote the code based on the Heroes of Might and Magic guide:

function arena1F()
gold = GetPlayerResource(1, 6);
if gold >= 2000
then
QuestionBox("/Maps/Multiplayer/arena/napadenie1.txt", "yes", "no");
else MessageBox("/Maps/Multiplayer/arena/napadenie1nexvatka.txt");
end;
end;
function yes()
SetPlayerResource(1, 6, gold-2000);
ChangeHeroStat(heroname, STAT_ATTACK, 1);
end;
Trigger(OBJECT_TOUCH_TRIGGER, "arena1", "arena1F");

All the messages work, the gold amount checks work, deducting 2000 gold works, but the attack bonus isn't applied to the hero.

I tried adding sleep(1) after the gold deduction line, I tried adding/removing heroname, I changed the name of "yes" to something else to avoid conflicts with other "yes" functions (there are many such objects on the map), I wrote the code to add attack as the first line and without the second line deducting gold, but it still doesn't work.

What could be the problem?

In reply to green belly
User Avatar
Auto-translated
green belly, the game doesn't know what a hero name is, to which it should add +1 attack. Here's a working version + I added a function for a negative response (because in your case, as I see, there should also be a function for a negative response):
function arena1F(hero)
  arena1Fhero = hero
  gold = GetPlayerResource(1, 6)
  if gold >= 2000 then
    QuestionBox("/Maps/Multiplayer/arena/napadenie1.txt", "yes", "no")
  else
    MessageBox("/Maps/Multiplayer/arena/napadenie1nexvatka.txt")
  end
end

function yes()
  SetPlayerResource(1, 6, gold - 2000)
  ChangeHeroStat(arena1Fhero, STAT_ATTACK, 1)
end

function no() -- this is just an example of what will be called if you press No. The code can be changed to suit your needs, or the function call can be completely removed when refusing, by replacing "no" with nil in QuestionBox
  SetPlayerResource(1, 6, gold - 2000)
  ChangeHeroStat(arena1Fhero, STAT_LUCK, 1)
end

Trigger(OBJECT_TOUCH_TRIGGER, "arena1", "arena1F")

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

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

In reply to Азгалор
User Avatar
Auto-translated
Azgalor
green belly, the game doesn't know what a heroname is, to which it should add +1 attack. Here's a working version + I added a function for a negative response (because in your case, as I see, there should also be a function for a negative response):
function arena1F(hero)
arena1Fhero = hero
gold = GetPlayerResource(1, 6)
if gold >= 2000 then
QuestionBox ("/Maps/Multiplayer/arena/napadenie1.txt", "yes", "no")
else MessageBox("/Maps/Multiplayer/arena/napadenie1nexvatka.txt")
end
end

function yes()
SetPlayerResource(1, 6, gold-2000)
ChangeHeroStat(arena1Fhero, STAT_ATTACK, 1)
end

function no() --this is just an example of what will be called if you press No. The code can be changed to suit your needs, or the function call can be completely removed when refusing, by replacing "no" with nil in QuestionBox
SetPlayerResource(1, 6, gold-2000)
ChangeHeroStat(arena1Fhero, STAT_LUCK, 1)
end

Trigger(OBJECT_TOUCH_TRIGGER, "arena1", "arena1F")
Thank you, it worked)
User Avatar
Auto-translated

Here I am again with questions((
I'm reading information online, but I still can't figure out how to write it correctly.
Input data:
1) There are 8 players on the map - each player is on their own - all different factions - each has their own "leveling zone".

2) Each player has their own building with a scripted name - let's say zdanie1 for the first player - zdanie2 for the second, and so on up to 8 players.

What needs to be coded:
1) A random hero of player 1 touches their building zdanie1, and there is a check for a skill. If the skill exists, a combat bonus is given to random HEROES OF THE OPPONENT players 2-8.

This is the key point of the entire script; it's for the OPPONENT's hero.

The same applies to other players and their buildings.
A random hero of player 2 touches their building zdanie2, and there is a check for a skill. If it exists, a combat bonus is given to all opponent heroes, i.e., the heroes of players 1, 3-8.
And so on for all players.
2) I understand that the code should look something like this (the code will be below in point 3), but I can't quite finish it.

It should be noted separately that I have learned how to give skills, spells, artifacts, and combat bonuses through a touch trigger, but only to the one who touches the building (on my map, this is equivalent to giving a bonus to MY hero, since each has their own building), and I am very grateful to AZGALOR for this.

3) My test code that DOESN'T work, but tries, so a hero touches and let's go:

function zdanie1F()
hero1 = GetPlayerHeroes(PLAYER_1);
hero2 = GetPlayerHeroes(PLAYER_2);
hero3 = GetPlayerHeroes(PLAYER_3);
hero4 = GetPlayerHeroes(PLAYER_4);
hero5 = GetPlayerHeroes(PLAYER_5);
hero6 = GetPlayerHeroes(PLAYER_6);
hero7 = GetPlayerHeroes(PLAYER_7);
hero8 = GetPlayerHeroes(PLAYER_8);
geroi1 = hero1
geroi2 = hero2
geroi3 = hero3
geroi4 = hero4
geroi5 = hero5
geroi6 = hero6
geroi7 = hero7
geroi8 = hero8
if HasHeroSkill (geroi1, let's say the Navigation skill)
then
GiveHeroBattleBonus (geroi2, morale bonus, -3);
GiveHeroBattleBonus (geroi3, morale bonus, -3);
GiveHeroBattleBonus (geroi4, morale bonus, -3);
GiveHeroBattleBonus (geroi5, morale bonus, -3);
GiveHeroBattleBonus (geroi6, morale bonus, -3);
GiveHeroBattleBonus (geroi7, morale bonus, -3);
GiveHeroBattleBonus (geroi8, morale bonus, -3);
Trigger (OBJECT_TOUCH_TRIGGER, "zdanie1", nil);
end;
end;
Trigger (OBJECT_TOUCH_TRIGGER, "zdanie1", "zdanie1F");

P.S. I was digging through the X-RTA map - there is a similar script there, but it is implemented without a trigger and using symbols -- which pull in previously defined values, such as --hero1 = hero1, but there are serious coders there.

User Avatar
Auto-translated
green belly, here are a couple of hints:
The GetPlayerHeroes() function returns an array of heroes, and the GiveHeroBattleBonus() function takes the name of a single hero as its first parameter. You need to iterate through all the heroes in the array. For example, for PLAYER_2:
for i, hero in hero2 do
GiveHeroBattleBonus(hero, morale bonus, -3);
end
And so on for all opponents.
The zdanie1F() function takes the name of the hero who triggered the trigger as input. This was reflected in the code that Azgalor sent you. You need to check it in HasHeroSkill().
The -- signs are comments, meaning they are not code. I suggest you look at some article about Lua; it will become clearer.
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
green belly, here are a couple of hints:
The GetPlayerHeroes() function returns an array of heroes, and the GiveHeroBattleBonus() function takes the name of a single hero as its first parameter. You need to iterate through all the heroes in the array. For example, for PLAYER_2:
for i, hero in hero2 do
GiveHeroBattleBonus(hero, morale bonus, -3);
end
And so on for all opponents.
The zdanie1F() function takes the name of the hero who triggered the trigger as input. This was reflected in the code that Azgalor sent you. You need to check it in HasHeroSkill().
The signs -- are comments, meaning they are not code. I advise you to look at some article about lua, it will become clearer.
Thank you, I corrected the hero names and added loops, and it worked!

Statistics

Welcome our newest member: Emil