Snippet PrintOrders

Azlier

Old World Ghost
Reaction score
461
A simple debugging snippet that I get tired of rewriting for every map.

When a unit is issued an order, it prints some order data. It will print the order ID in hex if it's a normal order, in ASCII if it's a rawcode. It also displays the type of order, the unit that was issued the order, and the name of the order (if any). Optionally, it can also display data on the target of an order if DISPLAY_TARGET_INFO is flipped to true.

Only works in debug mode.

Requires ASCII.

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
 

quraji

zap
Reaction score
144
You could make the order display in hex also, should be shorter to copy down... ;)

JASS:
library Int2HexString initializer init
    // converts an integer into a hex string (255 -> "FF")

globals
    private string array Hex_Values
endglobals

// see any decimal -> hex conversion guide online to see what's done here
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 = ModuloInteger(i,16)
        set i = i/16
        set hex = Hex_Values[r] + hex
        exitwhen (i==0)
    endloop
    return neg+hex
endfunction

private function init takes nothing returns nothing
    // hex values
    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"
endfunction

endlibrary


From my widely used "More String Functions" library of awesome string functions!!
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Static ifs outside functions/methods aren't supported, they are just ignored.
Also there is already a library for this :

http://www.wc3c.net/showthread.php?t=102883

Even if you need to delete the H2I function and change the calling of it by GetHandleId.
And instead of activate/deactivate the library yes it needs static ifs.
 

Azlier

Old World Ghost
Reaction score
461
>Static ifs outside functions/methods aren't supported, they are just ignored.

Whose idea was that? How sad.

>You could make the order display in hex also

I actually thought of that, but thought it would be overkill. Maybe I should actually add it :p.

>Also there is already a library for this

Noooooooo.

Well, I personally won't be using that one because that one is indeed overkill.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Well, I personally won't be using that one because that one is indeed overkill.
Diod's one ?

EDIT :
I've just realized theses constants are totally useless :

JASS:
    private integer TYPE_WHOKNOWS = 0
    
    private integer TYPE_NOTHING  = 1
    private integer TYPE_LOCATION = 2
    private integer TYPE_WIDGET   = 3
    
    private integer TYPE_UNIT         = 4
    private integer TYPE_ITEM         = 5
    private integer TYPE_DESTRUCTABLE = 6


Also there are indeed useless functions like Echo,DEBUG and such.

With your's the BJs inline makes me lol ^^
In fact you still even use a pretty useless one ModuloInteger
 

Azlier

Old World Ghost
Reaction score
461
Yes. /shrug

Usually I just use this to find a specific order id.
 

Azlier

Old World Ghost
Reaction score
461
Well, I've already inlined stuff. Might as well not change it back. But I don't quite feel like inlining ModuloInteger at the moment :eek:.
 

quraji

zap
Reaction score
144
What's wrong with not inlining ModuloInteger? Just makes your code harder to read.

What's wrong with using any BJ that is a decent function (and not just "WhateverSwapped"...those are just stupid)?

I do think you should add the display in hex. It makes it easier to read/write/type. Just make sure you add a note that it does indeed display in hex (and one will need to add the 0x to make it work correctly if they copy one).

EDIT: Oh hey, you did, woops. Hey it's my snippet too! :thup:
 

Azlier

Old World Ghost
Reaction score
461
I already did. I just didn't inline ModuleInteger because I am excessively lazy.
 

quraji

zap
Reaction score
144
I already did. I just didn't inline ModuleInteger because I am excessively lazy.

No reason to do it anyways :p
You should add a note that it displays in hex though. Or just prefix the output with "0x".

EDIT: You did that too....maybe I should look at things sometimes..
 
General chit-chat
Help Users
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • 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!
  • 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

      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