1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Dismiss Notice
  6. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger Viewer

Talent Jui V1.33.w3x
Variables
Talent
HowToInstall
Info
Talent
Talent init
TalentVariables
TalentPreMade
TalentPreMadeChoice
TalentGUI
Talent Example Heroes
TalentGUI
Talent Paladin
Talent Copy Palaidn
Talent BloodMag
Talent Uther
Talent GrubenLord
Talent FootMen
Talent ShadowPriest
GUI Hero MoutainKing
Talent MK Axe Learn
Talent MK Axe Reset
Talent MK Helm Learn
Talent MK Helm Reset
Talent MK Armor Learn
Talent MK Armor Reset
Talent MK Manastone Learn
Talent MK Manastone Reset
Talent MK Event
Talent MK Event Reset
Talent MountainKing Init Commented
Talent Muradin Copies MoutainKing
Talent MountainKing Init
Talent MountainKing Init Predefined
Demo
Gain TalentBook
Demo Event Choose Skill
Demo Event Reset Skill
Demo Event Gain a Choice
Demo Event Finished Chocies
Demo Reset
Demo PreventReset
Demo Macro
Demo LastSelect
Demo Info
Demo Print TierChoice Count
Kartenspezifischen eigenen Skript-Code unten eingeben. Dieser Text wird in das Karten-Skript nach der Deklaration der Variablen und vor jeglichem Auslöser-Code eingefügt.
function Debug takes string s returns nothing
	call DisplayTextToPlayer(GetLocalPlayer(), 0,0, s)
endfunction
function DebugExist takes string s, integer index returns nothing
	call BJDebugMsg(s+"."+I2S(index)+" Handle: "+I2S(GetHandleId(BlzGetFrameByName(s,index))))
endfunction
function DebugFrameValue takes string s, integer index returns nothing
	call BJDebugMsg(s+"."+I2S(index)+" Value: "+R2S(BlzFrameGetValue(BlzGetFrameByName(s,index))))
endfunction
function DebugFrameVisible takes string s, integer index returns nothing
	if BlzFrameIsVisible(BlzGetFrameByName(s,index)) then
		call BJDebugMsg(s+"."+I2S(index)+" is Visible")
	else
		call BJDebugMsg(s+"."+I2S(index)+" is Hidden")
	endif
endfunction
function DebugFrameText takes string s, integer index returns nothing
	call BJDebugMsg(s+"."+I2S(index)+" Text: "+BlzFrameGetText(BlzGetFrameByName(s,index)))
endfunction
function LoadToc takes string s returns nothing
	if BlzLoadTOCFile(s) then
		call BJDebugMsg("Loaded: "+s)
	else
		call BJDebugMsg("Failed to Load: "+s)
	endif	
endfunction
Name Type Is Array Initial Value
LastSelected unit No
StatPower integer Yes
StatType integer Yes
Talent__Button integer No
Talent__Choice integer No
Talent__Event real No
Talent__Level integer No
Talent__ResetAmount integer No
Talent__Tier integer No
Talent__Unit unit No
Talent__UnitCode unitcode No
TalentChoiceHead string Yes
TalentChoiceIcon imagefile Yes
TalentChoiceInt1 integer Yes
TalentChoiceInt2 integer Yes
TalentChoiceInt3 integer Yes
TalentChoiceLast integer No
TalentChoiceOnLearn trigger Yes
TalentChoiceOnReset trigger Yes
TalentChoiceReal1 real Yes
TalentChoiceReal2 real Yes
TalentChoiceText string Yes
TalentControlLevels integer Yes
TalentControlLevelsCurrent integer Yes
TalentControlLevelsMax integer Yes
TalentControlPreventReset boolean Yes
TalentControlTarget unit Yes
TalentGUI_ChoiceHead string No
TalentGUI_ChoiceIcon imagefile No
TalentGUI_ChoiceText string No
TalentGUI_Level integer No
TalentGUI_OnLearn trigger No
TalentGUI_OnReset trigger No
TalentGUI_ReplacedSpell abilcode No
TalentGUI_Spell abilcode No
TalentGUI_UnitType unitcode No
TalentGUI_UnitTypeCopied unitcode No
TalentGUIAddSpell trigger No
TalentGUICopyUnit trigger No
TalentGUICreateChoice trigger No
TalentGUIReplaceSpell trigger No
TalentHash hashtable No
TalentPreMadeChoiceTrigger trigger Yes
TalentReset trigger No
TalentSpellsPrefix string Yes
TalentSpellsSufix string Yes
TalentStrings string Yes
TalentTierLast integer No
TalentTrigger trigger Yes
TalentUser group No
Make sure World Editor generates unknown variables in Preferences is set.
Copy the Talent Folder.

update values inside Talent Init

export
war3mapImported\TalentBox.fdf
war3mapImported\TalentBox.toc

also import them into your map

Installed



 
Allows choosen UnitTypes to select 1 choice out of many at specific Levels, you might know that out of Heroes of the Storm.
can replace the default skill choicing or work seperate.

Choices in 1 Tier should not have the same OrderString, something strange might happen if they share the same orderstring.

All Choice-Containers used by 1 Hero must use the same OrderString, to be showin by the UI-Book.

A Hero is only added to the Talent_Triggers, if he has the default UI or the Hero Speciifc one, when starting this system or he enters the map. (can use this overall)
If you already have an enters map event, it might be good to remove the event from udg_TalentTrigger[1] (bottom of talent-script) and let yours call udg_TalentTrigger[1] with ConditionalTriggerExecute.
//Talent Jui 1.33
//by Tasyen

// Talent provides at wanted Levels a choice from a collection (Tier), from which the user picks one.
// Tiers are unitType specific (a paladin has different Choices then a demon hunter), This also includes the Levels obtaining them.
// One can handle choices by Events or one can bind Code beeing executed when picking a choice.
// Regardless using Events or binded code, creating a reset (revert picking a choice) is quite easy.
// Talent is mui.
// Choices and Tiers have a stable arrayIndex.

// Only UnitTypId having used TalentHeroSetFinalTier can use Talent.

// It is also recommented using "function TalentHeroSetCopy", if multiple unitTypes share the same Talent Setup, morphing units for example.

// Before an TalentUser is removed from them game, one should use "call FlushChildHashtable(udg_TalentHash, GetHandleId(unit))"
// Also it is recommented to do "call GroupRemoveUnit(udg_TalentUser, unit)"


//Known Erros: Choosen options overglow sometimes (most frequently the lowest button).

//===========================================================================
//Definitions:
//===========================================================================

//TalentAutoDetectNewUser (true) will create an "unit enters map" event for udg_TalentTrigger[TT_AutoDetectUnits()]
constant function TalentAutoDetectNewUser takes nothing returns boolean
    return true
endfunction

//Increases the Level of abilities gained by choices, if the ability is already owned.
constant function TalentImproveAbilities takes nothing returns boolean
    return true
endfunction
//(true) only add the new ability if the unit has the to replaced Ability
constant function TalentReplacedAbilityRequiered takes nothing returns boolean
    return true
endfunction

//Throw an Event when an unit picks a choiceTalent
constant function TalentThrowEventPick takes nothing returns boolean
    return true
endfunction

//Throw an Event when an unit gains a choice to pick a talent
constant function TalentThrowEventAvailable takes nothing returns boolean
    return true
endfunction
//Throw an Event when an unit resets a choice
constant function TalentThrowEventReset takes nothing returns boolean
    return true
endfunction
//Throw an Event when an unit picked the last Talent of its unitType.
constant function TalentThrowEventFinish takes nothing returns boolean
    return true
endfunction

//(true) When having no Choice close Talents. Happens on Levelup and picking a choice.
constant function TalentCloseWhenNoChoice takes nothing returns boolean
    return true
endfunction

//With false the unlearn Button won't exist
//udg_TalentControlPreventReset[GetConvertedPlayerId(player)] = true will disable the reset/Relearn Button for that player
constant function TalentBoxUseUnlearnButton takes nothing returns boolean
    return true
endfunction

//MaxAmount of Options shown in the UI of one tier.
//The Buttons start with 1 and include TalentBoxOptionMaxCount()
//One could still learn the Choice when a chat command would be provided.
function TalentBoxOptionMaxCount takes nothing returns integer
    return 6
endfunction

//Amount of LevelBoxes, if an unit got more tiers there will be a page control.
//if you want lest more boxes you might change TalentBoxLevelSizeX & TalentBoxLevelSizeY
function TalentBoxLevelAmount takes nothing returns integer
    return 7
endfunction
function TalentBoxLevelSizeX takes nothing returns real
    return 0.02 //sane values are below 0.05
endfunction
function TalentBoxLevelSizeY takes nothing returns real
    return 0.02
endfunction

//Bigger Options allow bigger texts, but also take more space of the screen, which reduces the possible amount of showing options in one tier.
//XSize of an option in the TalentBox
function TalentBoxOptionSizeX takes nothing returns real
    return 0.25
endfunction
//YSize of an option in the TalentBox, shouldn't be smaller than 0.04, when using Font 0.0085
function TalentBoxOptionSizeY takes nothing returns real
    return 0.045
endfunction
//YSpace between 2 options, + values increases the space between, - values reduces they can also overlap.
function TalentBoxOption2OptionGap takes nothing returns real
    return -0.005
endfunction
//YSpace between Title and option at the top.
function TalentBoxOption2TitleGap takes nothing returns real
    return 0.05
endfunction
//YSpace between LevelBoxes and option at the bottom
function TalentBoxOption2BottomGap takes nothing returns real
    return 0.00
endfunction

function TalentBoxResetSizeX takes nothing returns real
    return 0.07
endfunction
function TalentBoxResetSizeY takes nothing returns real
    return 0.025
endfunction

//IconSize, should be smaller than TalentBoxOptionSizeY
function TalentBoxOptionIconSize takes nothing returns real
    return 0.028
endfunction

//Default Position of the TalentBox
function TalentBoxPosX takes nothing returns real
    return 0.005
endfunction
function TalentBoxPosY takes nothing returns real
    return 0.2
endfunction
//The total y size varies with amount of shown options.
function TalentBoxBaseSizeY takes nothing returns real
    return 0.02
endfunction
function TalentBoxPosType takes nothing returns framepointtype
    return FRAMEPOINT_BOTTOMLEFT
endfunction

//Default Position for the ShowTalentBoxButton
function TalentBoxShowButtonPosX takes nothing returns real
    return 0.0
endfunction
function TalentBoxShowButtonPosY takes nothing returns real
    return 0.18
endfunction
function TalentBoxShowButtonPosType takes nothing returns framepointtype
    return FRAMEPOINT_BOTTOMLEFT
endfunction

function TalentStringsInit takes nothing returns nothing
//Customiceable Strings of Talent

   
   
//Customiceable Strings of TalentPreMadeChoice 
    set udg_TalentStrings[1] = "Learn:"         //TalentChoiceCreateAddSpells First Word.
    set udg_TalentStrings[2] = "\n"             //TalentChoiceCreateAddSpells First Seperator.
    set udg_TalentStrings[3] = ", "             //TalentChoiceCreateAddSpells Further Seperator.
    set udg_TalentStrings[9] = ""                           //TalentChoiceCreateImproveSpell    Prefix
    set udg_TalentStrings[10] = ", Manacost-Change"         //TalentChoiceCreateImproveSpell ManaCost-Change
    set udg_TalentStrings[11] = ", Cooldown-Change"         //TalentChoiceCreateImproveSpell Cooldown-Change
   
    set udg_TalentStrings[15] = "Weapon: "          //TalentChoiceCreateImproveWeapon PreFix
    set udg_TalentStrings[16] = ", Damage-Bonus "           //TalentChoiceCreateImproveWeapon Damage-Bonus
    set udg_TalentStrings[17] = ", AttackSpeedCooldown-Bonus "          //TalentChoiceCreateImproveWeapon AttackSpeedCooldown-Bonus
   

    set udg_TalentStrings[20] = ""                  //TalentChoiceCreateSustain Prefix
    set udg_TalentStrings[21] = "Life-Bonus "       //TalentChoiceCreateSustain Life-Bonus
    set udg_TalentStrings[22] = ", Mana-Bonus "     //TalentChoiceCreateSustain Mana-Bonus
    set udg_TalentStrings[23] = ", Armor-Bonus "        //TalentChoiceCreateSustain Armor-Bonus
   
    set udg_TalentStrings[28] = ""      //TalentChoiceCreateStats Prefix
    set udg_TalentStrings[29] = "Str-Bonus"     //TalentChoiceCreateStats Str-Bonus
    set udg_TalentStrings[30] = ", Agi-Bonus"       //TalentChoiceCreateStats Agi-Bonus
    set udg_TalentStrings[31] = ", Int-Bonus"       //TalentChoiceCreateStats Agi-Bonus
   
    set udg_TalentStrings[100] = "Unlearn choosen Talents from this Level and higher Levels.|nCan also be used to relearn Talents from this level upwards."     //Tooltip of Unlearn Button
    set udg_TalentStrings[101] = "(Un)Learn"        //Text of Reset-Button
    set udg_TalentStrings[102] = "Talent Level: "   //TalentBox Titel Prefix
    set udg_TalentStrings[103] = "Show Talent"      //Text of ShowTalentButton
    set udg_TalentStrings[104] = "No Talent User"   //No Talent User
endfunction
//===========================================================================
//API:
//===========================================================================
//  function TalentBoxShow takes unit target, player activePlayer returns nothing
    //Shows the TalentBox for activePlayer with target as unit.

//  function TalentMacroDo takes unit u, string s returns nothing
    //executes a bunch of Picks for Unit u.
    //"-U123" ->Unlearn all, Pick 1, Pick 2, Pick 3
    //"-112"  -> Pick 1, Pick 1, Pick 2, s has to start with "-"
    //Each done action will evoke events/triggers.

//  function TalentAddSelection takes unit u returns nothing
    //Test if u gets a new Tier to pick from, done automatically in: udg_TalentTrigger[TT_LevelUp()] (LevelUp).

//  function TalentAdd2Hero takes unit u returns nothing
    // can be used to force talentDetetcion
    //do not use it more than once for one unit.

//  function TalentResetDo takes unit u, integer amountOfResets returns nothing
    //This will undo the last amountOfResets done choices of unit u. Each Time calling the needed "udg_TalentChoiceOnReset" and throwing an event.
    //An OnLearn Requiers an onReset doing the opposite, if one wants to use this feature.
    //call it with 1 to remove the last done choice.
    //To undo all done Choices of an unit, call it with an absurd high number.

//  function TalentPickDo takes unit u, integer buttonNr returns nothing
    //unit u learns choice buttonNr of currentSelection Tier.
    //will only work if the hasSelection flag is set.
    //buttonNr is expected to be 1 to TalentBoxOptionMaxCount() including both
    //buttonNr also should not exceed TalentTierGetChoiceCount of the current Tier.

//  function TalentGetUnitTypeId takes unit u returns integer
    //wrapper for TalentGetUsedHeroTypeId

//  function TalentGetUsedHeroTypeId takes integer heroTypeId returns integer
    //Returns the unitTypeId used in Talent by that unit.
    //use it, if you used TalentHeroSetCopy in your map. If you did not use copy you can simple use GetUnitTypeId when using TalentHero-API

//===========================================================================
//TalentHero API
//===========================================================================
// TalentHero makes reading/writing HeroSheets(TalentTrees) more simple. This is not for data of existing units its the plan.

//  function TalentHeroSetCopy takes integer result, integer copyOrigin returns nothing
    //units from type result will use the setup from copyOrigin
    //also supports copy copy...
    //TalentHeroSetCopy is quite important, if an hero can morph
    //reading further data from result is disabled

