Well, basically it's easy. We reserve a Necromancer hero and create a quest to "save" the main hero, making it technically empty (OBJECTIVE_KIND_MANUAL) so we can control it through scripts. In the scripts, we'll write something like this:
NowNecromancer = 0 --Condition that we'll set when the hero becomes a Necromancer
function prim_save_gg( heroName ) --You can name this function differently; it's just for clarity
if ( heroName == Duncan ) and NowNecromancer ~= 1 then --Duncan is just an example. Replace it with the script name of your hero
SetObjectiveState("scripted quest name", OBJECTIVE_FAILED) --Fail the quest to save the main hero
sleep(10) --Give the player time to see the quest fail and realize they've lost the main hero
Loose() --Fail the mission because our hero died before becoming a Necromancer
elseif ( heroName == Duncan ) and NowNecromancer == 1 then --We lose the hero, but because we now have the condition that we're a Necromancer, we don't lose the game
print("It's okay, the condition is met. He died, and that's life. Now I'm a Necromancer, maybe I'll go buy some skulls.")
end
if ( heroName == DuncanNecro ) and NowNecromancer == 1 then --Our hero is a Necromancer, and the condition that we made him a Necromancer has been met
SetObjectiveState("scripted quest name", OBJECTIVE_FAILED) --Fail the quest to save the main hero
sleep(10) --Give the player time to see the quest fail and realize they've lost the main hero
Loose() --Fail the mission because our hero died after becoming a Necromancer
end
end
function TransformToNecromancer() --Here, we'll define what happens after the main hero becomes a Necromancer. How it's called is up to you.
--It's up to the author to decide what the conditions are.
NowNecromancer = 1 --Set the condition so the game doesn't fail after deleting the main hero
sleep(2) --Just in case, give the game time to process the information
DeployReserveHero("DuncanNecro", x, y, GROUND/UNDERGROUND) --Place the new main hero so the game doesn't fail if the player only has one hero and no castle with a tavern
sleep(2) --Also just in case, give the game time to process everything
RemoveObject("Duncan") --Painlessly delete the main hero
end
Trigger(PLAYER_REMOVE_HERO_TRIGGER, PLAYER_1, "prim_save_gg") --Trigger to track when the player loses a hero (PLAYER_1)Give it a try)
NowNecromancer = 0
function PrimSaveGG(heroName)
if (heroName == Hafad) and NowNecromanser ~= 1
then SetObjectiveState("prim1", OBJECTIVE_FAILED)
sleep(10)
Loose()
elseif (heroName == Hafad) and NowNecromanser == 1
end;
if (heroName == HafadNecro) and NowNecromanser == 1
then SetObjectiveState("prim1", OBJECTIVE_FAILED)
sleep(10)
Loose()
end;
end;
function TransformGG()
NowNecromanser = 1
sleep(2)
DeployReserveHero("HafadNecro", 31, 93, GROUND)
sleep(2)
RemoveObject("Hafad")
end;
Trigger(PLAYER_REMOVE_HERO_TRIGGER, PLAYER_1, "PrimSaveGG")