Snippet PrintOrders

Troll-Brain

You can change this now in User CP.
Reaction score
85
@quraji
Read more carefully.

I'm agree theses inlines are useless, cause TriggerRegisterAnyUnitEventBJ is just fine most of the time, and BJDebugMsg is also fine here.
But since he had already inline these ones, i was wondering why he didn't inline also ModuloInteger which can be done in one line.
 

Azlier

Old World Ghost
Reaction score
461
SQRUAAAAAK!

You have made me angry, and so I have inlined ModuloInteger in my fury!
 

quraji

zap
Reaction score
144
@quraji
Read more carefully.

I'm agree theses inlines are useless, cause TriggerRegisterAnyUnitEventBJ is just fine most of the time, and BJDebugMsg is also fine here.
But since he had already inline these ones, i was wondering why he didn't inline also ModuloInteger which can be done in one line.

I read more carefully, but I still don't see where you say that.
Just being difficult :p
 

Azlier

Old World Ghost
Reaction score
461
That's a very good question. I fixed it a while ago and never changed it back...

How odd.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Display an integer with the format 'XXXX' would be neater than hexadecimal.
Go requires the Ascii library :D
 

Azlier

Old World Ghost
Reaction score
461
I can't seem to get ASCII conversion to work.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
The functions Rawcode2String and String2Rawcode should be included inside the library, but anyway it only works when the issued order is also a valid rawcode (like training units orders).

Maybe you could check if the result string is valid and then display it ?
 

Azlier

Old World Ghost
Reaction score
461
Well, if it only works for rawcodes, then that's pretty useless to me.
 

Azlier

Old World Ghost
Reaction score
461
Meh.

Now has support for (de)activating the system in-game. It will also possibly cause desyncs in multiplayer. Just possibly. :p

EDIT:

What do you guys think of this? It prints normal orders in hex, and stuff like training and upgrade orders in ASCII. It can also optionally display information on the target of an order.

JASS:
library PrintOrders initializer Init requires Ascii

//Config
globals
    private constant boolean CLEAR_BEFORE_PRINTING = false
    //Setting this to true will clear the screen of text messages when printing order data.
    
    private constant string ACTIVATE = "-printon"
    //Typing this in-game will activate PrintOrder (it is activated by default).
    private constant string DEACTIVATE = "-printoff"
    //Typing this in-game will deactivate PrintOrder.
    
    private constant boolean DISPLAY_TARGET_INFO = false
    //When flipped to true, the system will display information on targets of orders.
endglobals
//End config

globals
    private string array Hex_Values
    private trigger t1 = CreateTrigger()
    private trigger t2 = CreateTrigger()
    private trigger t3 = CreateTrigger()
    private constant integer OFFSET = 0xD0000
endglobals
 
private function Int2HexString takes integer i returns string
    local string hex = ""
    local integer r = 0
    local string neg = ""
    if (i<0) then
        set neg = "-"
        set i = -i
    endif
    loop
        set r = i - (i / 16) * 16
        set i = i/16
        set hex = Hex_Values[r] + hex
        exitwhen (i==0)
    endloop
    return neg+hex
endfunction

private function Rawcode2String takes integer i returns string
    local string c = ""
    loop
        exitwhen i == 0
        set c = Ascii2Char(i - (i / 256) * 256)+c
        set i = i / 256
    endloop
    return c
endfunction

private function Target takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    static if DISPLAY_TARGET_INFO then
        local string n
    endif
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    
    static if DISPLAY_TARGET_INFO then
        if GetOrderTargetUnit() != null then
            set n = GetUnitName(GetOrderTargetUnit())
        elseif GetOrderTargetDestructable() != null then
            set n = GetDestructableName(GetOrderTargetDestructable())
        else
            set n = GetItemName(GetOrderTargetItem())
        endif
        
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target object order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\nTarget name: " + n + "\nTarget handle id: " + /*
        */I2S(GetHandleId(GetOrderTarget())) + "\n\n")
    else
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target object order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    endif
    
    return false
endfunction

private function Point takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    
    static if DISPLAY_TARGET_INFO then
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target point order at (" + R2S(GetOrderPointX()) + "," + R2S(GetOrderPointY()) + ")"/*
        */ + ".\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    else
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target point order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    endif
    
    return false
endfunction

private function Order takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
    */" issued order with no target.\n  OrderId: " + s + "\n  order name: " +/*
    */OrderId2String(GetIssuedOrderId()) + "\n\n")
    return false
endfunction