//  function TalentHeroTierCreate takes integer heroTypeId, integer level returns integer
    //Create a new Tier for that hero at level.
    //level should be 0 or bigger.
    //returns udg_TalentTierLast

//  function TalentHeroGetTier takes integer heroTypeId, integer level returns integer
    //get the tier at that level for heroTypeId
    //0 = no tier

//  function TalentHeroSetTier takes integer heroTypeId, integer level, integer tier returns nothing
    //heroTypeId will use at level given tier.

//  function TalentHeroGetFinalTier takes integer heroTypeId returns integer
   
//  function TalentHeroSetFinalTier takes integer heroTypeId, integer level returns nothing
    //Units picking a choice of the tier added at level will be considered as Finished with their Talents.
    //this one has to be used to make a heroTypeId useable for talent.
       
//  function TalentHeroLevel2SelectionIndex takes integer heroTypeId, integer level returns integer
    //Tells you which selectionIndex that level would be selected as.
    //Valid is 0 to x
    //Returns -1 if the level does not have a tier for that heroTypeId and therefore wouldn't be a valid selectionindex

//===========================================================================
//TalentUnit API
//===========================================================================
//Access Hashtable Data for active units

//function TalentUnitGetSelectionsDoneCount takes integer unitHandle returns integer
//  How many selections this unit has done?

//function TalentUnitGetSelectionButtonUsed takes integer unitHandle, integer selectionIndex returns integer
//  ButtonNr used, 1 to TalentBoxOptionMaxCount() (included)

//function TalentUnitGetSelectionLevel takes integer unitHandle, integer selectionIndex returns integer
//  level of that selectionDone (1 to TalentUnitGetSelectionsDoneCount)

//function TalentUnitGetChoiceDone takes integer unitHandle, integer selectionIndex returns integer
//  arrayIndex of the choice of that selectionDone

//function TalentUnitGetCurrentTier takes integer unitHandle returns integer
//  the tier from which unit can pick from

//function TalentUnitGetCurrentTierLevel takes integer unitHandle returns integer
//  from which level the tier the unit picks currently is from?

//function TalentUnitGetTalentProgressLevel takes integer unitHandle returns integer
//function TalentUnitHasChoice takes integer unitHandle returns boolean


//===========================================================================
//TalentTier API
//===========================================================================
//  function TalentTierCreate takes nothing returns integer
    //creates a new Tier
    //a Tier is an collection of choices from which the user can pick one.
    //returns udg_TalentTierLast the ArrayIndex of the tier

//  function TalentTierAddChoice takes integer tier, integer choice returns nothing
    //Adds a Choice to the tier, tier is the ArrayIndex of the tier choice the ArrayIndex of Choice.

//  function TalentTierGetChoiceCount takes integer tier returns integer
    //returns the amount of choices added to this tier

//  function TalentTierGetChoice takes integer tier, integer index returns integer
    //returns the choice index (0 means no choice was added yet)
    //will return the to this tier last added choice if index is to high
    //expects index > 0

//===========================================================================
//TalentChoice API
//===========================================================================

//  function TalentChoiceCreate takes code onLearn, code onReset returns integer
    //if you do not need the function binding for this choice, you could use "set udg_TalentChoiceLast = udg_TalentChoiceLast + 1" instead.
    //Creates a choice and 1 Trigger for each OnLearn/OnReset, if they are not null.
    //returns the ArrayIndex of the Choice
    //afterwards one should set udg_TalentChoiceText[returnedValue], udg_TalentChoiceHead[returnedValue], udg_TalentChoiceIcon[returnedValue]

//  function TalentChoiceCreateEx takes code onLearn, code onReset returns integer
    //Wrapper creating a choice and adding it to the last Created Tier
    //use this over TalentChoiceCreate and TalentTierAddChoice in most cases.
    //returns the choice ArrayIndex.

//  function TalentChoiceCreateTrigger takes trigger onLearn, trigger onReset returns integer

//  function TalentChoiceCreateTriggerEx takes trigger onLearn, trigger onReset returns integer
    //like TalentChoiceCreateEx
   
//  function TalentChoiceCreateAll takes string head, string text, string icon, code onLearn, code onReset returns integer
    //creates the Choice with the wanted data

//  function TalentChoiceCreateAllTrigger takes string head, string text, string icon, trigger onLearn, trigger onReset returns integer

//  function TalentChoiceCreateAllEx takes string head, string text, string icon, code onLearn, code onReset  returns integer
    //Create and Add

//  function TalentChoiceCreateAllTriggerEx takes string head, string text, string icon, trigger onLearn, trigger onReset  returns integer

//  function TalentChoiceAddAbility takes integer choice, integer abilityId returns nothing
    //Add abilityId to choiceIndex
    //one can attach multiple abilities to one choice.
    //one can attach the same ability multiple times to the same choice to increase its level.
    //  ^^ needs function TalentImproveAbilities to return true

//  function TalentChoiceAddAbilityEx takes integer abilityId returns nothing
    //Add to last created Choice

//  function TalentChoiceReplaceAbility takes integer choice, integer oldAbility, integer newAbility returns nothing
    //TalentImproveAbilities(true)oldAbility - 1 Level and newAbility + 1 Level
    //TalentImproveAbilities(false) removed oldAbility, add newAbility set level of newAbility to level of oldAbility

//  function TalentChoiceGetAbilityCount takes integer choice returns integer
//===========================================================================
//Variables inside Events and Code Binding:
//===========================================================================
//  udg_Talent__Unit        = the unit doing the choice
//  udg_Talent__UnitCode    = the unitCode the unit is using
//  udg_Talent__Choice      = the arrayIndex of the selected choice.
//  udg_Talent__Level       = the level from which this choice/Tier is.
//  udg_Talent__Tier        = the arrayIndex of the tier from which the choice is.
//  udg_Talent__Button      = the Index of the Button used, 1 to TalentBoxOptionMaxCount().
//                          , this variable is needed for event based Talent usage.

//===========================================================================
//Event:
//===========================================================================
//  To identyfy a choice in an Event use HeroType, udg_Talent__Level and udg_Talent__Button.
//  Inside trigger condition check for heroType, to use the correct talent tree for this unit.
        // UnitType of udg_Talent__Unit equal (==) "wanted Type"
//  Now create ifs one for each udg_Talent__Level (it is the level of the tier picked from).
//  Inside this ifs now do a check: udg_Talent__Button equal (==) 1  -> yes, do actions of Level x Button 1
//  Create another one with udg_Talent__Button equal (==) 2 -> yes, do actions of Level x, Button 2.
//  You can skip Button Ifs not beeing used for that hero-Class on that Level.

//  udg_Talent__Event
//          = 1 => on Choice.
//              after the Auotskills are added
//          = 2 => Tier aviable, does only call when there is no choice for this hero yet.
//          = 3 => Finished all choices of its hero Type.
//          = -1 => on Reset for each choice reseted.
//              before the autoskills are removed

//  Events can be indivudal (de)aktivaded inside "Definitions"

//===========================================================================
//Code Binding
//===========================================================================
// One can directly bind functions/triggers to an choice, 1 for picking the choice, 1 for reseting the choice.
// Talent allways uses triggers, but one can let the triggers be generated by only giving the functions.
 
//  udg_TalentChoiceOnLearn     -   Executes when Picked
//  udg_TalentChoiceOnReset     -   Executes when Reset, should do the opposite of OnLearn, if one wants to use the reset feature.
//                              -   if there is no reset in your project, just skip reset.

//===========================================================================
//Tier and Choice variables
//===========================================================================
// TalentChoice is a simple rising Array, each index represents a new choice.
//  udg_TalentChoiceLast        - last Index used from TalentChoice
//  udg_TalentChoiceHead        - the headLine shown
//  udg_TalentChoiceText        - the mainTooltip shown
//  udg_TalentChoiceIcon        - the image shown
//  udg_TalentChoiceOnLearn     - trigger
//  udg_TalentChoiceOnReset     - trigger

//  TalentChoice Abilities are Saved in the hash.
//  With the used ArrayIndex as main Key.
//  rising Positive sec Keys are the abilities gained
//  falling negative sec Keys are the abilities replaced.
//=====
// Tier is managed inside the hash.
// used tiers are from 1 to udg_TalentTierLast. (therefore you could also use arrayIndexes)
// Tiers use negative main Keys, (Background Info).

//===========================================================================
//TalentSpells
//===========================================================================
//  udg_TalentSpellsPrefix      - text displayed before the choicesHead, if a choice uses this Button.
//  udg_TalentSpellsSufix       - text displayed after choicesHead

//  The displayed HeadLine is ButtonPrefix + choiceHead + ButtonSufix

//===========================================================================
//udg_TalentTrigger is an array of Triggers controlling this system.
//      udg_TalentTrigger[TT_LevelUp()] = On Levelup| It checks for new Talent Tiers.
//      udg_TalentTrigger[TT_AutoDetectUnits()] = EnterPlayable Map Event
//          , if you alreay have a EnterPlayable Map trigger you should let "constant function TalentAutoDetectNewUser" return false
//          , also you then have to manualy inser talent users by:
//          , if TalentHas(unit) then
//               call TalentAdd2Hero(unit)
//           endif
//      udg_TalentTrigger[TT_SelectUnit()] = Make Talent UI (In)Visbile; Event On Unit Selection.

// you could disable all TalentTriggers[0 to 4], if you do not use reset and all Choices are done.

//      udg_TalentReset = when called resets udg_Talent__Unit and calls for each choice undone the reset event(-1).
//          Reset uses following values
//                  udg_Talent__ResetAmount = amount of talents undone starting from last selected. (use an absurd high number to undo all talents of a hero)
//                  udg_Talent__Unit = the hero losing talents.

//===========================================================================
//udg_TalentStrings contain all builtIn Strings which can/should be localiced used by This System.

//===========================================================================
//TT = TalentTrigger, ArrayIndexes

constant function TT_LevelUp takes nothing returns integer
    return 1
endfunction
constant function TT_AutoDetectUnits takes nothing returns integer
    return 2
endfunction
constant function TT_SelectUnit takes nothing returns integer
    return 3
endfunction
constant function TT_DeathTrigger takes nothing returns integer
    return 4
endfunction



//Hashtable
//unit handleId

constant function TalentHashIndex_LastLevel takes nothing returns integer
    return -1
endfunction
constant function TalentHashIndex_LevelOfLastChoice takes nothing returns integer
    return -2
endfunction
constant function TalentHashIndex_CurrentChoice takes nothing returns integer
    return -3
endfunction
constant function TalentHashIndex_CurrentChoiceLevel takes nothing returns integer
    return -4
endfunction
constant function TalentHashIndex_SelectionsDone takes nothing returns integer
    return -5
endfunction


constant function TalentHashIndex_HasChoice takes nothing returns integer
    return 0
endfunction


//UnitTypeId
//  0 to x choice containers
//  x  =  last talent(true)
constant function TalentHashIndex_DataCopyData takes nothing returns integer
    return -2
endfunction
constant function TalentHashIndex_FinalTierLevel takes nothing returns integer
    return -3
endfunction

//TalentSpells
// at 0 they save its array index.
//===========================================================================
function TalentGetUsedHeroTypeId takes integer heroTypeId returns integer
    local integer copyId = LoadInteger(udg_TalentHash, heroTypeId, TalentHashIndex_DataCopyData())
    if copyId != 0 then
        return TalentGetUsedHeroTypeId(copyId)
    else
        return heroTypeId
    endif  
endfunction
function TalentGetUnitTypeId takes unit u returns integer
    return TalentGetUsedHeroTypeId(GetUnitTypeId(u))
endfunction


//TalentJ
//Handleing Choice / Tier Creations
function TalentChoiceCreateTrigger takes trigger onLearn, trigger onReset returns integer
    set udg_TalentChoiceLast = udg_TalentChoiceLast + 1
    set udg_TalentChoiceOnLearn[udg_TalentChoiceLast] = onLearn
    set udg_TalentChoiceOnReset[udg_TalentChoiceLast] = onReset
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreate takes code onLearn, code onReset returns integer
    set udg_TalentChoiceLast = udg_TalentChoiceLast + 1
    if onLearn != null then
        set udg_TalentChoiceOnLearn[udg_TalentChoiceLast] = CreateTrigger()
        call TriggerAddAction(udg_TalentChoiceOnLearn[udg_TalentChoiceLast], onLearn)
    endif
    if onReset != null then
        set udg_TalentChoiceOnReset[udg_TalentChoiceLast] = CreateTrigger()
        call TriggerAddAction(udg_TalentChoiceOnReset[udg_TalentChoiceLast], onReset)
    endif  
    return udg_TalentChoiceLast
endfunction

function TalentChoiceCreateAll takes string head, string text, string icon, code onLearn, code onReset returns integer
    call TalentChoiceCreate(onLearn, onReset)
    set udg_TalentChoiceHead[udg_TalentChoiceLast] = head
    set udg_TalentChoiceText[udg_TalentChoiceLast] = text
    set udg_TalentChoiceIcon[udg_TalentChoiceLast] = icon
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateAllTrigger takes string head, string text, string icon, trigger onLearn, trigger onReset returns integer
    call TalentChoiceCreateTrigger(onLearn, onReset)
    set udg_TalentChoiceHead[udg_TalentChoiceLast] = head
    set udg_TalentChoiceText[udg_TalentChoiceLast] = text
    set udg_TalentChoiceIcon[udg_TalentChoiceLast] = icon
    return udg_TalentChoiceLast
endfunction

function TalentTierCreate takes nothing returns integer
    set udg_TalentTierLast = udg_TalentTierLast + 1
    return udg_TalentTierLast
endfunction

function TalentTierAddChoice takes integer tier, integer choice returns nothing
    local integer count = LoadInteger(udg_TalentHash, -tier, 0) + 1
    call SaveInteger(udg_TalentHash, -tier, count, choice)
    call SaveInteger(udg_TalentHash, -tier, 0, count)
endfunction
function TalentTierGetChoiceCount takes integer tier returns integer
    if tier > 0 then //tiers are saved in the negative side, convert positive calls in negative ones
        return LoadInteger(udg_TalentHash, -tier, 0)
    else
        return LoadInteger(udg_TalentHash, tier, 0)
    endif  
endfunction
function TalentTierGetChoice takes integer tier, integer index returns integer
    if tier > 0 then //tiers are saved in the negative side, convert positive calls in negative ones
        return LoadInteger(udg_TalentHash, -tier, index)
    else
        return LoadInteger(udg_TalentHash, tier, index)
    endif  
endfunction

function TalentChoiceCreateEx takes code onLearn, code onReset returns integer
    local integer choice = TalentChoiceCreate(onLearn, onReset)
    call TalentTierAddChoice(udg_TalentTierLast, choice)
    return choice
endfunction
function TalentChoiceCreateTriggerEx takes trigger onLearn, trigger onReset returns integer
    local integer choice = TalentChoiceCreateTrigger(onLearn, onReset)
    call TalentTierAddChoice(udg_TalentTierLast, choice)
    return choice
endfunction
function TalentChoiceCreateAllEx takes string head, string text, string icon, code onLearn, code onReset  returns integer
    local integer choice = TalentChoiceCreateAll(head, text, icon, onLearn, onReset)
    call TalentTierAddChoice(udg_TalentTierLast, choice)
    return choice
endfunction
function TalentChoiceCreateAllTriggerEx takes string head, string text, string icon, trigger onLearn, trigger onReset  returns integer
    local integer choice = TalentChoiceCreateAllTrigger(head, text, icon, onLearn, onReset)
    call TalentTierAddChoice(udg_TalentTierLast, choice)
    return choice
