• 🏆 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!

[JASS] Why wont the builder stop?

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
globals
    private constant integer WHEATFARM_ID = 'halt'

    private constant integer STOP = 851972
    
    private constant real GRANARY_MAXRANGE = 800.
    private boolexpr GRANARY_BOOL
    
    private group TempGroup = CreateGroup()
    private unit TempUnit
endglobals

private function WHEATFARM_CHECK takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer id = GetIssuedOrderId()
    local real x = GetOrderPointX()
    local real y = GetOrderPointY()
    
    if id == WHEATFARM_ID then
    
        call GroupEnumUnitsInRange(TempGroup,x,y,GRANARY_MAXRANGE,GRANARY_BOOL)
        
        set TempUnit = FirstOfGroup(TempGroup)
        
        if TempUnit == null then
            call IssueImmediateOrderById(u,STOP) //Why wont this stop the unit? the order is correct
            call DisplayTimedTextToPlayer(GetOwningPlayer(u),0,0,10,"Must build a Wheat farm within 800 yd of a grannary")
        endif
        
    endif
    
    set u = null
endfunction

private function Init_Trig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
    call TriggerAddAction(trig,function WHEATFARM_CHECK)
    
    set GRANARY_BOOL = Filter(function WEATHFARM_FILTER)
endfunction

It will display the text msg by it wont stop the builder, whys that?

I'v tried the order id in an other trigger and it worked..

So what is the problem here?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The event causes the code to run before the unit is physically given the order.

Thus how the orders are executing is.

Response to unit order is issued.
Unit order is issued.

Basically, the order you are responding to overwrites the order you want to execute.
To fix you will have to delay the response order 0 seconds via a timer (yes 0 is valid and near instantanious but still a delay) so that it executes after the oder it is responding to is given.
 
Status
Not open for further replies.
Top