private function Activate takes nothing returns boolean
    call EnableTrigger(t1)
    call EnableTrigger(t2)
    call EnableTrigger(t3)
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "PrintOrder activated.")
    return false
endfunction

private function Deactivate takes nothing returns boolean
    call DisableTrigger(t1)
    call DisableTrigger(t2)
    call DisableTrigger(t3)
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "PrintOrder deactivated.")
    return false
endfunction

private function Init takes nothing returns nothing
    static if DEBUG_MODE then
    local integer i = 15
    
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, GetLocalPlayer(), ACTIVATE, true)
    call TriggerAddCondition(t, Condition(function Activate))
    
    set t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, GetLocalPlayer(), DEACTIVATE, true)
    call TriggerAddCondition(t, Condition(function Deactivate))

    loop
        call TriggerRegisterPlayerUnitEvent(t1, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
        call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
        call TriggerRegisterPlayerUnitEvent(t3, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
        exitwhen i == 0
        set i = i - 1
    endloop
    call TriggerAddCondition(t1, Filter(function Target))
    call TriggerAddCondition(t2, Filter(function Point))
    call TriggerAddCondition(t3, Filter(function Order))
    set Hex_Values[0] = "0"
    set Hex_Values[1] = "1"
    set Hex_Values[2] = "2"
    set Hex_Values[3] = "3"
    set Hex_Values[4] = "4"
    set Hex_Values[5] = "5"
    set Hex_Values[6] = "6"
    set Hex_Values[7] = "7"
    set Hex_Values[8] = "8"
    set Hex_Values[9] = "9"
    set Hex_Values[10] = "A"
    set Hex_Values[11] = "B"
    set Hex_Values[12] = "C"
    set Hex_Values[13] = "D"
    set Hex_Values[14] = "E"
    set Hex_Values[15] = "F"
    
    endif
endfunction

endlibrary
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
You should test if it desynchronises or not :p
Saving some lines of code/triggers whatever, is totally irrelevant comparing to a such issue.

Also not your fault, but it's annoying that you have to declare your own Rawcode2String function.

You don't need several triggers, just use GetTriggerEventId.

I think you should also include the possibility to add a player name, if a player try to activate/deactivate and doesn't have the right name, then do nothing (yeah i know we have spoofers ...).
However, i found this idea rather silly, in a debug mode only one constant player should be able to do this, and not on a released map.
 

quraji

zap
Reaction score
144
Meh.

Now has support for (de)activating the system in-game. It will also possibly cause desyncs in multiplayer. Just possibly. :p

JASS:
library PrintOrders initializer Init requires Ascii

//Config
globals
    private constant boolean CLEAR_BEFORE_PRINTING = false
    //Setting this to true will clear the screen of text messages when printing order data.
    
    private constant string ACTIVATE = "-printon"
    //Typing this in-game will activate PrintOrder (it is activated by default).
    private constant string DEACTIVATE = "-printoff"
    //Typing this in-game will deactivate PrintOrder.
    
    private constant boolean DISPLAY_TARGET_INFO = false
    //When flipped to true, the system will display information on targets of orders.
endglobals
//End config

globals
    private string array Hex_Values
    private trigger t1 = CreateTrigger()
    private trigger t2 = CreateTrigger()
    private trigger t3 = CreateTrigger()
    private constant integer OFFSET = 0xD0000
endglobals
 
private function Int2HexString takes integer i returns string
    local string hex = ""
    local integer r = 0
    local string neg = ""
    if (i<0) then
        set neg = "-"
        set i = -i
    endif
    loop
        set r = i - (i / 16) * 16
        set i = i/16
        set hex = Hex_Values[r] + hex
        exitwhen (i==0)
    endloop
    return neg+hex
endfunction

private function Rawcode2String takes integer i returns string
    local string c = ""
    loop
        exitwhen i == 0
        set c = Ascii2Char(i - (i / 256) * 256)+c
        set i = i / 256
    endloop
    return c
endfunction

private function Target takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    static if DISPLAY_TARGET_INFO then
        local string n
    endif
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    
    static if DISPLAY_TARGET_INFO then
        if GetOrderTargetUnit() != null then
            set n = GetUnitName(GetOrderTargetUnit())
        elseif GetOrderTargetDestructable() != null then
            set n = GetDestructableName(GetOrderTargetDestructable())
        else
            set n = GetItemName(GetOrderTargetItem())
        endif
        
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target object order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\nTarget name: " + n + "\nTarget handle id: " + /*
        */I2S(GetHandleId(GetOrderTarget())) + "\n\n")
    else
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target object order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    endif
    
    return false
endfunction

private function Point takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    
    static if DISPLAY_TARGET_INFO then
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target point order at (" + R2S(GetOrderPointX()) + "," + R2S(GetOrderPointY()) + ")"/*
        */ + ".\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    else
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
        */" issued target point order.\n  OrderId: " + s + "\n  order name: " +/*
        */OrderId2String(GetIssuedOrderId()) + "\n\n")
    endif
    
    return false
