Faust
You can change this now in User CP.
- Reaction score
- 123
JASS:
scope Relocation initializer I
private struct Relocation
//! runtextmacro PUI()
unit mover
real x
real y
integer xp
timer clock = CreateTimer()
integer unitid
boolean transferFlag
static method Get takes unit whichUnit returns Relocation
local Relocation dat = Relocation[whichUnit] //check if an instance is already associated with whichUnit
if dat == 0 then //if not
set dat = Relocation.allocate() //allocate a new instance
//insert whatever you want to happen when a new instance is created here
set dat.transferFlag = false
set Relocation[whichUnit] = dat //associate the newly allocate instance with whichUnit
endif
return dat
endmethod
static method Transfer takes unit sourceUnit, unit targetUnit returns Relocation
local Relocation dat = Relocation.Get(sourceUnit)
//to make this function safer, you should check if targetUnit has an instance set before starting the transfer.
set dat.transferFlag = true //anything in onDestroy should not be carried out for a transfering instance.
//by releasing, the instance will be freed from the previous unit, and next in line to be allocated.
call dat.release()
set dat = Relocation.allocate()
set dat.transferFlag = false
set Relocation[targetUnit] = dat //transfer complete
return dat
endmethod
method onDestroy takes nothing returns nothing
if not .transferFlag then
//this block will only be called whenever an instance is fully destroyed.
//transfered instances will be ignored
call PauseTimer(.clock)
call ClearTimerStructA(.clock)
call DestroyTimer(.clock)
endif
endmethod
endstruct
private function C2 takes nothing returns boolean
return GetIssuedOrderId() == 852165
endfunction
private function C3 takes nothing returns boolean
return GetIssuedOrderId() == 852166 and IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
endfunction
private function RootHandle takes nothing returns nothing
local Relocation dat = GetTimerStructA(GetExpiredTimer())
if GetUnitX(dat.mover) == dat.x and GetUnitY(dat.mover) == dat.y then
call ReplaceTower(dat.mover, dat.unitid, 039;h01C039;)
call Relocation.Transfer(dat.mover, bj_lastCreatedUnit)
set dat.mover = bj_lastCreatedUnit
call SetHeroXP(bj_lastCreatedUnit, dat.xp, false)
call PauseTimer(dat.clock)
endif
if GetUnitCurrentOrder(dat.mover) != 852165 then
call PauseTimer(dat.clock)
endif
endfunction
private function Root takes nothing returns nothing
local Relocation dat = Relocation[GetTriggerUnit()]
local location l = GetOrderPointLoc()
set dat.mover = GetTriggerUnit()
set dat.x = GetLocationX(l)
set dat.y = GetLocationY(l)
set dat.clock = CreateTimer()
call SetTimerStructA(dat.clock, dat)
call TimerStart(dat.clock, 0.2, true, function RootHandle)
call RemoveLocation(l)
set l = null
endfunction
private function Uproot takes nothing returns nothing
local Relocation dat = Relocation[GetTriggerUnit()]
if dat == null then
call BJDebugMsg("Dat is null")
set dat = Relocation.create()
//call SetTimerStructA(dat.clock, dat)
else
call BJDebugMsg("dat is not null")
endif
set dat.xp = GetHeroXP(GetTriggerUnit())
call KillDummy(GetTriggerUnit())
set dat.unitid = GetUnitTypeId(GetTriggerUnit())
call ReplaceTower(GetTriggerUnit(), 039;h02A039;, 039;none039;)
call IssueImmediateOrderById(bj_lastCreatedUnit, 852166)
call Relocation.Transfer(GetTriggerUnit(), bj_lastCreatedUnit)
//set dat.mover = bj_lastCreatedUnit
endfunction
private function C1 takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 039;H029039;
endfunction
private function EntryUproot takes nothing returns nothing
local Relocation dat = Relocation[GetTriggerUnit()]
if dat == null then
call IssueImmediateOrderById(GetTriggerUnit(), 852166)
else
endif
endfunction
//===========================================================================
private function I takes nothing returns nothing
local trigger t = CreateTrigger()
local region r = CreateRegion()
call RegionAddRect(r, bj_mapInitialPlayableArea)
call TriggerRegisterEnterRegion(t, r, Condition(function C1))
call TriggerAddAction(t, function EntryUproot)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddCondition(t, Condition(function C2))
call TriggerAddAction(t, function Root)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_ORDER)
call TriggerAddCondition(t, Condition(function C3))
call TriggerAddAction(t, function Uproot)
endfunction
endscope
Now same thing happens, except there is only one red line with that error message