// Return To Position System
// version 1.0.0.7 by deathismyfriend
// Function List
//
//
// This one changes the units return position
// Custom script: call RTPChangeReturnPoint( location, unit)
//
//
// This one changes the untis facing angle
// Custom script: call RTPChangeUnitFacing( unit, real)
//
//
// This allows you to remove the unit from the group so it is not controlled anymore by the system.
// Custom script: call RTPRemoveUnitFromGroup( unit)
//
//
// This allows you to add a unit to the group.
// Note: Units that are not filtered in the filter trigger will automatically be added.
// Custom script: call RTPAddUnitToGroup( unit)
//
//
// This allows you to check if a unit is being managed by the system.
// Custom script: call RTPIsUnitInSystem( unit)
//
//
// This changes the units move command. it is preset to smart( smart is when they are not doing anything.)
// This is preset so when the unit isn't doing anything the system will order it to move to it's return position.
// This can be useful to change if you want a unit to suddenly run away. Let's say you have a trigger were its health gets below
// // a certain point and you want the unit to run away. Simply in that trigger change the order to attack and
// // whenever it is meant to attack it will run away instead.
// Custom script: call RTPChangeUnitMoveCommand( unit, string)
//
//
// This function registers all of the data from the old unit to the new unit.
// This helps with replacing units when the unit dies / or is changed.
// Make sure this is called before the old unit is removed from the game.
// You must create the unit before the old unit is removed.
// Create the old unit then hide the unit to simulate the death period then unhide unit when you want that unit to "revive"
// Then call this function
// Custom script: call ReplaceUnitRTP( oldUnit, newUnit)
//
//
function RTPChangeReturnPoint takes location L, unit u returns nothing
local integer i = GetUnitUserData( u)
set udg_unitPosXRTP[ i] = GetLocationX( L)
set udg_unitPosYRTP[ i] = GetLocationY( L)
endfunction
function RTPChangeUnitMoveCommand takes unit u, string str returns nothing
set udg_moveStringRTP[ GetUnitUserData( u)] = str
endfunction
function RTPChangeUnitFacing takes unit u, real face returns nothing
set udg_unitFacingRTP[ GetUnitUserData( u)] = face
endfunction
function RTPIsUnitInSystem takes unit u returns boolean
if IsUnitInGroup( u, udg_unitGroupRTP) then
return true
endif
return false
endfunction
function RTPRemoveUnitFromGroup takes unit u returns nothing
local integer i
if IsUnitInGroup( u, udg_unitGroupRTP) then
set i = GetUnitUserData( u)
set udg_unitRTP[ i] = null
set udg_unitPosXRTP[ i] = 0.00
set udg_unitPosYRTP[ i] = 0.00
set udg_unitFacingRTP[ i] = 0.00
call GroupRemoveUnit( udg_unitGroupRTP, u)
endif
endfunction
function ReplaceUnitRTP takes unit old, unit new returns nothing
local integer i
local integer i1
if IsUnitInGroup( old, udg_unitGroupRTP) then
set i = GetUnitUserData( old)
set i1 = GetUnitUserData( new)
set udg_unitRTP[ i1] = new
set udg_unitPosXRTP[ i1] = udg_unitPosXRTP[ i]
set udg_unitPosYRTP[ i1] = udg_unitPosYRTP[ i]
set udg_unitFacingRTP[ i1] = udg_unitFacingRTP[ i]
set udg_moveStringRTP[ i1] = udg_moveStringRTP[ i]
call GroupAddUnit( udg_unitGroupRTP, new)
call RTPRemoveUnitFromGroup( old)
endif
endfunction
function AddUnitToGroupRTP takes unit u, integer i returns nothing
if not IsUnitInGroup( u, udg_unitGroupRTP) then
set udg_unitRTP[ i] = u
set udg_unitPosXRTP[ i] = GetUnitX( u)
set udg_unitPosYRTP[ i] = GetUnitY( u)
set udg_unitFacingRTP[ i] = GetUnitFacing( u)
set udg_moveStringRTP[ i] = "smart"
call GroupAddUnit( udg_unitGroupRTP, u)
endif
endfunction
function RTPAddUnitToGroup takes unit u returns nothing
call AddUnitToGroupRTP( u, GetUnitUserData( u))
endfunction
function GetDistFromPointRTP takes real x1, real y1, real x2, real y2 returns real
return ( x2 - x1) * ( x2 - x1) + ( y2 - y1) * ( y2 - y1)
endfunction
function CheckingUnitToBeAddedRTP takes nothing returns boolean
local unit u = GetTriggerUnit()
if AddUnitsConditionsRTP( u) then
call AddUnitToGroupRTP( u, GetUnitUserData( u))
endif
set u = null
return false
endfunction
function GroupLoopRTP takes nothing returns nothing
local unit u = GetEnumUnit()
local integer str = GetUnitCurrentOrder( u)
local integer i = GetUnitUserData( u)
local real x
local real y
if GetUnitTypeId( u) == 0 or IsUnitType( u, UNIT_TYPE_DEAD) then
call GroupRemoveUnit( udg_unitGroupRTP, u)
elseif str == 0 then
set x = GetUnitX( u)
set y = GetUnitY( u)
if x != udg_unitPosXRTP[ i] and y != udg_unitPosYRTP[ i] then
call IssuePointOrder( u, udg_moveStringRTP[ i], udg_unitPosXRTP[ i], udg_unitPosYRTP[ i])
if GetDistFromPointRTP( x, y, udg_unitPosXRTP[ i], udg_unitPosYRTP[ i]) < 150 then
call SetUnitX( u, udg_unitPosXRTP[ i])
call SetUnitY( u, udg_unitPosYRTP[ i])
call SetUnitFacing( u, udg_unitFacingRTP[ i])
endif
endif
endif
set u = null
endfunction
function PeriodicGroupLoopRTP takes nothing returns boolean
call ForGroup( udg_unitGroupRTP, function GroupLoopRTP)
return false
endfunction
function RegisterUnitAtMapInitRTP takes nothing returns nothing
local unit u
local group g = CreateGroup()
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local region r = CreateRegion()
local timer tmr = GetExpiredTimer()
call GroupEnumUnitsInRect( g, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup( g)
exitwhen u == null
if AddUnitsConditionsRTP( u) then
call AddUnitToGroupRTP( u, GetUnitUserData( u))
endif
call GroupRemoveUnit( g, u)
endloop
call TriggerRegisterVariableEvent( t, "udg_UnitIndexerEvent", EQUAL, 1.00)
call TriggerAddCondition( t, Condition( function CheckingUnitToBeAddedRTP))
call TriggerRegisterTimerEvent( t1, 1.00, true)
call TriggerAddCondition( t1, Condition( function PeriodicGroupLoopRTP))
call DestroyGroup( g)
set g = null
set t = null
set t1 = null
set r = null
call DestroyTimer( tmr)
set tmr = null
endfunction
//===========================================================================
function InitTrig_ReturnToPosActions takes nothing returns nothing
local timer tmr = CreateTimer()
call TimerStart( tmr, 0.00, false, function RegisterUnitAtMapInitRTP)
set tmr = null
endfunction