this is easy
make the unit cost 1 lumber and 1 gold(or whatever you want)
then make all the units in the alter cost that.
next you will put a circle of power that does nothing next to the alter in question, make it belong to the player.
next use this trigger:
event:a unit dies
condition: unit is equal to a hero owned by player(whatever number player is)
actions: add (however much lumber/gold that your heroes cost) to player (whatever number player is) properties.
this will let you create a different hero instead.
this is the simplest way that i know how to do it, there are more complicated ways using JASS, but this one is guarenteed to work, you seem like a noob at triggers to me, so do this:
click on the little "a" in the options at top this will activate the trigger editor, next you choose to make a new trigger file, then a new trigger to put into it, next pick "Create new event", put in the event i told you to, i think its there initially.
after that pick"new condition and look for the condition i gave you
then finally, pick "new action" and find the action i gave you, (do this by filling i the blanks that i put thereu know the "( )" put this in, test your map, and you should be able to do it.
hope i helper
p.s. you can still keep the meelee initialization trigger, even if you do this.