- Joined
- Dec 3, 2011
- Messages
- 366
JASS:
library UnitData initializer init requires Table
/*
This system requires:
Table by Bribe:
[url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
API
function Unit takes UnitData returns Unit by unit data
E: set u = Unit(12)
function GetUnitData takes unit returns UnitData
E: set ud = GetUnitData(u)
function IsUnitIndexed takes unit returns boolean
function DeindexedUnit takes unit returns nothing
Remove unit data.
function IndexUnit takes unit returns nothing
Add unit data
function RemoveEx takes unit returns nothing.
Remove both unit and unit data. Use instade of function RemoveUnit()
function MakeUnitPernament takes unit, boolean returns nothing
Make unit will/won't be removed and deindexed when decay.
function IsUnitPernament takes unit returns boolean
function RegisterIndexEvent takes code returns nothing
function RegisterDeindexEvent takes code returns nothing
*/
//! textmacro CreateUnitDataAbi takes RAWCODE
//! external ObjectMerger w3a AId1 $RAWCODE$ Idef 0 $VALUE$ anam "Unit Data Ability" aite 0 ansf ""
//! endtextmacro
//! runtextmacro("AUID")
globals
Table UnitData
unit IndexingUnit
private integer udex = 0
private integer abi = 'AUID'
private trigger onIndex = CreateTrigger()
private trigger onDeindex = CreateTrigger()
endglobals
function Unit takes integer dex returns unit
return UnitData.unit[dex]
endfunction
function GetUnitData takes unit u returns integer
return UnitData.integer[GetHandleId(u)]
endfunction
function IsUnitIndexed takes unit u returns boolean
return GetUnitAbilityLevel(u,abi) != 0
endfunction
function MakeUnitPernament takes unit u, boolean b returns nothing
set UnitData.boolean[GetUnitData(u)] = b
endfunction
function IsUnitPernament takes unit u returns boolean
return UnitData.boolean[GetUnitData(u)]
endfunction
function DeindexUnit takes unit u returns nothing
set IndexingUnit = null
if (IsUnitIndexed(u) == true) then
set IndexingUnit = u
call UnitRemoveAbility(u,abi)
set UnitData.unit[GetUnitData(u)] = UnitData.unit[udex]
set UnitData.integer[GetHandleId(UnitData.unit[udex])] = GetUnitData(u)
set UnitData.unit[udex] = null
set udex = udex - 1
call TriggerExecute(onDeindex)
endif
endfunction
function RemoveUnitEx takes unit u returns nothing
call DeindexUnit(u)
call RemoveUnit(u)
endfunction
function IndexUnit takes unit u returns nothing
set IndexingUnit = null
if (IsUnitIndexed(u) == false) then
set IndexingUnit = u
set udex = udex + 1
set UnitData.unit[udex] = u
set UnitData.integer[GetHandleId(u)]=udex
call UnitAddAbility(u,abi)
call UnitMakeAbilityPermanent(u,true,abi)
call DisplayTextToPlayer(GetLocalPlayer(),0,0,I2S(GetUnitData(u)))
call TriggerExecute(onIndex)
endif
endfunction
function RegisterIndexEvent takes code func returns nothing
call TriggerAddAction(onIndex, func)
endfunction
function RegisterDeindexEvent takes code func returns nothing
call TriggerAddAction(onDeindex, func)
endfunction
private function act takes nothing returns boolean
local unit u = GetEnumUnit()
call IndexUnit(u)
return true
endfunction
private function enter takes nothing returns boolean
local unit u = GetEnteringUnit()
if IsUnitIndexed(u) == false then
call IndexUnit(u)
endif
return true
endfunction
private function decay takes nothing returns boolean
local unit u = GetDecayingUnit()
if IsUnitPernament(u) == false then
call RemoveUnitEx(u)
return true
else
return false
endif
endfunction
private function init takes nothing returns nothing
local integer i
local rect rct = GetWorldBounds()
local region r = CreateRegion()
call RegionAddRect(r,rct)
set UnitData = Table.create()
call TriggerRegisterEnterRegion(CreateTrigger(),r,Filter(function enter))
for i = 0 to 15
call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup,Player(i),Filter(function act))
call TriggerRegisterPlayerUnitEvent(CreateTrigger(),Player(i),EVENT_PLAYER_UNIT_DECAY,Filter(function decay))
endfor
set r = null
set rct = null
endfunction
endlibrary
Anyone can help me
Demo map:
View attachment Unit Data.w3x