endfunction

private function Order takes nothing returns boolean
    local integer order = GetIssuedOrderId()
    local string s
    if order - OFFSET < 8191 then
        set s = "0x" + Int2HexString(order)
    else
        set s = "'" + Rawcode2String(order) + "'"
    endif
    static if CLEAR_BEFORE_PRINTING then
        call ClearTextMessages()
    endif
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetTriggerUnit()) +/*
    */" issued order with no target.\n  OrderId: " + s + "\n  order name: " +/*
    */OrderId2String(GetIssuedOrderId()) + "\n\n")
    return false
endfunction

private function Activate takes nothing returns boolean
    call EnableTrigger(t1)
    call EnableTrigger(t2)
    call EnableTrigger(t3)
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "PrintOrder activated.")
    return false
endfunction

private function Deactivate takes nothing returns boolean
    call DisableTrigger(t1)
    call DisableTrigger(t2)
    call DisableTrigger(t3)
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "PrintOrder deactivated.")
    return false
endfunction

private function Init takes nothing returns nothing
    static if DEBUG_MODE then
    local integer i = 15
    
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, GetLocalPlayer(), ACTIVATE, true)
    call TriggerAddCondition(t, Condition(function Activate))
    
    set t = CreateTrigger()
    call TriggerRegisterPlayerChatEvent(t, GetLocalPlayer(), DEACTIVATE, true)
    call TriggerAddCondition(t, Condition(function Deactivate))

    loop
        call TriggerRegisterPlayerUnitEvent(t1, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
        call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
        call TriggerRegisterPlayerUnitEvent(t3, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
        exitwhen i == 0
        set i = i - 1
    endloop
    call TriggerAddCondition(t1, Filter(function Target))
    call TriggerAddCondition(t2, Filter(function Point))
    call TriggerAddCondition(t3, Filter(function Order))
    set Hex_Values[0] = "0"
    set Hex_Values[1] = "1"
    set Hex_Values[2] = "2"
    set Hex_Values[3] = "3"
    set Hex_Values[4] = "4"
    set Hex_Values[5] = "5"
    set Hex_Values[6] = "6"
    set Hex_Values[7] = "7"
    set Hex_Values[8] = "8"
    set Hex_Values[9] = "9"
    set Hex_Values[10] = "A"
    set Hex_Values[11] = "B"
    set Hex_Values[12] = "C"
    set Hex_Values[13] = "D"
    set Hex_Values[14] = "E"
    set Hex_Values[15] = "F"
    
    endif
endfunction

endlibrary

I've never tested if this desyncs either. Just put the TriggerRegister...(..., GetLocalPlayer(), ...) lines inside the loop, and be safe. I've never tested if this desyncs either.

However, i found this idea rather silly,

QFT :p
 

Azlier

Old World Ghost
Reaction score
461
If a TriggerEvaluate doesn't desync (which it doesn't), neither should this.

I have no way of testing, and it doesn't matter. :p

>You don't need several triggers, just use GetTriggerEventId.

Meh, if it's already done the efficient way, why change it?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
If a TriggerEvaluate doesn't desync (which it doesn't), neither should this.

I have no way of testing, and it doesn't matter. :p
Evil joke.

Meh, if it's already done the efficient way, why change it?
I would prefer saving some lines of code, instead of some nano seconds of code execution, especially because the point of this is for debug purpouse. :rolleyes:
 

Azlier

Old World Ghost
Reaction score
461
If you're not going to have it in the final release of your map, why change it to have less lines of code?

Code compresses to almost nothing anyway.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
If you're not going to have it in the final release of your map, why change it to have less lines of code?

Code compresses to almost nothing anyway.
The optimisation is in the same way, really really irrelevant here, like the BJ in-lines.
In a general way, i prefer compress code against in-line when speed is totally irrelevant, but i know you hate it for some odd reason.

Anyway, provide a code which could desync, even if you shouldn't release a map with a such code is so lame.
Maybe it doesn't, but at least test it or ask someone to do it for yourself.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top