GetTriggerUnit-
DogEntrepreneur
- Reaction score
- 129
HandleId are never the same and never recycled. They're numbers like 101505491171.
By using AIDS structs. You know, like, setting a struct up to be created and destroyed upon unit creation and destruction. So that you can clear the data properly.yes that works but then say a unit dies with the integer 2 attached to it how would i recycle it and use it again and all that stuff
library UnitTracking initializer Init requires AIDS
globals
private constant real PERIOD = .03125
endglobals
private struct Data extends array
real bx
real by
real nx
real ny
real dis
real totaldis
boolean stoptrack
private thistype next
private thistype prev
private static real dx
private static real dy
//From T32, =D
static method PeriodicLoop takes nothing returns nothing
local thistype this=thistype(0).next
loop
exitwhen this==0
if not this.stoptrack then
set this.bx = this.nx
set this.by = this.ny
set this.nx = GetUnitX(this.unit)
set this.ny = GetUnitY(this.unit)
set thistype.dx = this.nx - this.bx
set thistype.dy = this.ny - this.by
set this.dis = SquareRoot(thistype.dx * thistype.dx + thistype.dy * thistype.dy)
set this.totaldis = this.totaldis + this.dis
else
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
debug set this.prev=0
endif
set this=this.next
endloop
endmethod
method startTracking takes nothing returns nothing
set this.stoptrack = false
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
endmethod
//
private method AIDS_onCreate takes nothing returns nothing
set this.bx = 0.
set this.by = 0.
set this.nx = 0.
set this.ny = 0.
set this.dis = 0.
endmethod
private method AIDS_onDestroy takes nothing returns nothing
set this.stoptrack = true
endmethod
//! runtextmacro AIDS()
endstruct
globals
private Data d
endglobals
function TrackUnitMovement takes unit whichunit returns nothing
set d = Data[whichunit]
if d.stoptrack then
call d.startTracking()
endif
endfunction
function StopTrackingUnit takes unit whichunit returns nothing
set Data[whichunit].stoptrack = true
endfunction
function IsUnitMoving takes unit whichunit returns boolean
set d = Data[whichunit]
return d.dis != 0.
endfunction
function GetUnitMovingAngle takes unit whichunit returns real
set d = Data[whichunit]
return 57.2958 * (Atan2(d.ny - d.by, d.nx - d.bx))
endfunction
function GetUnitMovingDistance takes unit whichunit returns real
return Data[whichunit].dis
endfunction
function GetUnitTotalMovingDistance takes unit whichunit returns real
return Data[whichunit].totaldis
endfunction
function ResetUnitDistance takes unit whichunit returns nothing
set Data[whichunit].totaldis = 0.
endfunction
private function Init takes nothing returns nothing
call TimerStart(CreateTimer(),PERIOD,true,function Data.PeriodicLoop)
endfunction
endlibrary
When i use kill unit the second units distnace is 0 and when i use a diffrent variable also 0
scope THISBREAKSGTAMSSYSTEM initializer SHAMWOW
globals
unit EL_MAN
unit THE_OTHER_MAN
endglobals
function LOLWUT takes nothing returns nothing
call BJDebugMsg(R2S(GetUnitTotalMovingDistance(THE_OTHER_MAN)))
endfunction
function LOLCATS takes nothing returns nothing
set THE_OTHER_MAN = CreateUnit(Player(0),039;hfoo039;,0,0,0)
call TimerStart(CreateTimer(),1,true,function LOLWUT)
call TrackUnitMovement(THE_OTHER_MAN)
endfunction
function SLAPCHOP takes nothing returns nothing
call KillUnit(EL_MAN)
call TimerStart(CreateTimer(),100,false,function LOLCATS)
endfunction
function SHAMWOW takes nothing returns nothing
set EL_MAN = CreateUnit(Player(0),039;hfoo039;,0,0,0)
call IssuePointOrder(EL_MAN,"move",0,1000)
call TimerStart(CreateTimer(),5,false,function SLAPCHOP)
call TrackUnitMovement(EL_MAN)
endfunction
endscope
Why do people insist on using the unsafe and slower GetHandleId and hashtables..