HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Store order and play it

07-21-2008, 11:15 PM#1
RaveEye
Is there anyway I can save the units current order and give him the saved order later?

Lets say I have ordered my unitX to move to position x,y.
(Can I save this order in a variable.)

Then I order the unitX to stop

2 sec after I want the unitX to containue the saved order


I have found these native, but I cant get the to work
Collapse JASS:
local unit UnitX = SomeUnit
local integer order = GetUnitCurrentOrder(UnitX)
call IssueImmediateOrder(unitX,"stop")
call PolledWait(2)
call IssueImmediateOrderById(UnitX,order)
07-21-2008, 11:41 PM#2
chobibo
The order might not be compatible with the native, there are different kinds of orders, point orders, instant orders, unit-target orders, and others. For example, If you want a unit to move to coordinates x and y, aside from storing the order id, you also store the x and y values so you can re-order the unit.
07-22-2008, 06:46 AM#3
burningice95
You could create a trigger that fires whenever the unit is issued an order, and catch the order using the native GetIssuedOrderID(). Store the order to a global string variable, do your stuff, then give him the correct order with the variable (you would have to store the target and location of the order too, but that is easy)
07-22-2008, 02:19 PM#4
RaveEye
But I want to get the unit to containue its order. It can be
Attack Unit
Pickup Item
Drop Item
Sell Item
Move To x,y

Yes I want it to containue its order no matter what the order is.. Is this possible?
07-23-2008, 09:23 AM#5
Pyrogasm
With a struct:
Collapse JASS:
struct OrderHolder
    unit U
    integer Order = 0
    integer Type = 0
    real X = 0.00
    real Y = 0.00
    widget Target = null

    method StoreOrder takes integer Order, widget Target, real X, real Y, boolean ConsiderXY returns nothing
        set this.Order = Order

        if ConsiderXY == false and handle == null then
            set this.Type = 1
        elseif ConsiderXY == false and handle != null then
            set this.Type = 2
            set this.Target = Target
        elseif ConsiderXY == true then
            set this.Type = 3
            set this.X = X
            set this.Y = Y
        endif
    endmethod

    method RestoreOrder takes nothing returns nothing
        if this.Type == 1 then
            call IssueImmediateOrderById(this.U, this.Order)
        elseif this.Type == 2 then
            call IssueTargetOrderById(this.U, this.Order, this.Target)
        elseif this.Type == 3 then
            call IssuePointOrderById(this.U, this.Order, this.X, this.Y)
        endif
    endmethod

    static method create takes unit U returns OrderHolder
        local OrderHolder OH = OrderHolder.allocate()
        set OH.U = U
        return OH
    endmethod
endstruct
That, of course, is really just the foundations for what you could do, though I think it might work quite nicely.
07-23-2008, 03:30 PM#6
Blubb-Tec
Well, that doesn't solve the problem of getting the unit's current order's target point/unit. I already had this problem too, mainly for aos-spawns in combination with some unit-target teleport item, but I usually stored the unit's next target anyway, so I didn't have to do much...
Well, I suggest you either do the same for your units(saving the order when it is issued, using events), or you check what the function constant native GetUnitRallyPoint takes unit whichUnit returns location does. (Dunno if it is for the current order or for the order given to units when they spawn from a building...)
If that function works, Pyro's OrderHolder.StoreOrder() wouldn't require any arguments anymore, since the target unit is already given to the struct when the .create() is done.
07-23-2008, 04:47 PM#7
Troll-Brain
The rally point is just for units have the ability 'ARal' like the buildings.
And that's pretty useless, because if an unit has this ability then she stop when you set the rally point or do a right click.
There is a system here, it's not perfect, but we can't do better anyway.
http://www.hiveworkshop.com/forums/f...riggers-84857/
07-27-2008, 06:30 AM#8
Pyrogasm
I don't see why you couldn't automate getting a unit's current order/target/whatever:
Collapse JASS:
library OrderTracking initializer Init
    globals
        private trigger OrderTrig = null
        private trigger DeathTrig = null
        OrderHolder array OrderHolders[65000]
    endglobals

    struct OrderHolder
        unit U
        integer Order = 0
        integer Type = 0
        real X = 0.00
        real Y = 0.00
        widget Target = null
        OrderHolder Current

        method StoreOrder takes integer Order, widget Target, real X, real Y, boolean ConsiderXY returns nothing
            set this.Order = Order

            if ConsiderXY == false and handle == null then
                set this.Type = 1
            elseif ConsiderXY == false and handle != null then
                set this.Type = 2
                set this.Target = Target
            elseif ConsiderXY == true then
                set this.Type = 3
                set this.X = X
                set this.Y = Y
            endif
        endmethod

        method RestoreOrder takes nothing returns nothing
            if this.Type == 1 then
                call IssueImmediateOrderById(this.U, this.Order)
            elseif this.Type == 2 then
                call IssueTargetOrderById(this.U, this.Order, this.Target)
            elseif this.Type == 3 then
                call IssuePointOrderById(this.U, this.Order, this.X, this.Y)
            endif
        endmethod

        static method create takes unit U returns OrderHolder
            local OrderHolder OH = OrderHolder.allocate()
            set OH.U = U
            set OH.Current = OrderHolder.allocate()
            set OH.Current.U = U
            return OH
        endmethod
    endstruct

    private function H2I takes handle H returns integer
        return H
        return 0
    endfunction

    private function SetOrders takes nothing returns boolean
        local unit U = GetTriggerUnit()
        local integer Index = H2I(U)-0x100000
        local OrderHolder OH = OrderHolders[Index]

        if OH == 0 then
            set OH = OrderHolder.create(U)
            set OrderHolders[Index] = OH
        endif

        call OH.Current.StoreOrder(GetIssuedOrderId(), GetOrderTarget(), GetOrderPointX(), GetOrderPointY(), GetTriggerEventId() == EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)

        set U = null
        return false
    endfunction

    private function Death takes nothing returns boolean
        call OrderHolders[H2I(GetTriggerUnit)-0x100000].destroy()
        return false
    endfunction

    private function Init takes nothing returns nothing
        set OrderTrig = CreateTrigger()
        set DeathTrig = CreateTrigger()

        call TriggerRegisterAnyUnitEventBJ(OrderTrig, EVENT_PLAYER_UNIT_ISSUED_ORDER)
        call TriggerRegisterAnyUnitEventBJ(OrderTrig, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
        call TriggerRegisterAnyUnitEventBJ(OrderTrig, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
        call TriggerRegisterAnyUnitEventBJ(OrderTrig, EVENT_PLAYER_UNIT_DEATH)

        call TriggerAddCondition(OrderTrig, Condition(function SetOrders))
        call TriggerAddCondition(DeathTrig, Condition(function Death))
    endfunction
endlibrary