endfunction
function TalentChoiceGetAbilityCount takes integer choice returns integer
    return LoadInteger(udg_TalentHash, choice, 0)
endfunction
function TalentChoiceAddAbility takes integer choice, integer abilityId returns nothing
    local integer count = LoadInteger(udg_TalentHash, choice, 0) + 1
    call SaveInteger(udg_TalentHash, choice, count, abilityId)
    call SaveInteger(udg_TalentHash, choice, 0, count)
endfunction
function TalentChoiceAddAbilityEx takes integer abilityId returns nothing
    call TalentChoiceAddAbility(udg_TalentChoiceLast, abilityId)
endfunction

function TalentChoiceReplaceAbility takes integer choice, integer oldAbility, integer newAbility returns nothing
    local integer count = LoadInteger(udg_TalentHash, choice, 0) + 1
    call SaveInteger(udg_TalentHash, choice, count, newAbility)
    call SaveInteger(udg_TalentHash, choice, -count, oldAbility)
    call SaveInteger(udg_TalentHash, choice, 0, count)
endfunction
function TalentChoiceReplaceAbilityEx takes integer oldAbility, integer newAbility returns nothing
    call TalentChoiceReplaceAbility(udg_TalentChoiceLast, oldAbility, newAbility)
endfunction

//TalentHero
//Access data by UnitTypeId
function TalentHeroTierCreate takes integer heroTypeId, integer level returns integer
    call SaveInteger(udg_TalentHash, heroTypeId, level, TalentTierCreate())
    return udg_TalentTierLast
endfunction
function TalentHeroGetTier takes integer heroTypeId, integer level returns integer
    return LoadInteger(udg_TalentHash, heroTypeId, level)
endfunction
function TalentHeroSetTier takes integer heroTypeId, integer level, integer tier returns nothing
    call SaveInteger(udg_TalentHash, heroTypeId, level, tier)
endfunction
function TalentHeroGetFinalTier takes integer heroTypeId returns integer
    return LoadInteger(udg_TalentHash, heroTypeId, TalentHashIndex_FinalTierLevel())
endfunction
function TalentHeroSetFinalTier takes integer heroTypeId, integer level returns nothing
    call SaveInteger(udg_TalentHash, heroTypeId, TalentHashIndex_FinalTierLevel(), level)
endfunction

function TalentHeroSetCopy takes integer result, integer copyOrigin returns nothing
    call SaveInteger(udg_TalentHash, result, TalentHashIndex_DataCopyData(), copyOrigin)
endfunction

function TalentHeroLevel2SelectionIndex takes integer heroTypeId, integer level returns integer
    local integer i = 0
    local integer count = 0
   
    if TalentHeroGetTier(heroTypeId, level) == 0 then //The level has no tier?
        return -1
    endif
   
    loop
        exitwhen i > level
        if TalentHeroGetTier(heroTypeId, i) != 0 then
            set count = count + 1
        endif
        set i = i + 1
    endloop

    return count
endfunction

//TalentUnit
//Talent-Data of an existing unit
function TalentUnitGetSelectionsDoneCount takes integer unitHandle returns integer
    return LoadInteger(udg_TalentHash, unitHandle, TalentHashIndex_SelectionsDone())
endfunction

function TalentUnitGetSelectionButtonUsed takes integer unitHandle, integer selectionIndex returns integer
    return LoadInteger(udg_TalentHash, unitHandle, selectionIndex)
endfunction
function TalentUnitGetSelectionLevel takes integer unitHandle, integer selectionIndex returns integer
    return LoadInteger(udg_TalentHash, unitHandle, StringHash("SelectionLevel"+I2S(selectionIndex)))
endfunction

function TalentUnitGetChoiceDone takes unit u, integer selectionIndex returns integer
    local integer uId = GetHandleId(u)
    return TalentTierGetChoice(TalentHeroGetTier(TalentGetUnitTypeId(u), TalentUnitGetSelectionLevel(uId, selectionIndex)), TalentUnitGetSelectionButtonUsed(uId, selectionIndex))
endfunction

function TalentUnitGetCurrentTier takes integer unitHandle returns integer
    return LoadInteger(udg_TalentHash, unitHandle, TalentHashIndex_CurrentChoice())
endfunction
function TalentUnitGetCurrentTierLevel takes integer unitHandle returns integer
    return LoadInteger(udg_TalentHash, unitHandle, TalentHashIndex_CurrentChoiceLevel())
endfunction


function TalentUnitGetTalentProgressLevel takes integer unitHandle returns integer
    return LoadInteger(udg_TalentHash, unitHandle, TalentHashIndex_LevelOfLastChoice())
endfunction
function TalentUnitHasChoice takes integer unitHandle returns boolean
    return LoadBoolean(udg_TalentHash, unitHandle, TalentHashIndex_HasChoice())
endfunction
//Talent
//=========

function TalentBoxSetTier takes integer level, integer tier, player p returns nothing
    local integer i = TalentBoxOptionMaxCount()
    local integer choice
   
    local integer playerId = GetPlayerId(p)
    local integer unitHandle = GetHandleId(udg_TalentControlTarget[playerId] )
    local integer levelSelectionIndex = TalentHeroLevel2SelectionIndex(TalentGetUnitTypeId(udg_TalentControlTarget[playerId]), level)
    local integer buttonused = TalentUnitGetSelectionButtonUsed(unitHandle, levelSelectionIndex)
    local boolean enable = GetPlayerAlliance(GetOwningPlayer(udg_TalentControlTarget[playerId]), p, ALLIANCE_SHARED_CONTROL) and TalentUnitGetCurrentTierLevel(unitHandle) == level and TalentUnitHasChoice(unitHandle)
    local real frameSizeY = TalentBoxBaseSizeY() + TalentBoxOption2TitleGap() + TalentBoxOption2BottomGap() + RMaxBJ(TalentBoxResetSizeY(), TalentBoxLevelSizeY())
    local real frameSizeX = TalentBoxOptionSizeX() + 0.05
    local real optionSizeY = TalentBoxOptionSizeY()
    local integer selectionDone = TalentUnitGetSelectionsDoneCount(unitHandle)
    set udg_TalentControlLevelsCurrent[playerId] = level
    if GetLocalPlayer() == p then
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxItemParent",0), true)
        loop
            set choice = TalentTierGetChoice(tier, i) //Choices start with 1, buttons with 0
            if choice > 0 then
                call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxItem", i), true)
                call BlzFrameSetText(BlzGetFrameByName("TalentBoxItemTextText", i), udg_TalentChoiceText[choice])
                call BlzFrameSetTexture(BlzGetFrameByName("TalentBoxItemIcon", i), udg_TalentChoiceIcon[choice], 0, true)
                call BlzFrameSetText(BlzGetFrameByName("TalentBoxItemTitle", i), udg_TalentSpellsPrefix[i] + udg_TalentChoiceHead[choice] + udg_TalentSpellsSufix[i]  )
                //set frameSizeY = frameSizeY + optionSizeY
                if i < TalentBoxOptionMaxCount() and i > 1 then
                    set frameSizeY = frameSizeY + optionSizeY + TalentBoxOption2OptionGap()
                else
                    set frameSizeY = frameSizeY + optionSizeY
                endif
            else
                call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxItem", i), false)
            endif
            call BlzFrameSetEnable(BlzGetFrameByName("TalentBoxItem", i), enable)
            set i = i -1
            exitwhen i == 0
        endloop
        if buttonused > 0 and TalentUnitGetSelectionsDoneCount(unitHandle) >= levelSelectionIndex then
            if not BlzFrameIsVisible(BlzGetFrameByName("TalentHighlight", 0)) then
                call BlzFrameSetVisible(BlzGetFrameByName("TalentHighlight", 0),true)
            endif
            call BlzFrameClearAllPoints(BlzGetFrameByName("TalentHighlight", 0))
            //call BlzFrameSetParent(BlzGetFrameByName("TalentHighlight", 0), BlzGetFrameByName("TalentBoxItem", buttonused))
            call BlzFrameSetAllPoints(BlzGetFrameByName("TalentHighlight", 0), BlzGetFrameByName("TalentBoxItem", buttonused)) //Buttons start with 0, talent with 1
        else
            call BlzFrameSetVisible(BlzGetFrameByName("TalentHighlight", 0),false)
        endif
        call BlzFrameSetSize(BlzGetFrameByName("TalentBox", 0), frameSizeX, frameSizeY)
        call BlzFrameSetText(BlzGetFrameByName("TalentBoxTitle", 0), udg_TalentStrings[102] +I2S(level))
        if TalentBoxUseUnlearnButton() then
            call BlzFrameSetEnable(BlzGetFrameByName("TalentResetButton",0), TalentUnitGetCurrentTierLevel(unitHandle) >= level and not udg_TalentControlPreventReset[GetConvertedPlayerId(p)])
        endif
    endif
   
endfunction

function TalentBoxUpdate takes player p returns nothing
    local integer unitHandle = GetHandleId(udg_TalentControlTarget[GetPlayerId(p)])
    call TalentBoxSetTier(TalentUnitGetCurrentTierLevel(unitHandle), TalentUnitGetCurrentTier(unitHandle), p)
endfunction

function TalentBoxLevelClick takes nothing returns nothing
    local framehandle fh = BlzGetTriggerFrame()
    local integer i = TalentBoxLevelAmount()
    local integer playerFactor = TalentBoxLevelAmount()*GetPlayerId(GetTriggerPlayer())
    loop
        if fh == BlzGetFrameByName("TalentBoxLevelButton", i) then
            call TalentBoxSetTier(udg_TalentControlLevels[playerFactor + i], TalentHeroGetTier(TalentGetUnitTypeId(udg_TalentControlTarget[GetPlayerId(GetTriggerPlayer())]), udg_TalentControlLevels[playerFactor + i]), GetTriggerPlayer())
            exitwhen true
        endif
        exitwhen i == 0
        set i = i - 1
    endloop
 
    set fh = null
endfunction

function FrameLoseFocus takes nothing returns nothing
    if GetLocalPlayer() == GetTriggerPlayer() then
        call BlzFrameSetEnable(BlzGetTriggerFrame(), false)
        call BlzFrameSetEnable(BlzGetTriggerFrame(), true)
    endif
endfunction
function TalentBoxUpdateLevelBoxes takes player p, integer levelStart returns nothing
    local integer count = -1
    local integer level = levelStart
    local integer playerId = GetPlayerId(p)
    local integer heroTypeId = TalentGetUnitTypeId(udg_TalentControlTarget[playerId])
    local integer finalLevel = TalentHeroGetFinalTier(heroTypeId)
   
    local integer playerFactor = TalentBoxLevelAmount()*playerId
    if level > finalLevel then
        set level = 0
    endif
    if level < 1 then
        set level = 0
    endif
    if heroTypeId != 0 then
        loop
            if TalentHeroGetTier(heroTypeId,level) != 0 then //Have tier on that Level?
                set count = count + 1
                set udg_TalentControlLevels[playerFactor + count] = level
                set udg_TalentControlLevelsMax[playerId] = level
                if GetLocalPlayer() == p then
                    call BlzFrameSetText(BlzGetFrameByName("TalentBoxLevelButton", count), I2S(level))
                    call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxLevelButton", count), true)
                endif
               
            endif
       
            exitwhen level >= finalLevel
            set level = level + 1
            exitwhen count >= TalentBoxLevelAmount()-1
        endloop
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxLevelParent", 0), count > 1) //when there is only one level to choose from hide the levels

        if GetLocalPlayer() == p and levelStart <= 1 then
            call BlzFrameSetVisible(BlzGetFrameByName("TalentButtonDown", 0), udg_TalentControlLevelsMax[playerId] < finalLevel)
            call BlzFrameSetVisible(BlzGetFrameByName("TalentButtonUp", 0), udg_TalentControlLevelsMax[playerId] < finalLevel)
        endif
        call TalentBoxSetTier(udg_TalentControlLevels[playerFactor], TalentHeroGetTier(heroTypeId, udg_TalentControlLevels[playerFactor]), p)
    endif
    loop
        set count = count + 1
        exitwhen count >= TalentBoxLevelAmount()
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxLevelButton", count), false)
    endloop
endfunction


function TalentBoxUpdateLevelBoxesDown takes player p, integer levelStart returns nothing
    local integer count = TalentBoxLevelAmount()
    local integer level = levelStart
    local integer playerId = GetPlayerId(p)
    local integer heroTypeId = TalentGetUnitTypeId(udg_TalentControlTarget[playerId])
    local integer finalLevel = TalentHeroGetFinalTier(heroTypeId)
   
    local integer playerFactor = TalentBoxLevelAmount()*playerId
    local boolean first = true
    if level <= 0 then
        set level = finalLevel
    endif
    if heroTypeId != 0 then
        loop
            if TalentHeroGetTier(heroTypeId,level) != 0 then //Have tier on that Level?
                set count = count - 1
                set udg_TalentControlLevels[playerFactor + count] = level
                if first then
                    set udg_TalentControlLevelsMax[playerId] = level
                    set first = false
                endif
                if GetLocalPlayer() == p then
                    call BlzFrameSetText(BlzGetFrameByName("TalentBoxLevelButton", count), I2S(level))
                    call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxLevelButton", count), true)
                endif
               
            endif
       
            exitwhen level <= 0
            set level = level - 1
            exitwhen count == 0
        endloop
        call TalentBoxSetTier(udg_TalentControlLevelsMax[playerId], TalentHeroGetTier(heroTypeId, udg_TalentControlLevelsMax[playerId]), p)
    endif
endfunction

function TalentBoxLevelUpButtonAction takes nothing returns nothing
    local integer playerFactor = TalentBoxLevelAmount()*GetPlayerId(GetTriggerPlayer())
    call TalentBoxUpdateLevelBoxes(GetTriggerPlayer(), udg_TalentControlLevelsMax[GetPlayerId(GetTriggerPlayer())] + 1)
endfunction

function TalentLevelBoxDownButtonAction takes nothing returns nothing
    local integer playerFactor = TalentBoxLevelAmount()*GetPlayerId(GetTriggerPlayer())
    call TalentBoxUpdateLevelBoxesDown(GetTriggerPlayer(), udg_TalentControlLevels[playerFactor] - 1)
endfunction
 function TalentBoxShowEmpty takes player activePlayer returns nothing
        local real frameSizeY = 0.08
        local real frameSizeX = TalentBoxOptionSizeX() + 0.05
        local real optionSizeY = TalentBoxOptionSizeY()
        set udg_TalentControlLevelsCurrent[GetPlayerId(activePlayer)] = 0      
       
        if GetLocalPlayer() == activePlayer then
            call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxItemParent",0), false)
            call BlzFrameSetVisible(BlzGetFrameByName("TalentBoxLevelParent",0), false)
           
            call BlzFrameSetSize(BlzGetFrameByName("TalentBox",0), frameSizeX, frameSizeY)
            call BlzFrameSetText(BlzGetFrameByName("TalentBoxTitle",0), udg_TalentStrings[104])
        endif
    endfunction
   
function TalentHas takes unit u returns boolean
    return HaveSavedInteger(udg_TalentHash, TalentGetUnitTypeId(u), TalentHashIndex_FinalTierLevel())
endfunction

//Shows the TalentBox and sets the target for activePlayer.
function TalentBoxShow takes unit target, player activePlayer returns nothing
    local integer playerId = GetPlayerId(activePlayer)
    local integer unitHandle = GetHandleId(target)
    set udg_TalentControlTarget[playerId] = target //unit used look
    if TalentHas(target) then
        call TalentBoxUpdateLevelBoxes(activePlayer, 0)
        call TalentBoxSetTier(TalentUnitGetCurrentTierLevel(unitHandle), TalentUnitGetCurrentTier(unitHandle), activePlayer)
        if TalentBoxUseUnlearnButton() then
            call BlzFrameSetVisible(BlzGetFrameByName("TalentResetButton",0), GetPlayerAlliance(GetOwningPlayer(udg_TalentControlTarget[playerId]), activePlayer, ALLIANCE_SHARED_CONTROL))
        endif
    else
        call TalentBoxShowEmpty(activePlayer)
        if TalentBoxUseUnlearnButton() then
            call BlzFrameSetVisible(BlzGetFrameByName("TalentResetButton",0), false)
        endif
    endif
