- Joined
- Jul 10, 2007
- Messages
- 6,306
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
set Table(abils[i])[c[i]]=GetLearnedSkill()
set Table(marked[i]).boolean[GetLearnedSkill()]=true
set Table(abils[i])[c[i]]=GetLearnedSkill()
set Table(marked[i]).boolean[Table(abils[i])[c[i]]]=true
private function Ability takes nothing returns boolean
local integer i = GetUnitUserData(GetTriggerUnit())
if (not Table(marked[i]).boolean.has(GetLearnedSkill())) then
set Table(abils[i])[c[i]]=GetLearnedSkill()
set Table(marked[i]).boolean[GetLearnedSkill()]=true
set c[i]=c[i]+1
endif
return false
endfunction
private function Ability takes nothing returns boolean
local integer i = GetUnitUserData(GetTriggerUnit())
local integer a = GetLearnedSkill()
if (not Table(marked[i]).boolean.has(a)) then
set Table(abils[i])[c[i]]=a
set Table(marked[i]).boolean[a]=true
set c[i]=c[i]+1
endif
return false
endfunction
You could still elimate all the "Table()" typecasting and this needs a better description how to use it and why to use it.
why to use it
how to use it
Then your resource suffers obscurity. I can't really think of a reason for it other than the reason you already supported for your other resource, and with that in mind I feel it better to just inline it directly into that other resource. I know how much you hate to couple resources but I feel without any real purpose of this system aside from that one other library it kind of doesn't belong on its own. I think it was troll-brain who said "Cool!=Useful" and I agree with that here --
- Get learned abilities
- ???
- Profit!! (but what kind of profit?)
library GetLearnedAbilities /* v1.1.0.0
*************************************************************************************
*
* Allows one to retrieve all currently learned abilities of a unit
*
*************************************************************************************
*
* */ requires /*
*
* */ UnitIndexer /* hiveworkshop.com/forums/showthread.php?t=172090
* */ Table /* hiveworkshop.com/forums/showthread.php?t=188084
* */ RegisterPlayerUnitEvent /* hiveworkshop.com/forums/showthread.php?t=203338
*
************************************************************************************
*
* struct LearnedAbilities extends array
*
* static method operator [] takes unit u returns LearnedAbilities
* method operator [] takes integer index returns integer abilityId
*
* method operator count takes nothing returns integer abilityCount
*
***********************************************************************************/
globals
private Table abils
private Table marked
private integer array c
endglobals
private function Index takes nothing returns boolean
set abils[GetIndexedUnitId()] = Table.create()
set marked[GetIndexedUnitId()] = Table.create()
return false
endfunction
private function Deindex takes nothing returns boolean
call abils[GetIndexedUnitId()].destroy()
call marked[GetIndexedUnitId()].destroy()
set c[GetIndexedUnitId()] = 0
return false
endfunction
private function Ability takes nothing returns nothing
local integer i = GetUnitUserData(GetTriggerUnit())
if (not marked[i].boolean.has(GetLearnedSkill())) then
set abils[i][c[i]] = GetLearnedSkill()
set marked[i].boolean[GetLearnedSkill()] = true
set c[i] = c[i] + 1
endif
endfunction
private module M
private static method onInit takes nothing returns nothing
set abils = Table.create()
set marked = Table.create()
call RegisterUnitIndexEvent(Filter(function Index), UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Filter(function Deindex), UnitIndexer.DEINDEX)
call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL, function Ability)
endmethod
endmodule
struct LearnedAbilities extends array
static method operator [] takes unit u returns LearnedAbilities
return GetUnitUserData(u)
endmethod
method operator [] takes integer index returns integer
return abils[this][index]
endmethod
method operator count takes nothing returns integer
local integer i = c[this]
local integer m
loop
exitwhen i == 0
set i = i - 1
set m = abils[this][i]
if GetUnitAbilityLevel(GetUnitById(this), m) == 0 then
call marked[this].remove(m)
set c[this] = c[this] - 1
set abils[this][i] = abils[this][c[this]]
call abils[this].remove(c[this])
endif
endloop
return c[this]
endmethod
implement M
endstruct
endlibrary
exitwhen i == 0exitwhen 0 == iNes, when will you learn that uses is depricated and should not be used anymore?
method operator [] takes integer index returns integer
if index < c[this] then
return abils[this][index]
endif
return 0
endmethod
