Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
8 years ago
Auto-translated
Here's the question. We have this in the combat script: ``` function AttackerUnitDeath(unit) SummonCreature(DEFENDER, CREATURE_GHOST, 50 * diff) end ``` What condition should be added so that ghosts don't appear when combat units (cart, ballista, and tent) are destroyed? I can't figure it out. Please help.
User Avatar
8 years ago
Auto-translated
function AttackerUnitDeath(unit)
You can check the unit type:
IsCreature(unit);
Also, there are ready-made functions where all this is already checked; you can use AttackerCreatureDeath instead of AttackerUnitDeath. Quote from Novik's manual:
In the /scripts/combat-startup.lua file, this hook has been replaced with a set of functions:
void AttackerUnitDeath(unitName)
void AttackerHeroDeath(sUnitName)
void AttackerCreatureDeath(sUnitName)
void AttackerWarMachineDeath(sUnitName)
void AttackerBuildingDeath(sUnitName)
void DefenderUnitDeath(sUnitName)
void DefenderHeroDeath(sUnitName)
void DefenderCreatureDeath(sUnitName)
void DefenderWarMachineDeath(sUnitName)
void DefenderBuildingDeath(sUnitName)
User Avatar
8 years ago
Auto-translated
Thank you!
User Avatar
8 years ago
Auto-translated
Here's a question: is it possible to determine through a combat script whether any action has been performed by a hero or unit? All functions from the manuals, such as UnitCastGlobalSpell() and similar, force a unit to perform some action, but is it possible to find out if such an action was performed at all during the battle, without explicitly defining it?
User Avatar
8 years ago
Auto-translated
Here's a question (needed for the final version of the map): there's a script command MoveHero("Straker", GetObjectPosition("PlayerTown")). It works, but not always... sometimes he stays in place. For example, if a hero is standing at the entrance to the town. Is there a way to change this?

Added 1 minute ago
I need one thing: for the hero to rush headlong to a specific castle after he appears.

Added 2 minutes ago
I remember that in the Unicorn Empire campaign, the necromancer in the first mission behaves this way. I need something similar, but:

The hero appears on a specific day, and another hero might be in the castle.
User Avatar
8 years ago
Auto-translated
Question: I placed a region near player 2's Castle and named it vyhod1. I want to prevent anyone from leaving through it, so I want to block this region. I'm writing:
SetRegionBlocked(vyhod1, true, 2);
But it doesn't work, and the hero can still move through it. What's wrong?
User Avatar
8 years ago
Auto-translated
Instead of true, use 1.
In reply to OrnsteinDragonslayer
User Avatar
8 years ago
Auto-translated
OrnsteinDragonslayer
Question: I placed a region near player 2's castle and named it vyhod1. I want to prevent anyone from leaving that region, so I want to block it. I'm writing:
SetRegionBlocked(vyhod1, true, 2);
But it doesn't work, and the hero can still move around. What's wrong?
You're missing quotes around the region name.
In reply to RedHeavenHero
8 years ago
Auto-translated
Is there a way to make a function run every week without rewriting the code multiple times with a variable? Code: SetObjectEnabled("tav", nil) function Army(heroname) MessageBox("Maps/SingleMissions/Revenge of the/qwe.txt") QuestionBox("Maps/SingleMissions/Revenge of the/rtyui.txt", "arm") Trigger(OBJECT_TOUCH_TRIGGER, "tav", "nil") end function arm(heroname) sleep(2) gold= GetPlayerResource(1, 6) sleep(1) if gold<6000 then sleep(1) MessageBox("Maps/SingleMissions/Revenge of the/rtyu.txt") else gold= GetPlayerResource(1, 6) sleep(1) if gold>=6000 then SetPlayerResource(1, GOLD, gold - 6000) AddHeroCreatures("Godric", 2, 80) MessageBox("Maps/SingleMissions/Revenge of the/aer.txt") end end end
In reply to Годрикова впадина
User Avatar
8 years ago
Auto-translated
Godric's Hollow
Is there a way to make the function run every week without rewriting the code multiple times with a variable?
Code:
SetObjectEnabled("tav", nil)
function Army(heroname)
MessageBox("Maps/SingleMissions/Revenge of the/qwe.txt")
QuestionBox("Maps/SingleMissions/Revenge of the/rtyui.txt", "arm")
Trigger(OBJECT_TOUCH_TRIGGER, "tav", "nil")
end