endfunction

//has the general Choice UI or hero specific Choice UI.
function TalentHasCondition takes nothing returns boolean
    return TalentHas(GetTriggerUnit())
endfunction

function TalentAddSelection takes unit u returns nothing
    local integer tierGained
    local integer heroTypeId = TalentGetUnitTypeId(u)
    local integer currentLevel = IMaxBJ(GetHeroLevel(u), GetUnitLevel(u))
    local integer uId = GetHandleId(u)
    local player owner
    //Start from the last skill selection added.
    local integer loopA = TalentUnitGetTalentProgressLevel(uId)

    // Only show 1 SelectionContainer at the same time.
    if TalentUnitHasChoice(uId) then
        return
    endif

    set owner = GetOwningPlayer(u)
    loop
        exitwhen loopA > currentLevel
        set tierGained = TalentHeroGetTier(heroTypeId, loopA)          
        if tierGained != 0 then
           
            //Remember the container gained
            call SaveInteger(udg_TalentHash, uId, TalentHashIndex_CurrentChoice(), tierGained)
            //Remember the level of the container gained
            call SaveInteger(udg_TalentHash, uId, TalentHashIndex_CurrentChoiceLevel(), loopA)
            //Mark unit to have a selection.
            call SaveBoolean(udg_TalentHash, uId, TalentHashIndex_HasChoice(), true)
            //Remember this Level to leave lower levels out for further selections checks.
            call SaveInteger(udg_TalentHash, uId,TalentHashIndex_LevelOfLastChoice(),loopA +1)
           
            if TalentThrowEventAvailable() then //Throw Selection Event
                set udg_Talent__Choice = 0
                set udg_Talent__Unit = u
                set udg_Talent__UnitCode = heroTypeId
                set udg_Talent__Level = loopA
                set udg_Talent__Tier = tierGained
                set udg_Talent__Event = 0
                set udg_Talent__Event = 2
                set udg_Talent__Event = 0
            endif
            call TalentBoxSetTier(loopA, tierGained, owner)
            set owner = null
           
            return
        endif
        set loopA = loopA + 1
    endloop
    //if this part of code is reached there is no choice avaible
    call TalentBoxSetTier(TalentUnitGetCurrentTierLevel(uId), TalentUnitGetCurrentTier(uId), owner)
    //Remember this Level to leave lower levels out for further selections checks.
    call SaveInteger(udg_TalentHash, uId,TalentHashIndex_LevelOfLastChoice(),currentLevel + 1)
    if TalentCloseWhenNoChoice() and GetLocalPlayer() == GetTriggerPlayer() then
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBox", 0), false)
        call BlzFrameSetVisible(BlzGetFrameByName("TalentShowButton", 0), true)
    endif
    set owner = null
endfunction


function TalentAddSkill takes unit u, integer skillGained, integer newLevel returns nothing
    local integer skillGainedLevel = GetUnitAbilityLevel(u, skillGained)
    if skillGainedLevel == 0 then //Already got skillGained?
        call UnitAddAbility(u, skillGained)
        call UnitMakeAbilityPermanent(u, true, skillGained)
        call SetUnitAbilityLevel(u, skillGained, newLevel)
    elseif TalentImproveAbilities() then//Can upgrade Levels?
        call SetUnitAbilityLevel(u, skillGained, skillGainedLevel + 1)
    endif
endfunction
function TalentRemoveSkill takes unit u, integer skillLost returns nothing
    local integer skillLostLevel = GetUnitAbilityLevel(u, skillLost)
    if TalentImproveAbilities() and skillLostLevel > 1 then //Can Decrease Level?
        set skillLostLevel = skillLostLevel - 1
        call SetUnitAbilityLevel(u, skillLost, skillLostLevel)
    else
        call UnitRemoveAbility(u, skillLost)
    endif
endfunction
function TalentReplaceSkill takes unit u, integer skillReplaced, integer skillGained returns nothing
    local integer skillReplacedLevel = GetUnitAbilityLevel(u, skillReplaced)
    if not TalentReplacedAbilityRequiered() or skillReplacedLevel != 0 then
        call TalentRemoveSkill(u, skillReplaced)
        if skillGained != 0 then
            call TalentAddSkill(u, skillGained, skillReplacedLevel)
        endif
    endif
endfunction

function TalentPickDo takes unit u, integer buttonNr returns nothing
    local integer uId               = GetHandleId(u)
    local integer heroTypeId        = TalentGetUnitTypeId(u)
    local integer tier              = TalentUnitGetCurrentTier(uId)
    local integer tierLevel         = TalentUnitGetCurrentTierLevel(uId)
    local integer selectionsDone    = TalentUnitGetSelectionsDoneCount(uId) + 1
    local integer choiceIndex       = TalentTierGetChoice(tier, buttonNr)
    local integer skillGained
    local integer skillReplaced
    local integer loopB             = TalentChoiceGetAbilityCount(choiceIndex)
    if not TalentUnitHasChoice(uId) or choiceIndex == 0 then //Requiers to have a Choice
        return
    endif
   
    loop    //Load all saved Abilities and add/improve them to the unit
        exitwhen loopB == 0
        set skillGained = LoadInteger(udg_TalentHash, choiceIndex, loopB)
        set skillReplaced = LoadInteger(udg_TalentHash, choiceIndex, -loopB)
       
        if skillReplaced != 0 then //Replaces?
            call TalentReplaceSkill(u, skillReplaced, skillGained)
        else
            call TalentAddSkill(u, skillGained,1)
        endif
        set loopB = loopB - 1
    endloop

    //Execute OnLearn
    set udg_Talent__Unit = u
    set udg_Talent__UnitCode = heroTypeId
    set udg_Talent__Button = buttonNr
    set udg_Talent__Choice = choiceIndex
    set udg_Talent__Tier = tier
    set udg_Talent__Level = tierLevel
    call TriggerExecute(udg_TalentChoiceOnLearn[choiceIndex])
   
    if TalentThrowEventPick() then
        //Throw Selection Event
        set udg_Talent__Event = 0
        set udg_Talent__Event = 1
        set udg_Talent__Event = 0
    endif
    //Save Choices
    //call SaveInteger(udg_TalentHash, uId, selectionsDone, choiceIndex) //Save the picked ChoiceIndex
    call SaveInteger(udg_TalentHash, uId, selectionsDone, buttonNr) //Save the picked ButtonIndex
    call SaveInteger(udg_TalentHash, uId, TalentHashIndex_SelectionsDone(), selectionsDone)
    call SaveInteger(udg_TalentHash, uId, StringHash("SelectionLevel"+I2S(selectionsDone)), tierLevel)

    //Unmark having a selection.
    call SaveBoolean(udg_TalentHash, uId, TalentHashIndex_HasChoice(), false)
    //Last choice for this heroType?
    if TalentHeroGetFinalTier(heroTypeId) == tierLevel then
       
        //Throw Finish Choices Event.
        if TalentThrowEventFinish() then
            set udg_Talent__Event = 0
            set udg_Talent__Event = 3
            set udg_Talent__Event = 0
        endif
        if not TalentCloseWhenNoChoice() then
            call TalentBoxUpdate(GetTriggerPlayer())
        elseif GetLocalPlayer() == GetTriggerPlayer() then
            call BlzFrameSetVisible(BlzGetFrameByName("TalentBox", 0), false)
            call BlzFrameSetVisible(BlzGetFrameByName("TalentShowButton", 0), true)
        endif
    else
        //Check for further choices.
        call TalentAddSelection(u)
    endif
    set u = null
endfunction

function TalentLevelUpSimple takes nothing returns nothing
    call TalentAddSelection(GetTriggerUnit())
endfunction

function TalentOnDeath takes nothing returns nothing
    if GetTriggerUnit() == udg_TalentControlTarget[GetPlayerId(GetLocalPlayer())] then
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBox", 0), false)
        call BlzFrameSetVisible(BlzGetFrameByName("TalentShowButton", 0), true)
    endif
endfunction

function TalentAdd2Hero takes unit u returns nothing
    local integer uId = GetHandleId(u)
    if not IsUnitInGroup(u, udg_TalentUser) then
        call GroupAddUnit(udg_TalentUser, u)
    endif  
    call TalentAddSelection(u)
endfunction
function TalentAutoOnEnterMap takes nothing returns nothing
    call TalentAdd2Hero(GetTriggerUnit())
endfunction

function TalentResetDo takes unit u, integer amountOfResets returns nothing
    local integer uId
    local integer heroTypeId
    local integer selectionsDone
    local integer skillGained
    local integer skillReplaced
    local integer choice
    local integer level
    local integer loopB = 0
    local integer customUI
    local integer tier
    local integer spellNr
    local boolean isUsingBook
    //stop nullpointer.
    if u == null then
        return
    endif
    // reset less then 1 does not make sense.
    if amountOfResets < 1 then
        return
    endif
    set uId = GetHandleId(u)
    set heroTypeId = TalentGetUnitTypeId(u)
    set selectionsDone = TalentUnitGetSelectionsDoneCount(uId)
    //No selections done -> skip the rest.
    if selectionsDone == 0 then
        return
    endif
   
    set udg_Talent__Unit = u
    set udg_Talent__UnitCode = heroTypeId
    //Remove Autoadded Skills
    loop
        set level = TalentUnitGetSelectionLevel(uId, selectionsDone)
        set tier = TalentHeroGetTier(heroTypeId, level)
        set spellNr = TalentUnitGetSelectionButtonUsed(uId, selectionsDone)
        set choice = TalentTierGetChoice(tier, spellNr)
       
        set udg_Talent__Choice = choice
        set udg_Talent__Tier = tier
        set udg_Talent__Level = level
        set udg_Talent__Button = spellNr
       
       
        if TalentThrowEventReset() then //Throw a event that this choice is going to be lost.
            set udg_Talent__Event = 0
            set udg_Talent__Event = -1
            set udg_Talent__Event = 0
        endif
       
        set loopB = TalentChoiceGetAbilityCount(choice)
        loop    //Load all saved Abilities and add/improve them to the unit
            exitwhen loopB == 0
            set skillGained = LoadInteger(udg_TalentHash, choice, loopB)
            set skillReplaced = LoadInteger(udg_TalentHash, choice, -loopB)
           
            if skillReplaced != 0 then //Replaces?
                call TalentReplaceSkill(u, skillGained, skillReplaced)
            else
                call TalentRemoveSkill(u, skillGained)
            endif
            set loopB = loopB - 1
        endloop
       
        call TriggerExecute(udg_TalentChoiceOnReset[choice])
       
        set selectionsDone = selectionsDone - 1
        set amountOfResets = amountOfResets - 1
        exitwhen selectionsDone <= 0 or amountOfResets <= 0
    endloop
   
   
    //Forget this unit?
    if selectionsDone <= 0 then
        //Save Level Progress of talents to the choice Level.
        call SaveInteger(udg_TalentHash, uId, TalentHashIndex_LevelOfLastChoice(), 0)      
        //Choices Done
        call SaveInteger(udg_TalentHash, uId,TalentHashIndex_SelectionsDone(), 0)
        call SaveBoolean(udg_TalentHash, uId,TalentHashIndex_HasChoice(), false)
        //Full Reset
//      call FlushChildHashtable(udg_TalentHash, uId)
    else
        //Partly Reset.
       
        //Has no Choice,dat is needed to run the addChoice function.
        call SaveBoolean(udg_TalentHash, uId,TalentHashIndex_HasChoice(), false)

        //Save Level Progress of talents to the choice Level.
        call SaveInteger(udg_TalentHash, uId, TalentHashIndex_LevelOfLastChoice(), level)

       
        //Choices Done
        call SaveInteger(udg_TalentHash, uId,TalentHashIndex_SelectionsDone(), selectionsDone)
    endif  
   
    call TalentAddSelection(u)
endfunction

function TalentReset takes nothing returns nothing
    call TalentResetDo(udg_Talent__Unit, udg_Talent__ResetAmount)
    set udg_Talent__Unit = null
endfunction

function TalentShowUI takes nothing returns nothing
    call TalentBoxShow(GetTriggerUnit(), GetTriggerPlayer())
endfunction

//runs when executing the Talent <gen> trigger.
function TalentInit takes nothing returns nothing
    local group g = CreateGroup()
    local unit fog
    local integer fogId
    local integer loopA = 0
    local player p
   
    set udg_TalentTrigger[TT_LevelUp()] = CreateTrigger()
    set udg_TalentTrigger[TT_AutoDetectUnits()] = CreateTrigger()
    set udg_TalentTrigger[TT_SelectUnit()] = CreateTrigger()
    set udg_TalentTrigger[TT_DeathTrigger()] = CreateTrigger()
   
    set udg_TalentReset = CreateTrigger()
           
    call TriggerAddAction( udg_TalentReset, function TalentReset)
   
    call TriggerAddAction( udg_TalentTrigger[TT_LevelUp()], function TalentLevelUpSimple)
   
    call TriggerAddAction( udg_TalentTrigger[TT_SelectUnit()], function TalentShowUI)

    call TriggerAddAction( udg_TalentTrigger[TT_DeathTrigger()], function TalentOnDeath)
   
    //Get Choices on Entering Map for lvl 0/1.
    if TalentAutoDetectNewUser() then
        call TriggerRegisterEnterRectSimple( udg_TalentTrigger[TT_AutoDetectUnits()], GetPlayableMapRect() )
    endif  
    call TriggerAddAction( udg_TalentTrigger[TT_AutoDetectUnits()], function TalentAutoOnEnterMap)
    call TriggerAddCondition( udg_TalentTrigger[TT_AutoDetectUnits()], Condition( function TalentHasCondition ))
    set loopA = 0
    loop
        set p = Player(loopA)
        call TriggerRegisterPlayerUnitEvent(udg_TalentTrigger[TT_LevelUp()], p, EVENT_PLAYER_HERO_LEVEL, null)
        call TriggerRegisterPlayerUnitEvent(udg_TalentTrigger[TT_SelectUnit()], p, EVENT_PLAYER_UNIT_SELECTED, null)
        call TriggerRegisterPlayerUnitEvent(udg_TalentTrigger[TT_DeathTrigger()], p, EVENT_PLAYER_UNIT_DEATH, null)
       
        set loopA = loopA + 1
        exitwhen loopA == bj_MAX_PLAYER_SLOTS
    endloop
   
    //Add possible choices to all Units having the Talent book.
    call GroupEnumUnitsInRect (g, GetPlayableMapRect(), null)
    loop
        set fog = FirstOfGroup(g)
        exitwhen fog == null
        call GroupRemoveUnit(g,fog)
        if TalentHas(fog) then
            call TalentAdd2Hero(fog)
        endif
    endloop
   
    //cleanup
    call DestroyGroup(g)
    set g = null
    set p = null
    set fog = null
   
    call ExecuteFunc("TalentBoxCreate")
    //make this trigger unuseable
    call TriggerClearActions(gg_trg_Talent)
    call TriggerClearConditions(gg_trg_Talent)
   
endfunction

