- Joined
- Apr 24, 2012
- Messages
- 5,113
JASS:
library SkillBuild /* v1.3
*************************************************************************************
*
* AI System Member
*
* Allows AIs to automatically learn abilites
*
*************************************************************************************
*
* */ uses /*
*
* */ RegisterPlayerUnitEvent /*
* - hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/
*
*************************************************************************************
*
* API
*
* static method add takes integer heroId, integer spell, integer level returns nothing
* - adds a spell to the hero's to-learn list.
* - spells will be learned at "level"
*
*************************************************************************************
*
* Credits
*
* Magtheridon96 - RegisterPlayerUnitEvent
*
*************************************************************************************/
private module SBInit
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
struct SkillBuild extends array
private static hashtable ht
private static unit u
static method add takes integer heroId, integer spell, integer level returns nothing
call SaveInteger(ht, heroId, level, spell)
endmethod
private static method learn takes nothing returns boolean
local integer spell
set u = GetTriggerUnit()
if GetPlayerController(GetTriggerPlayer()) == MAP_CONTROL_COMPUTER and IsUnitType(u, UNIT_TYPE_HERO) then
set spell = LoadInteger(ht, GetUnitTypeId(u), GetUnitLevel(u))
if 0 != spell then
call SelectHeroSkill(u, spell)
endif
endif
return false
endmethod
private static method init takes nothing returns nothing
set ht = InitHashtable()
call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_LEVEL, function SkillBuild.learn)
endmethod
implement SBInit
endstruct
endlibrary
Demo:
JASS:
struct Test
private static method onInit takes nothing returns nothing
local integer heroId = 'Hmkg'
call SkillBuild.add(heroId, 'AHtc', 1)
call SkillBuild.add(heroId, 'AHtc', 4)
call SkillBuild.add(heroId, 'AHtc', 7)
endmethod
endstruct
Last edited: