• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Return To Position System v 1.0.0.7

This is a system i made to move units back to the position they were originally in. It also sets there facing to the same facing that the unit was. You can change the units facing with custom script. You can change were you want the unit to go to. So if you start the unit in one point and move him to another you can make him return to a new position of your choice.

I made the filtering easy. You can filter out units by adding the conditions u want the system to follow to the condition block in the filter units function. Make sure to use the tempUnit variable for any condition u add to here.

Import steps.
1) u need to install bribe's unit indexer system
2) copy the filter trigger first
3) copy the actions trigger second and make sure it stays below the filter trigger.
4) add conditions and use to ur liking.

  • ReturnToPosFilter
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: endfunction
      • Custom script: function AddUnitsConditionsRTP takes unit u returns boolean
      • -------- This is used for adding units to the group u can filter out the units u dont want to add by just adding conditions. --------
      • -------- Also note that if you dont want to add any units for a specific time you can set the addUnitBooleanRTP to false and it will not allow any units to be added. --------
      • -------- set addUnitBooleanRTP = false in a trigger do not change it here. Also dont change anything in the then block or the thing after the else block. --------
      • Custom script: set udg_tempUnit = u
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • addUnitBooleanRTP Equal to True
        • Then - Actions
          • Custom script: return true
        • Else - Actions
      • Custom script: return false
JASS:
    // 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


version 1.0.0.7
Fixed some of the description.​
version 1.0.0.6
Added a function that i forgot to add earlier.
This function gives more functionality to the user.​
version 1.0.0.5
Fixed a small bug created by last update.​
version 1.0.0.4
Made some changes to description.
Added the ability to check if a unit is in the return to position system.
Added the ability to add units to the system if they were removed at some point.​
version 1.0.0.3
Fixed a bug were players without JNGP couldnt use this.
This can now be used by everyone​
version 1.0.0.2
changed over to the unti indexer event​
version 1.0.0.1
removed useless things i forgot​
version 1.0.0.0
first version released​


Keywords:
jass, GUI, GUI friendly, friendly, deathismyfriend, dimf, unit return, return, return system, system
Contents

Template Map (Map)

Reviews
Return To Position System v 1.0.0.3 | Reviewed by Maker | 1st Sep 2013 APPROVED [tr] A useful, basic system. You could reconsider using the SetUnitX/Y as it can look weird

Moderator

M

Moderator


Return To Position System v 1.0.0.3 | Reviewed by Maker | 1st Sep 2013
APPROVED


126248-albums6177-picture66521.png


A useful, basic system. You could reconsider using the SetUnitX/Y
as it can look weird
[tr]
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Retro records a unit's state or properties over time. This includes positions, life, exp, etc. like a save/load.

I didn't notice the unit indexer because of that function that registers the unit who enters the map. Why not just use UnitIndexerEvent Equal To 1.00 then?

Thats a neat system then. im not sure how using UnitIndexerEvent equal to 1.00 works lol. That makes a triggger fire when a new unit gets a new custom value right ?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
because using them ends up to a much better resource :V

lol yes some of the systems are very useful but if i have no need for them i dont use them. like unit indexer. Its a great system but i just dont use it that often. Most spells of mine i use IA i dont like using unit groups.
This is the first time i have ever used that one lol.
I do use other ppls systems just not often.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
The unit teleports from (x0, y0) to (x1, y1) if the unit stops at a position that is not the actual original position. It just looks a bit off.

Ya i can't really find a workaround. i might have to check if the unit is in a short range from the position.

For some reason when you order unit to go to coordinates it is always off a slight amount.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
I'm not home so i can't do a demo code atm.

To use this though in the filter trigger you filter out all units that you don't want this system to effect simply by putting them in the conditions.
Now when you create unit at point this system checks to see if you have them filtered out. If they aren't filter ( match all conditions) then it will store their position and facing angle at that time. So when the unit stops doing anything it will order the unit to return to the position it was created at.

Now at any time during the game you can change the units position / facing angle.
To do this you do this.
  • This one changes the units return position
  • Set tempLoc = center of new location
  • Set tempUnit = the unit you want to change its return position
  • Custom script: call ChangeReturnPoint( udg_tempLoc, udg_tempUnit)
  • This one changes the untis facing angle
  • Set tempReal = new facing angle of unit.
  • Custom script: call ChangeUnitFacing( udg_tempUnit, udg_tempReal)
  • This allows you to remove the unit from the group so it is not controlled anymore by the system.
  • Custom script: call RemoveUnitFromGroup( udg_tempUnit)
I will update system later for better description. Normally i do better description so GUIers can use it easier sorry about that.
 
Top