function TalentBoxChoiceClick takes nothing returns nothing
    local framehandle fh = BlzGetTriggerFrame()
    local integer i = TalentBoxOptionMaxCount()
    if GetLocalPlayer() == GetTriggerPlayer() then
        call BlzFrameSetEnable(fh, false)
        call BlzFrameSetEnable(fh, true)
    endif

    loop
        if fh == BlzGetFrameByName("TalentBoxItem", i) then
            call TalentPickDo(udg_TalentControlTarget[GetPlayerId(GetTriggerPlayer())], i) //Choices start with 1, buttons with 0
            call TalentBoxUpdate(GetTriggerPlayer())
            exitwhen true
        endif
        set i = i -1
        exitwhen i == - 1
    endloop
    set fh = null
endfunction

function TalentResetButtonAction takes nothing returns nothing
    local integer playerId = GetPlayerId(GetTriggerPlayer())
    local integer unitHandle = GetHandleId(udg_TalentControlTarget[playerId] )
    local integer shownLevel = TalentHeroLevel2SelectionIndex(TalentGetUnitTypeId(udg_TalentControlTarget[playerId]), udg_TalentControlLevelsCurrent[playerId])
    local integer selectedCount = TalentUnitGetSelectionsDoneCount(unitHandle)
    local integer i
    if selectedCount + 1 - shownLevel > 0 then //reset
        call TalentResetDo(udg_TalentControlTarget[playerId], selectedCount + 1 - shownLevel)
    else //learn all rested talents.
        loop
            set selectedCount = selectedCount + 1
            set i = TalentUnitGetSelectionButtonUsed(unitHandle, selectedCount)
            exitwhen i == 0
            call TalentPickDo(udg_TalentControlTarget[playerId], i)
        endloop
    endif
    call TalentBoxUpdate(GetTriggerPlayer())
endfunction
function TalentBoxCloseButtonAction takes nothing returns nothing
    if GetLocalPlayer() == GetTriggerPlayer() then
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBox", 0), false)
        call BlzFrameSetVisible(BlzGetFrameByName("TalentShowButton", 0), true)
    endif
endfunction
function TalentBoxShowButtonAction takes nothing returns nothing
    if GetLocalPlayer() == GetTriggerPlayer() then
        call BlzFrameSetVisible(BlzGetFrameByName("TalentBox", 0), true)
        call BlzFrameSetVisible(BlzGetFrameByName("TalentShowButton", 0), false)
        call TalentBoxUpdate(GetTriggerPlayer())
    endif
endfunction

function TalentBoxCreate takes nothing returns nothing
   
    local framehandle talentBox = BlzCreateFrameByType("Dialog", "TalentBox", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "ScriptDialog", 0)
    local framehandle talentBoxItemParent = BlzCreateFrameByType("FRAME", "TalentBoxItemParent", talentBox, "", 0)
    local framehandle talentBoxLevelParent = BlzCreateFrameByType("FRAME", "TalentBoxLevelParent", talentBox, "", 0)
    local framehandle talentBoxItem
    local framehandle fh
    local framehandle selected = BlzCreateFrame("TalentHighlight", talentBox, 0, 0)
    local framehandle reset
    local framehandle pageUp = BlzCreateFrame("TalentButtonUp", talentBoxLevelParent, 0, 0)
    local framehandle pageDown =  BlzCreateFrame("TalentButtonDown", talentBoxLevelParent, 0, 0)
    local framehandle resetToolTip
    local framehandle closeButton = BlzCreateFrameByType("GLUETEXTBUTTON", "TalentCloseButton",talentBox, "ScriptDialogButton", 0)
    local framehandle showButton = BlzCreateFrameByType("GLUETEXTBUTTON", "TalentShowButton", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "ScriptDialogButton", 0)
    local integer i = 1
    local trigger choiceHandler = CreateTrigger()
    local trigger levelBoxHandler = CreateTrigger()
    local trigger resetHandler
    local trigger pageDownHandler = CreateTrigger()
    local trigger pageUpHandler = CreateTrigger()
    local trigger closeButtonHandler = CreateTrigger()
    local trigger showButtonHandler = CreateTrigger()
   
   
    call BlzFrameSetSize(showButton, 0.05, 0.05)
    call BlzFrameSetText(showButton, udg_TalentStrings[103])
   
    call BlzFrameSetPoint(BlzCreateFrameByType("TEXT", "TalentBoxTitle", talentBox, "TalentBoxTitle", 0), FRAMEPOINT_TOP, talentBox, FRAMEPOINT_TOP, 0.0, -0.03)
   
    call BlzFrameSetAbsPoint(showButton, TalentBoxShowButtonPosType(), TalentBoxShowButtonPosX(), TalentBoxShowButtonPosY())
   
    call TriggerAddAction(choiceHandler, function TalentBoxChoiceClick)
    call TriggerAddAction(levelBoxHandler, function TalentBoxLevelClick)
    call TriggerAddAction(pageDownHandler, function TalentLevelBoxDownButtonAction)
    call TriggerAddAction(pageUpHandler, function TalentBoxLevelUpButtonAction)
    call TriggerAddAction(closeButtonHandler, function TalentBoxCloseButtonAction)
    call TriggerAddAction(showButtonHandler, function TalentBoxShowButtonAction)
   
    //call TriggerAddAction(choiceHandler, function FrameLoseFocus)
    call TriggerAddAction(levelBoxHandler, function FrameLoseFocus)
    call TriggerAddAction(pageDownHandler, function FrameLoseFocus)
    call TriggerAddAction(pageUpHandler, function FrameLoseFocus)
    call TriggerAddAction(closeButtonHandler, function FrameLoseFocus)
   

    call BlzFrameSetText(closeButton,  "X")
    call BlzFrameSetSize(closeButton, 0.035, 0.035)
   
    call BlzFrameSetVisible(selected, false)


    call BlzTriggerRegisterFrameEvent(pageDownHandler, pageDown, FRAMEEVENT_CONTROL_CLICK)
    call BlzTriggerRegisterFrameEvent(pageUpHandler, pageUp, FRAMEEVENT_CONTROL_CLICK)
   
    call BlzTriggerRegisterFrameEvent(closeButtonHandler, closeButton, FRAMEEVENT_CONTROL_CLICK)
    call BlzTriggerRegisterFrameEvent(showButtonHandler, showButton, FRAMEEVENT_CONTROL_CLICK)
   
 

    call BlzFrameSetAbsPoint(talentBox, TalentBoxPosType(), TalentBoxPosX(), TalentBoxPosY())
       
    call BlzFrameSetText(BlzGetFrameByName("TalentBoxTitle", 0),  udg_TalentStrings[102])
    loop
        exitwhen i > TalentBoxOptionMaxCount()
        set talentBoxItem = BlzCreateFrame("TalentBoxItem", talentBoxItemParent, 0, i)
        call BlzFrameSetPoint(talentBoxItem, FRAMEPOINT_BOTTOM, BlzGetFrameByName("TalentBoxItem", i - 1), FRAMEPOINT_TOP, 0, TalentBoxOption2OptionGap())

        call BlzFrameSetEnable(BlzGetFrameByName("TalentBoxItemInfoText", i), false)
        call BlzFrameSetEnable(BlzGetFrameByName("TalentBoxItemTextText", i), false)
        call BlzFrameSetEnable(BlzGetFrameByName("TalentBoxItemTitle", i), false)
        call BlzFrameSetSize(talentBoxItem, TalentBoxOptionSizeX(), TalentBoxOptionSizeY())
        call BlzFrameSetSize(BlzGetFrameByName("TalentBoxItemIcon", i), TalentBoxOptionIconSize(), TalentBoxOptionIconSize())
        call BlzTriggerRegisterFrameEvent(choiceHandler, talentBoxItem, FRAMEEVENT_CONTROL_CLICK)
        set i = i + 1
    endloop
   
    call BlzFrameSetPoint(BlzGetFrameByName("TalentBoxItem", 1), FRAMEPOINT_BOTTOMLEFT, talentBox, FRAMEPOINT_BOTTOMLEFT, 0.025, 0.0235 + TalentBoxOption2BottomGap() + RMaxBJ(TalentBoxResetSizeY(), TalentBoxLevelSizeY()))
    //call BlzFrameSetVisible(BlzGetFrameByName("TalentHighlight", 1), false)
   
    call BlzFrameSetPoint(closeButton, FRAMEPOINT_TOPRIGHT, talentBox, FRAMEPOINT_TOPRIGHT, 0.0, 0)
   
    set i = 0
    loop
        set fh = BlzCreateFrame("TalentBoxLevelButton", talentBoxLevelParent, 0, i)
        call BlzFrameSetPoint(fh, FRAMEPOINT_BOTTOMLEFT, BlzGetFrameByName("TalentBoxLevelButton", i - 1), FRAMEPOINT_BOTTOMRIGHT, 0,0)
        call BlzFrameSetSize(fh, TalentBoxLevelSizeX(), TalentBoxLevelSizeY())
        call BlzTriggerRegisterFrameEvent(levelBoxHandler, fh, FRAMEEVENT_CONTROL_CLICK)
        set i = i + 1
        exitwhen i == TalentBoxLevelAmount()
    endloop
    call BlzFrameSetPoint(BlzGetFrameByName("TalentBoxLevelButton",0), FRAMEPOINT_BOTTOMLEFT, talentBox, FRAMEPOINT_BOTTOMLEFT, 0.027,0.0235)
   
    call BlzFrameSetVisible(talentBox, false)
   
    call BlzFrameSetPoint(pageDown, FRAMEPOINT_BOTTOMLEFT, fh, FRAMEPOINT_BOTTOMRIGHT, 0, 0)
    call BlzFrameSetPoint(pageUp, FRAMEPOINT_BOTTOM, pageDown, FRAMEPOINT_TOP, 0, 0)
   
    if TalentBoxUseUnlearnButton() then
        set resetHandler = CreateTrigger()
        set reset = BlzCreateFrameByType("GLUETEXTBUTTON", "TalentResetButton",talentBox, "ScriptDialogButton", 0)
        set resetToolTip = BlzCreateFrame("TalentBoxTextArea", talentBox, 0, 0)
        call BlzFrameSetPoint(resetToolTip, FRAMEPOINT_LEFT, talentBox, FRAMEPOINT_RIGHT, 0.03,0)
        call BlzFrameSetSize(resetToolTip, 0.22, 0.09)
        call BlzFrameSetText(resetToolTip, udg_TalentStrings[100])
        call BlzFrameSetTooltip(reset, resetToolTip)
        call BlzFrameSetText(reset,  udg_TalentStrings[101])
        call BlzFrameSetSize(reset, TalentBoxResetSizeX(), TalentBoxResetSizeY())
        call BlzTriggerRegisterFrameEvent(resetHandler, reset, FRAMEEVENT_CONTROL_CLICK)
        call TriggerAddAction(resetHandler, function TalentResetButtonAction)
        call TriggerAddAction(resetHandler, function FrameLoseFocus)
        call BlzFrameSetPoint(reset, FRAMEPOINT_BOTTOMRIGHT, talentBox, FRAMEPOINT_BOTTOMRIGHT, -0.027, 0.0235)
    endif
   
    set fh = null
endfunction

function TalentMacroDo takes unit u, string s returns nothing
    local string char
    local integer i = 0
    local integer sLength = StringLength(s)
    local integer charAsInt
    set char = SubString(s, 0, 1)
    if char != "-" then //Invalid macro, macro has to start with "-"
        return
    endif
    loop
        exitwhen i > sLength
        set char = SubString(s, i, i + 1)

        if char == "U" or char == "u" then
            call TalentResetDo(u, 999999)
        endif
        set charAsInt = S2I(char)
        if charAsInt > 0 then
            call TalentPickDo(u, charAsInt)
        endif
        set i = i + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Talent takes nothing returns nothing
    //This has to run before any TalentHeroSheet generations
    set gg_trg_Talent = CreateTrigger(  )
    set udg_TalentHash = InitHashtable(  )
    call TriggerAddAction( gg_trg_Talent, function TalentInit) //The TalentInit has to run after all TalentHeroSheets were generated
    call ExecuteFunc("TalentStringsInit")   //TalentStringsInit should run before any TalentHeroSheet was generated
    call BlzLoadTOCFile("war3mapimported\\talentbox.toc")
endfunction
 
Talent init
  Events
    Time - Elapsed game time is 0.00 seconds
  Conditions
  Actions
    -------- This Trigger should run after all Talents for the hereos were setuped --------
    -------- Define the talentspells --------
    Set VariableSet TalentSpellsPrefix[1] = |cffffcc00
    Set VariableSet TalentSpellsPrefix[2] = |cffff00cc
    Set VariableSet TalentSpellsPrefix[3] = |cffcccccc
    -------- One can define PreFix[1 to 5] and SuFix[1 to 5] to display something before and after the Choices head if it uses this Choice Button. --------
    -------- Prefix and Sufix are not shown inside Choices Done. --------
    -------- Start the system, will also add skillchoices for all already existing units. (Level 0/1) --------
    Trigger - Run Talent <gen> (ignoring conditions)
//TalentPreMadeChoice 1.2a
//by Tasyen

// Contains Predefined ChoiceCreations

//API
//=========
//  function TalentChoiceCreateStats takes integer strAdd, integer agiAdd, integer intAdd returns integer
//      Create a new Choice which adds Str, agi and int.
//      The Choice is added to the last created Tier.
//      This also generates Main-Text showing the stats gained.
//      If you wana add pre Text do it as shown below
//      set udg_TalentChoiceText[udg_TalentChoiceLast] = "your Text" + udg_TalentChoiceText[udg_TalentChoiceLast]

//  function TalentChoiceCreateStr takes integer add returns integer
//  function TalentChoiceCreateAgi takes integer add returns integer
//  function TalentChoiceCreateInt takes integer add returns integer

//  function TalentChoiceCreateSustain takes integer lifeAdd, integer manaAdd, real armorAdd returns integer

//  function TalentChoiceCreateImproveWeapon takes integer weaponIndex, integer damageAdd, real cooldownAdd returns integer

//  function TalentChoiceCreateImproveSpell takes integer spell, integer manaCostAdd, real cooldownAdd returns integer
//      use negative values to improve the spell.

//  function TalentChoiceCreateAddSpells takes integer spell1, integer spell2, integer spell3 returns integer
//      creates a new choice add it to the last created Tier and pushes spell1, spell2, and spell3 onto the choice.
//      spell2 and spell3 are only added if they are not 0.

//  function TalentChoiceCreateAddSpell takes integer spell, boolean useButtonInfos returns integer
//      this choice will add 1 ability, if useButtonInfos is used then text, HeadLine and Icon are taken from the spell

//  function TalentChoiceCreateReplaceSpell takes integer oldSpell, integer newSpell returns integer

//=======================

function TalentChoiceAddTextInt takes string name, integer value returns nothing
    if value != 0 then
        set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentChoiceText[udg_TalentChoiceLast] +name+"|r: "+ I2S(value)
    endif
endfunction
function TalentChoiceAddTextIntAsObject takes string name, integer value returns nothing
    if value != 0 then
        set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentChoiceText[udg_TalentChoiceLast] +name+ GetObjectName(value)+"|r"
    endif
endfunction
function TalentChoiceAddTextReal takes string name, real value returns nothing
    if value != 0 then
        set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentChoiceText[udg_TalentChoiceLast] +name+"|r: "+ R2SW(value,1,1)
    endif
endfunction
function TalentChoiceStatsLearn takes nothing returns nothing
    call SetHeroStr(udg_Talent__Unit, GetHeroStr(udg_Talent__Unit,false) + udg_TalentChoiceInt1[udg_Talent__Choice],true)
    call SetHeroAgi(udg_Talent__Unit, GetHeroAgi(udg_Talent__Unit,false) + udg_TalentChoiceInt2[udg_Talent__Choice],true)
    call SetHeroInt(udg_Talent__Unit, GetHeroInt(udg_Talent__Unit,false) + udg_TalentChoiceInt3[udg_Talent__Choice],true)
