Posts from Scripts
Auto-translated
Example:
If a hero has learned a specific spell, then he gets +1 to spell power.
1. The start() function seems to need to start with a capital letter - Start(). Lua is case-sensitive.
2. Mana might not be given to the hero immediately; you can reliably wait using this construct:
SetUnitManaPoints(GetAttackerHero(), 100);
repeat sleep() until(GetUnitManaPoints(GetAttackerHero()) == 100);
3. Spell casting functions may fail in some cases, causing the script to crash at that point. There is a safer way to run them through a separate thread:
startThread(UnitCastGlobalSpell, GetAttackerHero(), 212);
And also, after the spell casting functions and before restoring the previous mana, it is better to put sleep(1), so that the mana has time to be deducted before it is restored.
function Start()
lev = GetGameVar("level") + 0;
mana = GetUnitManaPoints(GetAttackerHero())
SetUnitManaPoints(GetAttackerHero(), 100);
repeat sleep() until(GetUnitManaPoints(GetAttackerHero()) == 100);
if lev < 10 then
startThread(UnitCastGlobalSpell, GetAttackerHero(), 212);
elseif lev < 20 then
startThread(UnitCastGlobalSpell, GetAttackerHero(), 212);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 215);
elseif lev < 30 then
startThread(UnitCastGlobalSpell, GetAttackerHero(), 212);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 215);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 210);
else
startThread(UnitCastGlobalSpell, GetAttackerHero(), 212);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 215);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 210);
startThread(UnitCastGlobalSpell, GetAttackerHero(), 213);
end
sleep(2);
SetUnitManaPoints(GetAttackerHero(), mana);
end
player_hero = '';
function Start()
if(IsHuman(ATTACKER)) then
player_hero = GetAttackerHero();
else
player_hero = GetDefenderHero();
end
combatSetPause(not nil);
local last_mana = GetUnitManaPoints(player_hero);
SetUnitManaPoints(player_hero, 100);
repeat sleep() until(GetUnitManaPoints(player_hero) == 100);
startThread(UnitCastGlobalSpell, player_hero, SPELL_MASS_STONESKIN);
sleep(1);
SetUnitManaPoints(player_hero, last_mana);
repeat sleep() until(GetUnitManaPoints(player_hero) == last_mana);
setATB(player_hero, 0.5);
sleep(1);
combatSetPause(nil);
end
The problem is this: I want the "uderzhatG" quest to activate after capturing the "gorodSvyat" town. Also, if this town belongs to Player 2, then the quest should fail, and the player should lose the mission. Also, after the hero "Nemor" is defeated, the quest should be completed. But after I add the functions below to my code, everything breaks, and it doesn't trigger (although the initial settings are applied). What's the problem?function uderzhat ()
SetObjectiveState("uderzhatG", OBJECTIVE_ACTIVE);
Trigger(OBJECT_CAPTURE_TRIGGER, "gorodSvyat", nil );
end;
Trigger(OBJECT_CAPTURE_TRIGGER, "gorodSvyat", "uderzhat" );
function CheckSvyat ()
while (1) do
sleep(2);
if GetObjectOwner("gorodSvyat")==PLAYER_2 then
sleep (2)
SetObjectiveState("uderzhatG", OBJECTIVE_FAILED);
sleep (15)
Loose ();
break
end;
end;
end;
startThread (CheckSvyat)
function UderzhatComplete ()
SetObjectiveState("uderzhatG", OBJECTIVE_COMPLETED);
Trigger (PLAYER_REMOVE_HERO_TRIGGER, "Nemor", nil)
end
Trigger (PLAYER_REMOVE_HERO_TRIGGER, "Nemor", "UderzhatComplete")
I might be wrong, but perhaps you could try this trigger: Trigger(OBJECT_CAPTURE_TRIGGER, "gorodSvyat", "CheckSvyat" );
I might be wrong, but it might be possible to place a trigger: Trigger(OBJECT_CAPTURE_TRIGGER, "gorodSvyat", "CheckSvyat" );
Instead of a start thread or where?
Instead of a starting thread, or where?
After this line:
Trigger(OBJECT_CAPTURE_TRIGGER, "gorodSvyat", nil )
Does it work?