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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top