endfunction
function TalentChoiceStatsReset takes nothing returns nothing
    call SetHeroStr(udg_Talent__Unit, GetHeroStr(udg_Talent__Unit,false) - udg_TalentChoiceInt1[udg_Talent__Choice],true)
    call SetHeroAgi(udg_Talent__Unit, GetHeroAgi(udg_Talent__Unit,false) - udg_TalentChoiceInt2[udg_Talent__Choice],true)
    call SetHeroInt(udg_Talent__Unit, GetHeroInt(udg_Talent__Unit,false) - udg_TalentChoiceInt3[udg_Talent__Choice],true)
endfunction
function TalentChoiceSustainLearn takes nothing returns nothing
    call BlzSetUnitMaxHP(udg_Talent__Unit, BlzGetUnitMaxHP(udg_Talent__Unit) + udg_TalentChoiceInt1[udg_Talent__Choice])
    call BlzSetUnitMaxMana(udg_Talent__Unit, BlzGetUnitMaxMana(udg_Talent__Unit) + udg_TalentChoiceInt2[udg_Talent__Choice])
    call BlzSetUnitArmor(udg_Talent__Unit, BlzGetUnitArmor(udg_Talent__Unit) + udg_TalentChoiceReal1[udg_Talent__Choice])
    call SetUnitState(udg_Talent__Unit, UNIT_STATE_LIFE, GetUnitState(udg_Talent__Unit,UNIT_STATE_LIFE) + udg_TalentChoiceInt1[udg_Talent__Choice])
    call SetUnitState(udg_Talent__Unit, UNIT_STATE_MANA, GetUnitState(udg_Talent__Unit,UNIT_STATE_MANA) + udg_TalentChoiceInt2[udg_Talent__Choice])
endfunction
function TalentChoiceSustainReset takes nothing returns nothing
    call BlzSetUnitMaxHP(udg_Talent__Unit, BlzGetUnitMaxHP(udg_Talent__Unit) - udg_TalentChoiceInt1[udg_Talent__Choice])
    call BlzSetUnitMaxMana(udg_Talent__Unit, BlzGetUnitMaxMana(udg_Talent__Unit) - udg_TalentChoiceInt2[udg_Talent__Choice])
    call BlzSetUnitArmor(udg_Talent__Unit, BlzGetUnitArmor(udg_Talent__Unit) - udg_TalentChoiceReal1[udg_Talent__Choice])
endfunction
function TalentChoiceImproveWeaponLearn takes nothing returns nothing
    //Weapon, Damage, Cooldown
    call BlzSetUnitAttackCooldown(udg_Talent__Unit, BlzGetUnitAttackCooldown(udg_Talent__Unit, udg_TalentChoiceInt1[udg_Talent__Choice]) + udg_TalentChoiceReal1[udg_Talent__Choice], udg_TalentChoiceInt1[udg_Talent__Choice])
    call BlzSetUnitBaseDamage(udg_Talent__Unit, BlzGetUnitBaseDamage(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice]) + udg_TalentChoiceInt2[udg_Talent__Choice], udg_TalentChoiceInt1[udg_Talent__Choice])
endfunction
function TalentChoiceImproveWeaponReset takes nothing returns nothing
    //Weapon, Damage, Cooldown
    call BlzSetUnitAttackCooldown(udg_Talent__Unit, BlzGetUnitAttackCooldown(udg_Talent__Unit, udg_TalentChoiceInt1[udg_Talent__Choice]) - udg_TalentChoiceReal1[udg_Talent__Choice], udg_TalentChoiceInt1[udg_Talent__Choice])
    call BlzSetUnitBaseDamage(udg_Talent__Unit, BlzGetUnitBaseDamage(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice]) - udg_TalentChoiceInt2[udg_Talent__Choice], udg_TalentChoiceInt1[udg_Talent__Choice])
endfunction
function TalentChoiceImproveUnitSpellLearn takes nothing returns nothing
    call BlzSetUnitAbilityManaCost(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0, BlzGetUnitAbilityManaCost(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0) + udg_TalentChoiceInt2[udg_Talent__Choice])
    call BlzSetUnitAbilityCooldown(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0, BlzGetUnitAbilityCooldown(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0) + udg_TalentChoiceReal1[udg_Talent__Choice])
endfunction
function TalentChoiceImproveUnitSpellReset takes nothing returns nothing
    call BlzSetUnitAbilityManaCost(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0, BlzGetUnitAbilityManaCost(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0) - udg_TalentChoiceInt2[udg_Talent__Choice])
    call BlzSetUnitAbilityCooldown(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0, BlzGetUnitAbilityCooldown(udg_Talent__Unit,udg_TalentChoiceInt1[udg_Talent__Choice], 0) - udg_TalentChoiceReal1[udg_Talent__Choice])
endfunction

function TalentChoiceCreateStats takes integer strAdd, integer agiAdd, integer intAdd returns integer
    call TalentChoiceCreateTriggerEx(udg_TalentPreMadeChoiceTrigger[0],udg_TalentPreMadeChoiceTrigger[1])
    set udg_TalentChoiceInt1[udg_TalentChoiceLast] = strAdd
    set udg_TalentChoiceInt2[udg_TalentChoiceLast] = agiAdd
    set udg_TalentChoiceInt3[udg_TalentChoiceLast] = intAdd
    set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentStrings[28]
    call TalentChoiceAddTextInt(udg_TalentStrings[29],udg_TalentChoiceInt1[udg_TalentChoiceLast])
    call TalentChoiceAddTextInt(udg_TalentStrings[30],udg_TalentChoiceInt2[udg_TalentChoiceLast])
    call TalentChoiceAddTextInt(udg_TalentStrings[31],udg_TalentChoiceInt3[udg_TalentChoiceLast])
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateStr takes integer add returns integer
    return TalentChoiceCreateStats(add,0,0)
endfunction
function TalentChoiceCreateAgi takes integer add returns integer
    return TalentChoiceCreateStats(0,add,0)
endfunction
function TalentChoiceCreateInt takes integer add returns integer
    return TalentChoiceCreateStats(0,0,add)
endfunction
function TalentChoiceCreateSustain takes integer lifeAdd, integer manaAdd, real armorAdd returns integer
    call TalentChoiceCreateTriggerEx(udg_TalentPreMadeChoiceTrigger[2],udg_TalentPreMadeChoiceTrigger[3])
    set udg_TalentChoiceInt1[udg_TalentChoiceLast] = lifeAdd
    set udg_TalentChoiceInt2[udg_TalentChoiceLast] = manaAdd
    set udg_TalentChoiceReal1[udg_TalentChoiceLast] = armorAdd
   
    set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentStrings[20]
    call TalentChoiceAddTextInt(udg_TalentStrings[21],udg_TalentChoiceInt1[udg_TalentChoiceLast])
    call TalentChoiceAddTextInt(udg_TalentStrings[22],udg_TalentChoiceInt2[udg_TalentChoiceLast])
    call TalentChoiceAddTextReal(udg_TalentStrings[23],udg_TalentChoiceReal1[udg_TalentChoiceLast])
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateImproveWeapon takes integer weaponIndex, integer damageAdd, real cooldownAdd returns integer
    call TalentChoiceCreateTriggerEx(udg_TalentPreMadeChoiceTrigger[4],udg_TalentPreMadeChoiceTrigger[5])
    set udg_TalentChoiceInt1[udg_TalentChoiceLast] = weaponIndex
    set udg_TalentChoiceInt2[udg_TalentChoiceLast] = damageAdd
    set udg_TalentChoiceReal1[udg_TalentChoiceLast] = cooldownAdd
    set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentStrings[15]+ I2S(udg_TalentChoiceInt1[udg_TalentChoiceLast])
    call TalentChoiceAddTextInt(udg_TalentStrings[16],udg_TalentChoiceInt2[udg_TalentChoiceLast])
    call TalentChoiceAddTextReal(udg_TalentStrings[17],udg_TalentChoiceReal1[udg_TalentChoiceLast])
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateImproveSpell takes integer spell, integer manaCostAdd, real cooldownAdd returns integer
    call TalentChoiceCreateTriggerEx(udg_TalentPreMadeChoiceTrigger[6],udg_TalentPreMadeChoiceTrigger[7])
    set udg_TalentChoiceInt1[udg_TalentChoiceLast] = spell
    set udg_TalentChoiceInt2[udg_TalentChoiceLast] = manaCostAdd
    set udg_TalentChoiceReal1[udg_TalentChoiceLast] = cooldownAdd
    set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentStrings[9] + GetObjectName(spell)
    call TalentChoiceAddTextInt(udg_TalentStrings[10],udg_TalentChoiceInt2[udg_TalentChoiceLast])
    call TalentChoiceAddTextReal(udg_TalentStrings[11],udg_TalentChoiceReal1[udg_TalentChoiceLast])
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateAddSpell takes integer spell, boolean useButtonInfos returns integer
    call TalentChoiceCreateEx(null,null)
    call TalentChoiceAddAbility(udg_TalentChoiceLast, spell)
    if useButtonInfos then
        set udg_TalentChoiceText[udg_TalentChoiceLast] = BlzGetAbilityExtendedTooltip(spell,0)
        set udg_TalentChoiceHead[udg_TalentChoiceLast] = BlzGetAbilityTooltip(spell,0)
        set udg_TalentChoiceIcon[udg_TalentChoiceLast] = BlzGetAbilityIcon(spell)
    endif
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateReplaceSpell takes integer oldSpell, integer newSpell returns integer
    call TalentChoiceCreateEx(null,null)
    call TalentChoiceReplaceAbility(udg_TalentChoiceLast, oldSpell, newSpell)
    return udg_TalentChoiceLast
endfunction
function TalentChoiceCreateAddSpells takes integer spell1, integer spell2, integer spell3 returns integer
    call TalentChoiceCreateEx(null,null)
    call TalentChoiceAddAbility(udg_TalentChoiceLast, spell1)
    set udg_TalentChoiceText[udg_TalentChoiceLast] = udg_TalentStrings[1]
    call TalentChoiceAddTextIntAsObject(udg_TalentStrings[2],spell1)
    if spell2 != 0 then
        call TalentChoiceAddAbility(udg_TalentChoiceLast, spell2)
        call TalentChoiceAddTextIntAsObject(udg_TalentStrings[3],spell2)
    endif
    if spell3 != 0 then
        call TalentChoiceAddAbility(udg_TalentChoiceLast, spell3)
        call TalentChoiceAddTextIntAsObject(udg_TalentStrings[3],spell3)
    endif
    return udg_TalentChoiceLast
endfunction
//===========================================================================
function InitTrig_TalentPreMadeChoice takes nothing returns nothing
    set udg_TalentPreMadeChoiceTrigger[0] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[1] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[2] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[3] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[4] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[5] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[6] = CreateTrigger()
    set udg_TalentPreMadeChoiceTrigger[7] = CreateTrigger()
   
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[0], function TalentChoiceStatsLearn)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[1], function TalentChoiceStatsReset)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[2], function TalentChoiceSustainLearn)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[3], function TalentChoiceSustainReset)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[4], function TalentChoiceImproveWeaponLearn)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[5], function TalentChoiceImproveWeaponReset)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[6], function TalentChoiceImproveUnitSpellLearn)
    call TriggerAddAction(udg_TalentPreMadeChoiceTrigger[7], function TalentChoiceImproveUnitSpellReset)

endfunction
 
//Talent GUI 1.03
//by Tasyen
//===========================================================================
// Makes Talent Registering useable using GUI only.
//===========================================================================
function TalentGuiCreateChoice takes nothing returns nothing
    local integer heroTier = TalentHeroGetTier(udg_TalentGUI_UnitType, udg_TalentGUI_Level)
    if heroTier == 0 then
        set heroTier = TalentHeroTierCreate(udg_TalentGUI_UnitType, udg_TalentGUI_Level)
    endif
    call TalentTierAddChoice(heroTier, TalentChoiceCreateAllTrigger(udg_TalentGUI_ChoiceHead,udg_TalentGUI_ChoiceText,udg_TalentGUI_ChoiceIcon,udg_TalentGUI_OnLearn,udg_TalentGUI_OnReset))
    set udg_TalentGUI_OnReset = null
    set udg_TalentGUI_OnLearn = null
    if udg_TalentGUI_Spell != 0 and udg_TalentGUI_ReplacedSpell != 0 then
        call TalentChoiceReplaceAbilityEx(udg_TalentGUI_ReplacedSpell,udg_TalentGUI_Spell)
        set udg_TalentGUI_Spell = 0
        set udg_TalentGUI_ReplacedSpell = 0
    elseif udg_TalentGUI_Spell != 0 then
        call TalentChoiceAddAbilityEx(udg_TalentGUI_Spell)
        set udg_TalentGUI_Spell = 0
    endif
endfunction
function TalentGuiAddSpell takes nothing returns nothing
    call TalentChoiceAddAbilityEx(udg_TalentGUI_Spell)
endfunction
function TalentGuiReplaceSpell takes nothing returns nothing
    call TalentChoiceReplaceAbilityEx(udg_TalentGUI_ReplacedSpell,udg_TalentGUI_Spell)
endfunction
function TalentGuiFinalize takes nothing returns nothing
    call TalentHeroSetFinalTier(udg_TalentGUI_UnitType, udg_TalentGUI_Level)
endfunction
function TalentGuiCopy takes nothing returns nothing
    call TalentHeroSetCopy(udg_TalentGUI_UnitType, udg_TalentGUI_UnitTypeCopied)
endfunction
//===========================================================================
function InitTrig_TalentGUI takes nothing returns nothing
    set gg_trg_TalentGUI = CreateTrigger(  )
    set udg_TalentGUICreateChoice = CreateTrigger()
    set udg_TalentGUIAddSpell = CreateTrigger()
    set udg_TalentGUIReplaceSpell = CreateTrigger()
    set udg_TalentGUICopyUnit = CreateTrigger()
    call TriggerAddAction(udg_TalentGUICreateChoice, function TalentGuiCreateChoice)
    call TriggerAddAction(udg_TalentGUIAddSpell, function TalentGuiAddSpell)
    call TriggerAddAction(udg_TalentGUIReplaceSpell, function TalentGuiReplaceSpell)
    call TriggerAddAction(udg_TalentGUICopyUnit, function TalentGuiCopy)
    call TriggerAddAction(gg_trg_TalentGUI, function TalentGuiFinalize)
   