function arm(heroname)
sleep(2)
gold= GetPlayerResource(1, 6)
sleep(1)
if gold<6000 then
sleep(1)
MessageBox("Maps/SingleMissions/Revenge of the/rtyu.txt")
else
gold= GetPlayerResource(1, 6)
sleep(1)
if gold>=6000 then
SetPlayerResource(1, GOLD, gold - 6000)
AddHeroCreatures("Godric", 2, 80)
MessageBox("Maps/SingleMissions/Revenge of the/aer.txt")
end
end
end
Of course, you can simply avoid resetting the trigger
In reply to DarkLordax
8 years ago
Auto-translated
What do you mean?
Currently, OBJECT_TOUCH_TRIGGER is set, we just need the function to be available again every week.
In reply to Годрикова впадина
User Avatar
8 years ago
Auto-translated
Godric's Hollow
What do you mean?
Right now, there's an OBJECT_TOUCH_TRIGGER; we just need to make sure the function is available again every week.
Okay, then...
make the day check for Monday or another desired day.
In reply to Gerter
User Avatar
8 years ago
Auto-translated
Gerter
I have a question – is it possible to determine through a combat script whether any action has been performed by a hero or unit? All functions from the manuals, such as UnitCastGlobalSpell(), etc., force a unit to perform some action, but is it possible to find out whether such an action has been performed at all during the battle, without explicitly writing it?
I am also interested in this question. How extensive are the capabilities of combat scripts? And is it possible to interact with the combat log in some way? For example, to track and record certain data in a variable during the battle (the amount of mana spent, or how much damage a specific spell has dealt).
Is this even possible at the level of interpreted scripts? Or is all of this hidden without any possibility of interaction?
In reply to Kavalar
User Avatar
8 years ago
Auto-translated
Kavalar
I am also interested in this question. How extensive are the capabilities of combat scripts? And is it possible to interact with the combat log in some way? For example, to track and record certain data during the battle in a variable (the amount of mana spent, or how much damage a specific spell dealt).
Is this even possible at the level of interpreted scripts? Or is all of this hidden without any possibility of interaction?
1. The log is not accessible to scripts.
2. The amount of mana spent can be tracked using the GetUnitManaPoints function.
3. Indirectly, it is possible to determine how many creatures a hero killed with a particular spell (it is unlikely that the spell itself can be determined) by measuring the mana and the number of creatures in each unit before and after casting the spell.
In reply to RedHeavenHero
User Avatar
8 years ago
Auto-translated
RedHeavenHero
1. The log is not accessible to scripts.
2. The amount of mana spent can be tracked using the GetUnitManaPoints function.
3. Indirectly, it is possible to determine how many creatures a hero killed with a particular spell (it will be difficult to identify the spell itself), by measuring the mana and the number of creatures in each stack before and after casting the spell.
So, something like, if the hero's mana decreases, check the enemy stacks?

I had an idea to identify a spell, for example, by extracting its presence in the hero's spellbook before the battle and analytically calculating, with adjustments for SP and bonuses from schools, how much damage it should deal. Then, simply compare, and if the amount of mana spent and the damage dealt match, record it. What do you think, could it work?
The only problem is accounting for resistance, and while it's possible to analyze creatures, it's unclear how to deal with hero bonuses or artifact bonuses.:smile32:

Statistics

Welcome our newest member: recijeb