Code:
function XYDist takes real X1, real Y1, real X2, real Y2 returns real
local real dx = X2 - X1
local real dy = Y2 - Y1
return SquareRoot(dx * dx + dy * dy)
endfunction
function SetUnitPosEx takes unit wUnit, real moveSize, real tgtX, real tgtY returns nothing
local real getAngle = bj_RADTODEG * Atan2(tgtY - GetUnitY(wUnit), tgtX - GetUnitX(wUnit))
local real x = GetUnitX(wUnit) + moveSize * Cos(getAngle * bj_DEGTORAD)
local real y = GetUnitY(wUnit) + moveSize * Sin(getAngle * bj_DEGTORAD)
call SetUnitPosition(wUnit, x,y)
call SetUnitFacing(wUnit, getAngle)
endfunction
function StopMovingUnitXY takes trigger t returns nothing
call FlushChildHashtable(udg_SkillTable, GetHandleId(t) )
call DestroyTrigger(t)
endfunction
function MoveProc takes nothing returns nothing
//Unpack the load
local unit wUnit = LoadUnitHandle (udg_SkillTable, GetHandleId(GetTriggeringTrigger()), StringHash("wUnit") )
local real speed = LoadReal (udg_SkillTable, GetHandleId(GetTriggeringTrigger()), StringHash("speed") )
local real X = LoadReal (udg_SkillTable, GetHandleId(GetTriggeringTrigger()), StringHash("X") )
local real Y = LoadReal (udg_SkillTable, GetHandleId(GetTriggeringTrigger()), StringHash("Y") )
local trigger exec= LoadTriggerHandle(udg_SkillTable, GetHandleId(GetTriggeringTrigger()), StringHash("Exec") )
//Let's process the movement
//First, check if UnitX is bigger than target X (also Y), to determine the upside/downside.
//Oh, we can use XYDist!
call SetUnitPosEx( wUnit, speed * udg_updateSpeed, X, Y )
//Check!
if XYDist(GetUnitX(wUnit), GetUnitY(wUnit), X, Y ) <= speed * udg_updateSpeed then
//Finish touch here!
//Note that we can't create new listener. Therefore, we use Trigger!
//call ExecuteFunc(exec)
call TriggerExecute(exec)
//Clean this mess and let it tingle
call StopMovingUnitXY(GetTriggeringTrigger())
endif
//Trying to Nullify the allocated pointer
//Because even pointer takes 4 byte for declaration, right?
set wUnit = null
set exec = null //don't destroy! it won't work...
endfunction
function UpdateMoveUnitSpeed takes trigger t, real newSpeed returns nothing
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("speed"), newSpeed)
endfunction
function UpdateMoveUnitXY takes trigger t, real newX, real newY returns nothing
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("X"), newX)
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("Y"), newY)
endfunction
function MoveUnitXY takes unit wUnit, real speed, real X, real Y, trigger exec returns trigger
local trigger t = CreateTrigger()
//local timer tim = CreateTimer() //A bit useless, and unknown usage. But we will find out! OH useless... >_<
//Packing before expanding
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("X"), X)
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("Y"), Y)
call SaveReal(udg_SkillTable, GetHandleId(t), StringHash("speed"), speed)
call SaveUnitHandle(udg_SkillTable, GetHandleId(t), StringHash("wUnit"), wUnit)
call SaveTriggerHandle( udg_SkillTable, GetHandleId(t), StringHash("Exec"), exec )
//call SaveTimerHandle(udg_SkillTable, GetHandleId(t), StringHash("timer"), tim) //Completely useless
//Trigger Session
call TriggerRegisterTimerEvent(t, udg_updateSpeed, true)
call TriggerAddAction(t,function MoveProc)
//Return huff... w00t with return trigger? ooo...
return t
endfunction
Share This Thread