endfunction

 
function TalentStr takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_STR, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
endfunction
function TalentStrReset takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_STR, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
endfunction
function TalentAgi takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_AGI, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
endfunction
function TalentAgiReset takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_AGI, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
endfunction
function TalentInt takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_INT, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
endfunction
function TalentIntReset takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_INT, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
endfunction
function TalentKroneOfKing takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_INT, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
    call ModifyHeroStat( bj_HEROSTAT_STR, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
    call ModifyHeroStat( bj_HEROSTAT_AGI, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, 6 )
endfunction
function TalentKroneOfKingReset takes nothing returns nothing
    call ModifyHeroStat( bj_HEROSTAT_INT, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
    call ModifyHeroStat( bj_HEROSTAT_STR, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
    call ModifyHeroStat( bj_HEROSTAT_AGI, udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -6 )
endfunction
function TalentMithrilBlade takes nothing returns nothing
    call BlzSetUnitBaseDamage(udg_Talent__Unit, BlzGetUnitBaseDamage(udg_Talent__Unit, 0) + 20, 0)
endfunction
function TalentMithrilBladeReset takes nothing returns nothing
    call BlzSetUnitBaseDamage(udg_Talent__Unit, BlzGetUnitBaseDamage(udg_Talent__Unit, 0) - 20, 0)
endfunction
function TalentMithrilArmor takes nothing returns nothing
    call BlzSetUnitArmor(udg_Talent__Unit, BlzGetUnitArmor(udg_Talent__Unit) + 10)
endfunction
function TalentMithrilArmorReset takes nothing returns nothing
    call BlzSetUnitArmor(udg_Talent__Unit, BlzGetUnitArmor(udg_Talent__Unit) - 10)
endfunction
function TalentStatChange takes nothing returns nothing
    call ModifyHeroStat( udg_StatType[udg_Talent__Choice], udg_Talent__Unit, bj_MODIFYMETHOD_ADD, udg_StatPower[udg_Talent__Choice] )
endfunction
function TalentStatChangeReset takes nothing returns nothing
    call ModifyHeroStat( udg_StatType[udg_Talent__Choice], udg_Talent__Unit, bj_MODIFYMETHOD_ADD, -udg_StatPower[udg_Talent__Choice] )
endfunction
//Example for using Talent by Tasyen.
function TalentPaladin takes nothing returns nothing
    //Which HeroType is this; Custom Paladin
    local integer heroTypeId = 'H001'
    local integer choice
    local integer abilityId
   
    call TalentHeroSetFinalTier(heroTypeId, 8)  //Mark Level 8 as last choice
    //HeroTypeId gains at Level 0: create a new Tier
    call TalentHeroTierCreate(heroTypeId, 0)

    //Create a new Choice and add it to the last Created Tier
    set choice = TalentChoiceCreateEx( function TalentStr , function TalentStrReset)    //activade function TalentStr when Picking this Talent
    set udg_TalentChoiceText[choice] = "Gain 6 Str"
    set udg_TalentChoiceHead[choice] = "Handschuhe der Kraft"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower.blp"

    set choice = TalentChoiceCreateEx( function TalentAgi , function TalentAgiReset)
    set udg_TalentChoiceText[choice] = "Gain 6 Agi"
    set udg_TalentChoiceHead[choice] = "Schuhe der Beweglichkeit"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility.blp"

    set choice = TalentChoiceCreateEx( function TalentInt , function TalentIntReset)
    set udg_TalentChoiceText[choice] = "Gain 6 Int"
    set udg_TalentChoiceHead[choice] = "Robe der Weißen"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNRobeOfTheMagi.blp"

    //Level 2
    call TalentHeroTierCreate(heroTypeId, 2)
 
    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'Awfb'
    call TalentChoiceAddAbility(choice, abilityId) //Skill gained when picking this choice
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)

    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'AHhb'
    call TalentChoiceAddAbility(choice, abilityId)
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)


    //Level 4
    call TalentHeroTierCreate(heroTypeId, 4)

    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'Ainf'
    call TalentChoiceAddAbility(choice, abilityId)
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)

    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'Afbt'
    call TalentChoiceAddAbility(choice, abilityId)
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)

    //Create Own Variabes and attach them

    set choice = TalentChoiceCreateEx( function TalentStatChange , function TalentStatChangeReset)  //activade function TalentStr when Picking this Talent
    set udg_TalentChoiceText[choice] = "Gain 8 Str"
    set udg_TalentChoiceHead[choice] = "Gürtel der Gigantenkraft"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNBelt.blp"
    set udg_StatType[choice] = bj_HEROSTAT_STR  //choice is the index of the last create Choice, so attach custom Data to it.
    set udg_StatPower[choice] = 8
   
    set choice = TalentChoiceCreateEx( function TalentStatChange, function TalentStatChangeReset)
    set udg_TalentChoiceText[choice] = "Gain 8 Int"
    set udg_TalentChoiceHead[choice] = "Robe der Weißen"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNRobeOfTheMagi.blp"
    set udg_StatType[choice] = bj_HEROSTAT_INT
    set udg_StatPower[choice] = 8


    //Level 6
    call TalentHeroTierCreate(heroTypeId, 6)

    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'AHre'
    call TalentChoiceAddAbility(choice, abilityId)
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)

    set choice = TalentChoiceCreateEx(null, null)
    set abilityId = 'AHav'
    call TalentChoiceAddAbility(choice, abilityId)
    set udg_TalentChoiceText[choice] = BlzGetAbilityExtendedTooltip(abilityId,1)
    set udg_TalentChoiceHead[choice] = BlzGetAbilityTooltip(abilityId,1)
    set udg_TalentChoiceIcon[choice] = BlzGetAbilityIcon(abilityId)

    //Level 8
    call TalentHeroTierCreate(heroTypeId, 8)

    set choice = TalentChoiceCreateEx(function TalentKroneOfKing, function TalentKroneOfKingReset)
    set udg_TalentChoiceText[choice] = "Gain + 6 to all stats"
    set udg_TalentChoiceHead[choice] = "Krone des Königs"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHelmutPurple.blp"

    set choice = TalentChoiceCreateEx(function TalentMithrilBlade, function TalentMithrilBladeReset)
    set udg_TalentChoiceText[choice] = "Gain 20 ATK"
    set udg_TalentChoiceHead[choice] = "Mithril Blade"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNArcaniteMelee.blp"

    set choice = TalentChoiceCreateEx(function TalentMithrilArmor, function TalentMithrilArmorReset)
    set udg_TalentChoiceText[choice] = "Gain 10 Armor"
    set udg_TalentChoiceHead[choice] = "Mithril Armor"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpThree.blp"

endfunction

//===========================================================================
function InitTrig_Talent_Paladin takes nothing returns nothing
    set gg_trg_Talent_Paladin = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_Paladin, function TalentPaladin )
endfunction


 
//Example for using Talent by Tasyen.
function Talent_Dagren takes nothing returns nothing
    call TalentHeroSetCopy('H003', 'H001')  //'H003' uses the same talents as 'H001'
    call TalentHeroSetCopy('H004', 'H002') //'H004' uses the same talents as 'H002'
    //You also shoud copy when an unit can morph
endfunction

//===========================================================================
function InitTrig_Talent_Copy_Palaidn takes nothing returns nothing
    set gg_trg_Talent_Copy_Palaidn = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_Copy_Palaidn, function Talent_Dagren )
endfunction

 

//Example for using Talent by Tasyen.
function TalentBloodMage takes nothing returns nothing
    local integer heroTypeId = 'H005'   //Custom BloodMage
    local integer choice
    local integer abilityId

    call TalentHeroSetFinalTier(heroTypeId, 10)     //Mark Level 10 as last choice, after the heroe picks it, the selection skills are removed.

    call TalentHeroTierCreate(heroTypeId, 0)

    set choice = TalentChoiceCreateAddSpells('AHfs','ANbf','ANfb') //Create a choice adding this 3 spells and add the choice to the last created Tier
    set udg_TalentChoiceText[choice] = "Learn Firebolt, Breath of Fire and Flamestrike"
    set udg_TalentChoiceHead[choice] = "Fire Magic"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNFire.blp"
   
    set choice = TalentChoiceCreateAddSpells('ANfl','AOcl','ANmo')
    //set udg_TalentChoiceText[choice] = "Learn Chaing Lighnting, Moonsoun and Foked Lightning"
    set udg_TalentChoiceHead[choice] = "Lightning Magic"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNMonsoon.blp"

    //LEVEL 5
    call TalentHeroTierCreate(heroTypeId, 5)

    set choice = TalentChoiceCreateStats(6, 3, 3)
    set udg_TalentChoiceHead[choice] = "Magic Power: Str"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHelmOfValor.blp"

    set choice = TalentChoiceCreateStats(3, 6, 3)
    set udg_TalentChoiceHead[choice] = "Magic Power: AGI"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHoodOfCunning.blp"

    set choice = TalentChoiceCreateStats(3, 3, 6)
    set udg_TalentChoiceHead[choice] = "Magic Power: Int"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNPipeOfInsight.blp"

   
    //Level 10
    call TalentHeroTierCreate(heroTypeId, 10)

    call TalentChoiceCreateAddSpell('AHpx',true)
    call TalentChoiceCreateAddSpell('AUin',true)


endfunction

//===========================================================================
function InitTrig_Talent_BloodMag takes nothing returns nothing
    set gg_trg_Talent_BloodMag = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_BloodMag, function TalentBloodMage )
endfunction


 
//Example for using Talent by Tasyen.
function TalentUther takes nothing returns nothing
    local integer choice


    //Which HeroType is this; Custom Uther
    local integer heroTypeId = 'H002'
   
    call TalentHeroSetFinalTier(heroTypeId, 4)

    call TalentHeroTierCreate(heroTypeId, 0)

    set choice = TalentChoiceCreateStr(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Str"
    set udg_TalentChoiceHead[choice] = "Handschuhe der Kraft"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower.blp"

    set choice = TalentChoiceCreateAgi(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Agi"
    set udg_TalentChoiceHead[choice] = "Schuhe der Beweglichkeit"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility.blp"

    set choice = TalentChoiceCreateInt(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Int"
    set udg_TalentChoiceHead[choice] = "Robe der Weißen"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNRobeOfTheMagi.blp"

    //Level 1
    call TalentHeroTierCreate(heroTypeId, 1)
 
    call TalentChoiceCreateAddSpell('Awfb',true)
    call TalentChoiceCreateAddSpell('AHhb',true)

    //Level 2
    call TalentHeroTierCreate(heroTypeId, 2)

    call TalentChoiceCreateAddSpell('Ainf',true)
    call TalentChoiceCreateAddSpell('Afbt',true)

    //Create Own Variabes and attach them

    set choice = TalentChoiceCreateStr(8)
    set udg_TalentChoiceText[choice] = "Gain 8 Str"
    set udg_TalentChoiceHead[choice] = "Gürtel der Gigantenkraft"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNBelt.blp"
   
    set choice = TalentChoiceCreateInt(8)
    set udg_TalentChoiceText[choice] = "Gain 8 Int"
    set udg_TalentChoiceHead[choice] = "Robe der Weißen"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNRobeOfTheMagi.blp"


    call TalentChoiceCreateAddSpell('ACam',true)
    call TalentChoiceCreateAddSpell('ACmp',true)


    //Level 3
    call TalentHeroTierCreate(heroTypeId, 3)

    call TalentChoiceCreateAddSpell('AHre',true)
    call TalentChoiceCreateAddSpell('AHav',true)

    //Level 4
    call TalentHeroTierCreate(heroTypeId, 4)

    set choice = TalentChoiceCreateStats(6, 6, 6)
    set udg_TalentChoiceText[choice] = "Gain + 6 to all stats"
    set udg_TalentChoiceHead[choice] = "Krone des Königs"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHelmutPurple.blp"

    set choice = TalentChoiceCreateImproveWeapon(0, 20, 0)
    set udg_TalentChoiceText[choice] = "Gain 20 ATK"
    set udg_TalentChoiceHead[choice] = "Mithril Blade"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNArcaniteMelee.blp"

    set choice = TalentChoiceCreateSustain(0, 0, 10)
    set udg_TalentChoiceText[choice] = "Gain 10 Armor"
    set udg_TalentChoiceHead[choice] = "Mithril Armor"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpThree.blp"
 
endfunction

//===========================================================================
function InitTrig_Talent_Uther takes nothing returns nothing
    set gg_trg_Talent_Uther = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_Uther, function TalentUther )
endfunction

 
//Example for using Talent by Tasyen.
function TalentsPitLord takes nothing returns nothing
    local integer choice
    local integer LoopA = 20
   
    local integer heroTypeId = 'N000'   //Custom PitLord
    local integer tier = TalentTierCreate() //Create a Tier and remember it

    call TalentHeroSetFinalTier(heroTypeId, 20)
   
    set choice = TalentChoiceCreateStr(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Str"
    set udg_TalentChoiceHead[choice] = "Handschuhe der Kraft"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNGauntletsOfOgrePower.blp"

    set choice = TalentChoiceCreateAgi(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Agi"
    set udg_TalentChoiceHead[choice] = "Schuhe der Beweglichkeit"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNSlippersOfAgility.blp"

    set choice = TalentChoiceCreateInt(6)
    set udg_TalentChoiceText[choice] = "Gain 6 Int"
    set udg_TalentChoiceHead[choice] = "Robe der Weißen"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNRobeOfTheMagi.blp" 

    loop    //Add tier for Level 20 to 1 (count down), uses always the same tier and choices
        call TalentHeroSetTier(heroTypeId, LoopA, tier)
        set LoopA = LoopA - 1
        exitwhen LoopA == 0
    endloop
endfunction

//===========================================================================
function InitTrig_Talent_GrubenLord takes nothing returns nothing
    set gg_trg_Talent_GrubenLord = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_GrubenLord, function TalentsPitLord )
endfunction

 
//Example for using Talent by Tasyen.
function TalentFootmen takes nothing returns nothing
    local integer choice

    //Which HeroType is this; Footmen
    local integer heroTypeId = 'hfoo'
    call TalentHeroSetFinalTier(heroTypeId, 1)

    call TalentHeroTierCreate(heroTypeId, 1)

    //Create a new Choice and add it to the last Created Tier
    set choice = TalentChoiceCreateImproveWeapon(0, 6, 0)
    set udg_TalentChoiceHead[choice] = "Deadly Footman"
    set udg_TalentChoiceText[choice] = "Increases Base AttackDamage by 6"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNSteelMelee.blp"

    set choice = TalentChoiceCreateSustain(0, 0, 4)
    set udg_TalentChoiceHead[choice] = "Tanky Footman"
    set udg_TalentChoiceText[choice] = "Increases Armor by 4"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHumanArmorUpOne.blp"

endfunction

//===========================================================================
function InitTrig_Talent_FootMen takes nothing returns nothing
    set gg_trg_Talent_FootMen = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_FootMen, function TalentFootmen )
endfunction

 
//Example for using Talent by Tasyen.
function TalentShadowPriest takes nothing returns nothing
    local integer choice

    //Which HeroType is this; Wald-Troll-Schattenpriester
    local integer heroTypeId = 'nfsp'
    call TalentHeroSetFinalTier(heroTypeId, 1)

    call TalentHeroTierCreate(heroTypeId, 1)

    set choice = TalentChoiceCreateReplaceSpell('Anh1','Anh2')
    set udg_TalentChoiceHead[choice] = "More Heal"
    set udg_TalentChoiceText[choice] = "Increases Heal by 13"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHealOn.blp"

    set choice = TalentChoiceCreateImproveSpell('Anh1', -2, -0.2)
    set udg_TalentChoiceHead[choice] = "Cheaper Heal"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNHealOn.blp"

    set choice = TalentChoiceCreateSustain(200, 100, 1)
    set udg_TalentChoiceHead[choice] = "Sustain Healer"
    set udg_TalentChoiceIcon[choice] = "ReplaceableTextures\\CommandButtons\\BTNForestTrollShadowPriest.blp"

endfunction

//===========================================================================
function InitTrig_Talent_ShadowPriest takes nothing returns nothing
    set gg_trg_Talent_ShadowPriest = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Talent_ShadowPriest, function TalentShadowPriest )
endfunction

 
Talent MK Axe Learn
  Events
  Conditions
  Actions
    Unit - Set Base Damage of Talent__Unit to ((Base Damage of Talent__Unit for weapon index 1) + 20) for weapon index: 0
Talent MK Axe Reset
  Events
  Conditions
  Actions
    Unit - Set Base Damage of Talent__Unit to ((Base Damage of Talent__Unit for weapon index 0) - 20) for weapon index: 0
Talent MK Helm Learn
  Events
  Conditions
  Actions
    Hero - Modify Strength of Talent__Unit: Add 6.
    Hero - Modify Agility of Talent__Unit: Add 6.
Talent MK Helm Reset
  Events
  Conditions
  Actions
    Hero - Modify Strength of Talent__Unit: Subtract 6.
    Hero - Modify Agility of Talent__Unit: Subtract 6.
Talent MK Armor Learn
  Events
  Conditions
  Actions
    Unit - Set Max HP of Talent__Unit to ((Max HP of Talent__Unit) + 500)
    Unit - Set life of Talent__Unit to ((Life of Talent__Unit) + 500.00)
Talent MK Armor Reset
  Events
  Conditions
  Actions
    Unit - Set Max HP of Talent__Unit to ((Max HP of Talent__Unit) - 500)
Talent MK Manastone Learn
  Events
  Conditions
  Actions
    Unit - Set Max Mana of Talent__Unit to ((Max Mana of Talent__Unit) + 250)
    Unit - Set mana of Talent__Unit to ((Mana of Talent__Unit) + 250.00)
Talent MK Manastone Reset
  Events
  Conditions
  Actions
    Unit - Set Max Mana of Talent__Unit to ((Max Mana of Talent__Unit) - 250)
Talent MK Event
  Events
    Game - Talent__Event becomes Equal to 1.00
  Conditions
    TalentGUI_UnitTypeCopied Equal to Mountain King
    Or - Any (Conditions) are true
      Conditions
        (Unit-type of Talent__Unit) Equal to Mountain King
        (Unit-type of Talent__Unit) Equal to Bergkönig - Clone
  Actions
    -------- Only MountainKing and Muradin are using this Event Trigger --------
    -------- ---- --------
    -------- ---- --------
    -------- Lets get the Level of the Choice done --------
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 1
      Then - Actions
        -------- This Choice is From Level 1 --------
        -------- It is either Axe (Button 1) or Pulverice (Button2) --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            -------- "Axe" was picked --------
            Unit - Set Base Damage of Talent__Unit to ((Base Damage of Talent__Unit for weapon index 0) + 20) for weapon index: 0
          Else - Actions
        -------- Button 2 (Choice 2) does not need an Event Handling cause it auto adds an ability --------
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 4
      Then - Actions
        -------- This Choice is From Level 4 --------
        -------- Helm or Healing Potion --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            -------- "Helm" was picked --------
            Hero - Modify Strength of Talent__Unit: Add 6.
            Hero - Modify Agility of Talent__Unit: Add 6.
          Else - Actions
        -------- "Healing Potion" is an auto added skill --------
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 7
      Then - Actions
        -------- This Choice is From Level 7 --------
        -------- Armor, Manastone, Flamestrike --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            Unit - Set Max HP of Talent__Unit to ((Max HP of Talent__Unit) + 500)
            Unit - Set life of Talent__Unit to ((Life of Talent__Unit) + 500.00)
          Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 2
          Then - Actions
            Unit - Set Max Mana of Talent__Unit to ((Max Mana of Talent__Unit) + 250)
            Unit - Set mana of Talent__Unit to ((Mana of Talent__Unit) + 250.00)
          Else - Actions
      Else - Actions
Talent MK Event Reset
  Events
    Game - Talent__Event becomes Equal to -1.00
  Conditions
    Or - Any (Conditions) are true
      Conditions
        (Unit-type of Talent__Unit) Equal to Mountain King
        (Unit-type of Talent__Unit) Equal to Bergkönig - Clone
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 1
      Then - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            Unit - Set Base Damage of Talent__Unit to ((Base Damage of Talent__Unit for weapon index 0) - 20) for weapon index: 0
          Else - Actions
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 4
      Then - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            Hero - Modify Strength of Talent__Unit: Subtract 6.
            Hero - Modify Agility of Talent__Unit: Subtract 6.
          Else - Actions
      Else - Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        Talent__Level Equal to 7
      Then - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 1
          Then - Actions
            Unit - Set Max HP of Talent__Unit to ((Max HP of Talent__Unit) - 500)
          Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            Talent__Button Equal to 2
          Then - Actions
            Unit - Set Max Mana of Talent__Unit to ((Max Mana of Talent__Unit) - 250)
          Else - Actions
      Else - Actions
Talent MountainKing Init Commented
  Events
    Map initialization
  Conditions
  Actions
    -------- Who uses this? --------
    Set VariableSet TalentGUI_UnitType = Mountain King
    -------- ---- --------
    -------- ---- --------
    -------- For which Level create choices? --------
    Set VariableSet TalentGUI_Level = 1
    -------- CreateChoices will use that Level until changed --------
    -------- ---- --------
    -------- Setup shown Text, it will be used in the next created Choice --------
    Set VariableSet TalentGUI_ChoiceHead = Axe
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNOrcMeleeUpOne.blp
    Set VariableSet TalentGUI_ChoiceText = Gain 20 Base-ATK
    -------- Create a new Choice using Head,Icon,Text Spell and ReplaceSpell --------
    -------- The new Choice is also added to the last Created Tier --------
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- Add 1 further Choice to the last created Tier --------
    -------- ---- --------
    -------- If you set TalentGUI_Spell, this Choice will add/improve also an Ability. --------
    -------- TalentGUI_ReplacedSpell will be lost/Reduced when picking that choice. --------
    Set VariableSet TalentGUI_Spell = Pulverize (Neutral Hostile)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    -------- ---- --------
    -------- Level 4 --------
    Set VariableSet TalentGUI_Level = 4
    -------- ---- --------
    Set VariableSet TalentGUI_ChoiceHead = Helm
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNHelmOfValor.blp
    Set VariableSet TalentGUI_ChoiceText = +6 STR|n+6 AGI
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    Set VariableSet TalentGUI_Spell = Heiltrank (Lesser)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    -------- ---- --------
    -------- Create for MountainKing a Tier at Level 7 --------
    Set VariableSet TalentGUI_Level = 7
    Set VariableSet TalentGUI_ChoiceHead = Armor
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNArmorGolem.blp
    Set VariableSet TalentGUI_ChoiceText = +500 Max Life
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    Set VariableSet TalentGUI_ChoiceHead = ManaStone
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNPendantOfMana.blp
    Set VariableSet TalentGUI_ChoiceText = +250 Max Mana
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    Set VariableSet TalentGUI_Spell = Flame Strike
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 3)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- CreateChoice resets TalentGUI_Spell & TalentGUI_ReplacedSpell --------
    Set VariableSet TalentGUI_Spell = Flame Strike
    -------- One can run : TalentGUIReplaceSpell or TalentGUIAddSpell, after creating a choice to add addtional abilities --------
    -------- Adding multiple Times the same spell wil increase it if "function TalentIncreaseByDoubleLearning" returns true, default --------
    -------- AddSpell/ReplaceSpell keeps TalentGUI_Spell & TalentGUI_ReplacedSpell --------
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    -------- Talent init for this HeroType is complete --------
    Trigger - Run TalentGUI <gen> (ignoring conditions)
