Jakamo Jones
Chieftain
- Joined
- Sep 4, 2022
- Messages
- 4
I had a simple requirement... I wanted to create a unit with some amount of XP and promotions already chosen. I had searched the forums but mostly just people saying it can't be done. After trying out a million things, I found the way to do it.
here's some pseudo code. for example if you wanted to level up a melee unit to have 50/90 XP and Battlecry + Commando:
-First you gotta give the unit 15 xp
-Then you simulate what the UI does to pick Battlecry
-Then you give the unit another 30 xp (for a total of 45 now)
-Then you use UnitManager.RequestCommand to pick Commando
-And then finally top it off to get to 50
but bad news! Unless you're playing as Gran Colombia, the 2nd command will fail because your unit has already completed its turn!
So we need a way to reset a unit's turn... HEY I HAVE AN IDEA. I'll just spawn Hippolyta next to my new unit and activate her ability to restore movement.
Now I can pick Commando!
Feels really dumb though, has anybody else had luck with resetting a unit's turn from script?
here's some pseudo code. for example if you wanted to level up a melee unit to have 50/90 XP and Battlecry + Commando:
-First you gotta give the unit 15 xp
Code:
myNewUnit:GetExperience():ChangeExperience(15)
Code:
UnitManager.RequestComand(myNewUnit, UnitCommandTypes.PROMOTE, {UnitCommandTypes.PARAM_PROMOTION_TYPE = "BATTLECRY"})
Code:
myNewUnit:GetExperience():ChangeExperience(30)
Code:
UnitManager.RequestComand(myNewUnit, UnitCommandTypes.PROMOTE, {UnitCommandTypes.PARAM_PROMOTION_TYPE = "COMMANDO"})
Code:
myNewUnit:GetExperience():ChangeExperience(5)
but bad news! Unless you're playing as Gran Colombia, the 2nd command will fail because your unit has already completed its turn!
So we need a way to reset a unit's turn... HEY I HAVE AN IDEA. I'll just spawn Hippolyta next to my new unit and activate her ability to restore movement.
Now I can pick Commando!
Feels really dumb though, has anybody else had luck with resetting a unit's turn from script?