[Trigger] Relative Movement for Squads

Level 22
Joined
Jul 25, 2009
Messages
3,112
Alright so, this is kind of awkward to explain, so let me give you a picture.

I've got a bunch of units in my map that are locusted and/or won't hold formation for whatever reason (also won't hold formation when you attack move) and I want them to, instead of clump in a single point, surround the point they were ordered to. This would of course be implemented into my existing squad system.

Here's a snippet of code (copied from Amigurumi's System) for ordering the members of a group to move. What's the easiest way to achieve this kind of relative movement without causing lag?

P.S. I forgot how to do GUI tags on Hive.

Order Squad Leader
Events
Unit - A unit Is issued an order with no target
Unit - A unit Is issued an order targeting an object
Unit - A unit Is issued an order targeting a point
Conditions
((Ordered unit) is A structure) Equal to False
GLeader[(Custom value of (Ordered unit))] Equal to (Ordered unit)
(Custom value of (Ordered unit)) Not equal to 0
Actions
Trigger - Turn off (This trigger)
Set GGroup[1] = (Units in (Playable map area) matching (((Custom value of (Matching unit)) Equal to (Custom value of (Ordered unit))) and (((Matching unit) is A structure) Equal to False)))
Custom script: call GroupImmediateOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()) )
Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetUnit() )
Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetDestructable() )
Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetItem() )
Set GPoint[1] = (Target point of issued order)
Custom script: call GroupPointOrderLoc( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), udg_GPoint[1] )
Custom script: call RemoveLocation(udg_GPoint[1])
Custom script: call DestroyGroup(udg_GGroup[1])
Trigger - Turn on (This trigger)
 

Attachments

  • aaaa.jpg
    aaaa.jpg
    9.8 KB · Views: 77

MyPad

Spell Reviewer
Level 20
Joined
May 9, 2014
Messages
1,601
To do GUI tags, you would use these tags:

[trigger][/trigger]

  • Order Squad Leader
    • Events
      • Unit - A unit Is issued an order with no target
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • ((Ordered unit) is A structure) Equal to False
      • GLeader[(Custom value of (Ordered unit))] Equal to (Ordered unit)
      • (Custom value of (Ordered unit)) Not equal to 0
    • Actions
      • Trigger - Turn off (This trigger)
      • Set GGroup[1] = (Units in (Playable map area) matching (((Custom value of (Matching unit)) Equal to (Custom value of (Ordered unit))) and (((Matching unit) is A structure) Equal to False)))
      • Custom script: call GroupImmediateOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()) )
      • Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetUnit() )
      • Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetDestructable() )
      • Custom script: call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetItem() )
      • Set GPoint[1] = (Target point of issued order)
      • Custom script: call GroupPointOrderLoc( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), udg_GPoint[1] )
      • Custom script: call RemoveLocation(udg_GPoint[1])
      • Custom script: call DestroyGroup(udg_GGroup[1])
      • Trigger - Turn on (This trigger)
Translating that into pure jass, (as per my rendition):

JASS:
function Trig_Order_Squad_Leader_Conditions takes nothing returns boolean
    if ( not ( IsUnitType( GetOrderedUnit(), UNIT_TYPE_MECHANICAL ) == false )) then
        return false
    endif
    if ( not (udg_GLeader[ GetUnitUserData( GetOrderedUnit() ) ] == GetOrderedUnit() )) then
        return false
    endif
    if ( not ( GetUnitUserData( GetOrderedUnit() ) != 0 )) then
        return false
    endif
    return true
endfunction

// The function name is not exact, though
function Order_Squad_Leader_001 takes nothing returns boolean
    if ( not ( GetUnitUserData(GetFilterUnit() ) == GetUnitUserData(GetOrderedUnit()) )) then
        return false
    endif
    return true
endfunction

function Trig_Order_Squad_Leader_Actions takes nothing returns nothing
    call DisableTrigger( GetTriggeringTrigger() )
    set udg_GGroup[1] = GetUnitsInRectMatching(GetPlayableMapRect(), Filter(function Order_Squad_Leader_001))
    call GroupImmediateOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()) )
    call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetUnit() )
    call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetDestructable() )
    call GroupTargetOrder( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), GetOrderTargetItem() )
    set udg_GPoint[1] = GetOrderPointLoc()
    call GroupPointOrderLoc( udg_GGroup[1], OrderId2String(GetIssuedOrderId()), udg_GPoint[1] )
    call RemoveLocation(udg_GPoint[1])
    call DestroyGroup(udg_GGroup[1])
    call EnableTrigger( GetTriggeringTrigger())
endfunction

function InitTrig_Order_Squad_Leader takes nothing returns nothing
    set gg_trg_Order_Squad_Leader = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Squad_Leader, EVENT_PLAYER_UNIT_ISSUED_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Squad_Leader, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Order_Squad_Leader, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddCondition( gg_trg_Order_Squad_Leader, Condition(function Trig_Order_Squad_Leader_Conditions) )
    call TriggerAddAction( gg_trg_Order_Squad_Leader, function Trig_Order_Squad_Leader_Actions))
endfunction
 
Top