Talent Muradin Copies MoutainKing
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet TalentGUI_UnitType = Bergkönig - Clone
    Set VariableSet TalentGUI_UnitTypeCopied = Mountain King
    Trigger - Run TalentGUICopyUnit (ignoring conditions)
Talent MountainKing Init
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet TalentGUI_UnitType = Mountain King
    Set VariableSet TalentGUI_Level = 1
    Set VariableSet TalentGUI_ChoiceHead = Axe
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNOrcMeleeUpOne.blp
    Set VariableSet TalentGUI_ChoiceText = Gain 20 Base-ATK
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Pulverize (Neutral Hostile)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Level = 4
    Set VariableSet TalentGUI_ChoiceHead = Helm
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNHelmOfValor.blp
    Set VariableSet TalentGUI_ChoiceText = +6 STR|n+6 AGI
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Heiltrank (Lesser)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Level = 7
    Set VariableSet TalentGUI_ChoiceHead = Armor
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNArmorGolem.blp
    Set VariableSet TalentGUI_ChoiceText = +500 Max Life
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_ChoiceHead = ManaStone
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNPendantOfMana.blp
    Set VariableSet TalentGUI_ChoiceText = +250 Max Mana
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Flame Strike
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 3)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    -------- ---- --------
    Trigger - Run TalentGUI <gen> (ignoring conditions)
You should disable the Talent MK Event & Talent MK Event Reset when using this.

Kinda don't know if this code binding is good in GUI.
One ends up with dozens of Triggers which will float the trigger picking.
Talent MountainKing Init Predefined
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet TalentGUI_UnitType = Mountain King
    Set VariableSet TalentGUI_Level = 1
    Set VariableSet TalentGUI_ChoiceHead = Axe
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNOrcMeleeUpOne.blp
    Set VariableSet TalentGUI_ChoiceText = Gain 20 Base-ATK
    Set VariableSet TalentGUI_OnLearn = Talent_MK_Axe_Learn <gen>
    Set VariableSet TalentGUI_OnReset = Talent_MK_Axe_Reset <gen>
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Pulverize (Neutral Hostile)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Level = 4
    Set VariableSet TalentGUI_ChoiceHead = Helm
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNHelmOfValor.blp
    Set VariableSet TalentGUI_ChoiceText = +6 STR|n+6 AGI
    Set VariableSet TalentGUI_OnLearn = Talent_MK_Helm_Learn <gen>
    Set VariableSet TalentGUI_OnReset = Talent_MK_Helm_Reset <gen>
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Heiltrank (Lesser)
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 1)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Level = 7
    Set VariableSet TalentGUI_ChoiceHead = Armor
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNArmorGolem.blp
    Set VariableSet TalentGUI_ChoiceText = +500 Max Life
    Set VariableSet TalentGUI_OnLearn = Talent_MK_Armor_Learn <gen>
    Set VariableSet TalentGUI_OnReset = Talent_MK_Armor_Reset <gen>
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- Attach Data to the choice --------
    Set VariableSet StatPower[TalentChoiceLast] = 500
    -------- ---- --------
    Set VariableSet TalentGUI_ChoiceHead = ManaStone
    Set VariableSet TalentGUI_ChoiceIcon = ReplaceableTextures\CommandButtons\BTNPendantOfMana.blp
    Set VariableSet TalentGUI_ChoiceText = +250 Max Mana
    Set VariableSet TalentGUI_OnLearn = Talent_MK_Manastone_Learn <gen>
    Set VariableSet TalentGUI_OnReset = Talent_MK_Manastone_Reset <gen>
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    -------- ---- --------
    Set VariableSet TalentGUI_Spell = Flame Strike
    Set VariableSet TalentGUI_ChoiceHead = (Name of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceIcon = (Icon of TalentGUI_Spell)
    Set VariableSet TalentGUI_ChoiceText = (Extended Tooltip of TalentGUI_Spell for level 3)
    Trigger - Run TalentGUICreateChoice (ignoring conditions)
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    Trigger - Run TalentGUIAddSpell (ignoring conditions)
    -------- ---- --------
    Trigger - Run TalentGUI <gen> (ignoring conditions)
Gain TalentBook
  Events
    Unit - A unit Acquires an item
  Conditions
    (Item-type of (Item being manipulated)) Equal to
  Actions
    Custom script: call TalentAdd2Hero(GetTriggerUnit())
Demo Event Choose Skill
  Events
    Game - Talent__Event becomes Equal to 1.00
  Conditions
  Actions
    Game - Display to (All players) the text: ((Proper name of Talent__Unit) + (( has picked: + TalentSpellsPrefix[Talent__Button]) + (TalentChoiceHead[Talent__Choice] + TalentSpellsSufix[Talent__Button])))
Demo Event Reset Skill
  Events
    Game - Talent__Event becomes Equal to -1.00
  Conditions
  Actions
    Game - Display to (All players) the text: ((Proper name of Talent__Unit) + (( has lost: + TalentSpellsPrefix[Talent__Button]) + (TalentChoiceHead[Talent__Choice] + TalentSpellsSufix[Talent__Button])))
Demo Event Gain a Choice
  Events
    Game - Talent__Event becomes Equal to 2.00
  Conditions
  Actions
    Game - Display to (All players) the text: ((Proper name of Talent__Unit) + ( got a choice for Level: + (String(Talent__Level))))
Demo Event Finished Chocies
  Events
    Game - Talent__Event becomes Equal to 3.00
  Conditions
  Actions
    Game - Display to (All players) the text: ((Proper name of Talent__Unit) + has reached the end of it's Talents.)
Demo Reset
  Events
    Player - Player 1 (Red) types a chat message containing reset (stringnoformat) as An exact match
  Conditions
  Actions
    -------- Trigger based changes, you have to revert yourself, best by using the -1 Event --------
    -------- Who resets (a) talent(s) --------
    Set VariableSet Talent__Unit = LastSelected
    -------- How many talent choices are undone? if you want all, use a absurd high number. --------
    Set VariableSet Talent__ResetAmount = 99
    Trigger - Run TalentReset (ignoring conditions)
Demo PreventReset
  Events
    Player - Player 1 (Red) types a chat message containing PreventReset (stringnoformat) as An exact match
  Conditions
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        ((Execution count of (This trigger)) And 1) Equal to 1
      Then - Actions
        Set VariableSet TalentControlPreventReset[(Player number of (Triggering player))] = True
        Game - Display to (All players) the text: PreventReset enabled
        -------- You also need to update the box, it won't update current inspected tier --------
        Custom script: call TalentBoxUpdate(GetTriggerPlayer())
      Else - Actions
        Game - Display to (All players) the text: PreventReset Disabled
        Set VariableSet TalentControlPreventReset[(Player number of (Triggering player))] = False
        -------- You also need to update the box, it won't update current inspected tier --------
        Custom script: call TalentBoxUpdate(GetTriggerPlayer())
Demo Macro
  Events
    Player - Player 1 (Red) types a chat message containing - (stringnoformat) as A substring
  Conditions
    (Substring((Entered chat string), 1, 1)) Equal to -
  Actions
    Custom script: call TalentMacroDo(udg_TalentControlTarget[GetPlayerId(GetTriggerPlayer())], GetEventPlayerChatString())
Demo LastSelect
  Events
    Player - Player 1 (Red) Selects a unit
  Conditions
  Actions
    Set VariableSet LastSelected = (Triggering unit)
function Trig_Demo_Info_Actions takes nothing returns nothing
    local framehandle fh = BlzCreateFrame("TalentBoxTextArea", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), 0, 0)
    call BlzFrameSetSize(fh, 0.22, 0.22)
    call BlzFrameSetAbsPoint(fh, FRAMEPOINT_TOPRIGHT, 0.8, 0.5)
    call BlzFrameSetText(fh, "Talent Jui, gives units/heroes at levels you want a tier. An unit can pick 1 option from the given options the tier has.|n|nSelect an unit and click the ShowTalent Button to show the TalentBox.|n|nWhen the talentBox is shown you can observe talents choosen from the selected unit regardless of ownerhship.|n|nYou can pick/unlearn talents from any unit you have shared control of.")
    call BlzFrameAddText(fh, "You can write \"PreventReset\" to toggle enablity of the resetButton.")
    call BlzFrameSetEnable(fh, false)
endfunction

//===========================================================================
function InitTrig_Demo_Info takes nothing returns nothing
    set gg_trg_Demo_Info = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Demo_Info, 0.00 )
    call TriggerAddAction( gg_trg_Demo_Info, function Trig_Demo_Info_Actions )
endfunction

 
Debug Info to have an idea how many indexes are taken.
Demo Print TierChoice Count
  Events
    Time - Elapsed game time is 1.00 seconds
  Conditions
  Actions
    Game - Display to (All players) the text: (Choice Count: + (String(TalentChoiceLast)))
    Game - Display to (All players) the text: (Tier Count: + (String(TalentTierLast)))