Skip to content

Posts from Combat scripts and battle management.

No ratings yet — be the first to rate!
User Avatar
9 years ago
Auto-translated
In general, I think it would be useful to dedicate a separate thread specifically to combat scripts (I hope a thread like this hasn't already been created). Why I wanted to create this thread: In the file with scripted functions, there is also a description of functions used in battles. For example, I have already used features such as summoning various creatures onto the battlefield, casting targeted/mass/area-of-effect spells, and moving along the ATB scale. However, during experiments with combat scripts, many questions arose, and I haven't found answers to them. The purpose of this thread: Personally, I would like to understand how much control a map editor can have over battles using combat scripts. Why, in some cases, a script doesn't work or doesn't produce the desired result, and how to achieve that result. Also, beginner map editors will have the opportunity to get to know combat scripts better. Here are just a few questions that I remember and have wanted to ask for a long time: 1) Can combat scripts be used to temporarily increase the stats of creatures/heroes during a battle? (e.g., give +1 to the speed of friendly creatures). 2) Can a creature be given an ability during a battle that it doesn't normally have? (unlikely, but who knows...) 3) How can I make it so that when a hero casts a spell using a script, they don't move back on the ATB scale? (of course, you can move the hero along the scale using the corresponding function, but I haven't found a function that returns the CURRENT position of a unit/hero). 4) Situation: a friendly creature starts its turn and attacks an enemy. At this time, the hero casts a conditional magic arrow using a script, and the target creature dies before the attacker reaches it. How can this collision be avoided? 5) Can creatures that normally cannot cast spells cast spells using a combat script? Or those that don't have that spell in their spellbook? Can siege weapons cast spells? :D 6) Can you give extra shots to a ballista or catapult in battle? Increase damage/healing power? 7) Is there a try-catch structure that allows you to ignore errors that occur during script execution?
User Avatar
9 years ago
Auto-translated
MasteR
Here are just a few questions that I remember and have wanted to ask for a long time:

1) Is it possible to temporarily increase the stats of creatures/heroes during combat using combat scripts? (e.g., give +1 to the speed of friendly creatures).
2) Is it possible to give a creature an ability during combat that it doesn't normally have? (unlikely, but who knows...)
3) How can I make it so that when a hero casts a spell using a script, they don't move back on the ATB scale? (of course, you can move the hero on the scale using the appropriate function, but I haven't found a function that returns the CURRENT position of the unit/hero)
4) Situation: a friendly creature starts its turn and attacks an enemy. At this time, the hero casts a conditional magic arrow using a script, and the target creature dies before the attacker reaches it. How can I avoid this collision?
5) Can creatures cast spells using a combat script that they normally cannot cast? Or those that don't have that spell in their spellbook? Can siege weapons cast spells? :D
6) Is it possible to give extra shots to a ballista or catapult in combat? Increase damage/healing power?
7) Is there a try-catch structure that allows you to ignore errors that occur during script execution?
1-3) Most likely, it is not possible.
4) You can use the following structure:
repeat sleep() until combatReadyPerson()
, which will wait until someone's turn comes.
5) Creatures can cast spells that they don't know, including those that cannot cast spells at all. However, there must be enough mana for this spell.
6) Most likely, no. But the ballista still has infinite shots: after reaching 0, it will continue to fire, and the shots will become negative.
7) You can emulate try using startThread and catch using errorHook. In the lualib library, I implemented a function called pcall, which does approximately this.
User Avatar
9 years ago
Auto-translated
Regarding point 1, it seems like some global script is used to grant a speed bonus to the hero. Or is that incorrect? Regarding point 3: there are skills that reduce knockback, and spells that have no knockback at all (enchanted arrow doesn't knock back). Could this be used somehow, perhaps by reassigning or tweaking something?
In reply to RedHeavenHero
User Avatar
9 years ago
Auto-translated
RedHeavenHero
1-3) Most likely, it’s impossible.
Are there any ways to achieve similar effects without mods and combat scripts?
One of the possible, albeit crude, methods, as I think, is to give the hero the corresponding artifact at the beginning of the battle and take it away at the end, but this probably won’t work if the hero already has an item in that artifact slot...
RedHeavenHero

4) You can use the following construct:
repeat sleep() until combatReadyPerson()
, which will wait until someone’s turn comes.
Good method, thank you.
RedHeavenHero

5) Creatures can cast spells that they don’t know, including creatures that can’t cast spells at all. However, they must have enough mana for this spell.
That is, you need to initially give the creature more mana and take it away after casting. But here, most likely, another problem will arise – the creature will roll back on the initiative order.
RedHeavenHero

6) Most likely, no. But the ballista still has infinite shots: after reaching 0, it will continue to fire, and the shots will become negative.
Here, I meant an additional shot per turn, i.e., not 2, but 3 shots at a time.
RedHeavenHero

7) You can emulate try using startThread and catch using errorHook. In the lualib library, I implemented the pcall function, which does approximately this.
I need to try it. Thank you.

Added 5 minutes ago
Another question:

I wanted to implement a “rollback” of the hero after casting using combat scripts, making it 20% less (i.e., to position 0.2 on the initiative order instead of 0). It will work normally in the usual case, but what if the hero has Wizard skills? In this case, simply setting the initiative order position will no longer work correctly, and I need to calculate all the hero’s and his opponent’s skills?
User Avatar
9 years ago
Auto-translated
One of the possible axe-based methods, as I think, is to give the hero a corresponding artifact at the beginning of the battle and take it away at the end, but this probably won't work if the hero already has a slot for that artifact...
In this case, ChangeHeroStat and GiveHeroBattleBonus will work better.
That is, initially, you need to give the creature more mana and take it away after casting.
Yes, exactly.
Here, I meant an additional shot per turn, i.e., not 2, but 3 shots at a time, for example.
It's unlikely to work here. You can give an additional turn.
In this case, a simple assignment of the ATV position will no longer work correctly, and you need to calculate all the hero's and his opponent's abilities?
Yes, most likely, you will have to do that.
User Avatar
9 years ago
Auto-translated
To my surprise, I discovered that the script function setATB() doesn't work. I first tried it to lift a ballista, then tried it on a hero and creatures. The effect is zero. I called it through the console like this:

@cr = GetAttackerCreatures()
@setATB(cr[0], 1)
User Avatar
9 years ago
Auto-translated
It works, but it doesn't always prevent the target from taking a turn. If a creature has already received its turn, the setATB effect will only take place after its turn is completed.
In reply to RedHeavenHero
User Avatar
8 years ago
Auto-translated
maybe it's not relevant, but could someone tell me what parameters are needed in the UnitCastGlobalSpell function?
User Avatar
8 years ago
Auto-translated
What parameters are needed in the UnitCastGlobalSpell function?
the name of the casting creature or hero (it must have enough mana) and the ID of the global spell.
7 years ago
Auto-translated
Please tell me if it is possible to create a script that would allow a hero to cast buffs on a ballista.

Statistics

Welcome our newest member: recijeb