The learning spell parts is easy. I've done that with triggers. You don't need a script for that.
Events:
A unit gains a level
Conditions:
or - multiple
Owner of leveling hero eqaul to player4
Owner of leveling hero eqaul to player5
Owner of leveling hero eqaul to player6
Owner of leveling hero eqaul to player7
Level of leveling hero is 2
Actions:
If all coniditions are true then
conditions:
unit type of leveling hero is "HeroName"
learn skill for leveling hero "Skill"
else
new if all coniditions are true
And so on until you've covered all heroes you use.
Then just copy the trigger and change the level of leveling hero to 3,4,5 and so on, and change skills.