I've been creating maps ever since HOMM2, and now i've come to HOMM5 and realized how new to script/trigger creation i am, so i got a little request which i hope a seasoned map maker can help me with...
You see, i want to make a script or something so when a specific creature enters an army under my colour i want it to turn into another unit. Example, if i recruit an Archangel i'd like it to turn into a Fallen Angel.
If anyone could aid me i'd be grateful. :3
<Insert a random comment that makes you think i'm funny and think better of me>
From the HoF campaigns you can copy their script which is :
function transformTroops()
sleep(3);
print("function transformTroops for hero ", heroName ," has started...");
while IsHeroAlive ( heroName ) == true do
for i=1,14 do
creaturesCount = GetHeroCreatures( heroName, i );
if creaturesCount > 0 then
RemoveHeroCreatures( heroName, i, 10000);
n = i;
if mod(i,2) ~= 0 then n = i + 1; end;
AddHeroCreatures( heroName, 105 + (n/2), creaturesCount );
end;
end;
sleep(2);
end;
print("Hero ", heroName, " is dead. Function transformTroops terminated");
end;
startThread(transformTroops)
Just replace heroName in the function by the name of your hero. Follow the pattern if you want to change the creatures ids.
Thank you very much, Neckie! Very informative. I just got another question...
Its a quite simple question, i'd just like to be pointed out where in that script you get to change unit into another unit. I fail to see it... sorry if i'm much of a drag. ^^
<Insert a random comment that makes you think i'm funny and think better of me>
There is no single command that replaces units. You first have to determine whether there is X type units at all, then how many of them are there, then remove all them and then add the same number of new creatures.
-- determines how many creatures of the type that corresponds to "i" are in heros army.
quote:
RemoveHeroCreatures( heroName, i, 10000); n = i; if mod(i,2) ~= 0 then n = i + 1; end;
Removes all (unless there is more than 10000 creatures of that type) creatures. mod(i,2) determines whether the creature is base mod(i,2) ~= 0 or upgraded mod(i,2) = 0
Right... i've tried several things, but i've yet to get the script to work. I inserted my Heros name in the script, yet nothing happens when i test the map.
Do i have to do more than just replacing 'HeroName' with the specific Heroes' name?
<Insert a random comment that makes you think i'm funny and think better of me>
yeah its the internal hero name (see Pitsu h5 scripting guide for the name list). Here is an example for Biara :
function transformTroops()
sleep(3);
print("function transformTroops for hero Biara has started...");
while IsHeroAlive ( "Biara" ) == true do
for i=1,14 do
creaturesCount = GetHeroCreatures( "Biara", i );
if creaturesCount > 0 then
RemoveHeroCreatures( "Biara", i, 10000);
n = i;
if mod(i,2) ~= 0 then n = i + 1; end;
AddHeroCreatures( "Biara", 105 + (n/2), creaturesCount );
end;
end;
sleep(2);
end;
print("Biara is dead. Function transformTroops terminated");
end;
startThread(transformTroops)
1. Are you sure that it is a singleplayer map, not multiplayer? Multiplayer maps cannot have scripts. To verify it, open your h5m file with winzip or winrar archiver and look whether there is a Singlemission or MultiPlayer directory in it.
2. Note the sleep(3) or sleep(2) lines in the script. Change these values from 3 and 2 to anything higher (one or both of them, lets say to 30 or 20).
3. Try to enable console and see what kind of errormessage it gives at the start of the map. (IIRC instructions for console activations are in one of Editor documents)
4. Copy-paste your script here so that we can see it and point at misspellings or other errors.