NeuroToxin
New Member
- Reaction score
- 46
As the title says, I want to know how to tell if a unit is already associated with another struct instance of the same type.
I'd add the dummies to a unit group member of a struct attached to the caster...or, in semi-GUI language, a unit group array keyed to the custom value of the caster as assigned by a unit indexing system.What im trying to do, is get it so every dummy unit is associated with its caster.
struct ABC
unit Owner
private static HandleTable table
static method create takes unit u returns thistype
local thistype this = 0
if thistype.table.exists(u) then
return thistype(thistype.table<u>)
endif
set this = thistype.allocate()
set this.Owner = u
set thistype.table[this.Owner] = this
return this
endmethod
method destroy takes nothing returns nothing
call thistype.table.flush(this.Owner)
set this.Owner = null
call this.deallocate()
endmethod
static method getInstance takes unit u returns thistype
return thistype(thistype.table<u>)
endmethod
private static method onInit takes nothing returns nothing
set thistype.table = HandleTable.create()
endmethod
endstruct</u></u>
struct myStruct
// ... blah blah blah ...
public static hashtable hash
public unit whichUnit
public static method has takes unit whichUnit returns boolean
return (LoadInteger(thistype.hash, GetHandleId(whichUnit), 0) != 0 or not HaveSavedInteger(thistype.hash, GetHandleId(whichUnit), 0))
endmethod
public static method create takes unit whichUnit returns thistype
local thistype this
if (LoadInteger(thistype.hash, GetHandleId(whichUnit), 0) != 0 or not HaveSavedInteger(thistype.hash, GetHandleId(whichUnit), 0)) then // Second part may not be necessary. I don't remember
set thistype.whichUnit = whichUnit
call SaveInteger(thistype.hash, GetHandleId(whichUnit), 0, this)
else
debug call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Warning: Unit already identified with an instance!")
return 0
endif
// ... blah blah blah ...
return this
endmethod
private method onDestroy takes nothing returns nothing
call RemoveInteger(thistype.hash, GetHandleId(this.whichUnit), 0)
set this.whichUnit = null
endmethod
private static method onInit takes nothing returns nothing
set thistype.hash = InitHashtable()
endmethod
endstruct
function trololol takes unit whichUnit returns nothing
local myStruct lolol
if ( not myStruct.has(whichUnit) ) then
set lolol = myStruct.create(whichUnit)
endif
// ... blah blah blah ...
endfunction
You're doing the same too.You guys are making this as complicated as you can, aren't you?