ubi.com    Forums  Hop To Forum Categories  Might and Magic  Hop To Forums  Heroes of Might and Magic V Cartographers Guild    Unit "replacing" script/trigger
Go
New
Find
Notify
Tools
Reply
  
  Login/Join 
Posted
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
 
Posts: 5 | Registered: Sun August 19 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
I would say go for a thread that checks units in army(ies) and replaces them when necessary.
 
Posts: 616 | Registered: Fri February 27 2004Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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.
 
Posts: 4 | Registered: Fri May 04 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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. ^^
 
Posts: 5 | Registered: Sun August 19 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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.

quote:
for i=1,14 do

-- Haven creatures have code numbers 1-14 (1- peasant, 2- conscript ... 14 archangel)

quote:
creaturesCount = GetHeroCreatures( heroName, i );

-- 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

quote:
AddHeroCreatures( heroName, 105 + (n/2), creaturesCount );


Adds "red" haven units. 105+(n/2) gives you the nummerical code for red haven units.
 
Posts: 616 | Registered: Fri February 27 2004Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
You're a lifesaver! Thanks a lot! I'll take a careful look on it. Once again, thank you. Much appreciated. :3
 
Posts: 5 | Registered: Sun August 19 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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?
 
Posts: 5 | Registered: Sun August 19 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
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)   
 
Posts: 4 | Registered: Fri May 04 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Still not working, for some reason... does it require a version greater than 2.0 to use that script or something?
 
Posts: 5 | Registered: Sun August 19 2007Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Some advice:

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.
 
Posts: 616 | Registered: Fri February 27 2004Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

ubi.com    Forums  Hop To Forum Categories  Might and Magic  Hop To Forums  Heroes of Might and Magic V Cartographers Guild    Unit "replacing" script/trigger

Terms of Use