• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Order Tracking - Submission

Status
Not open for further replies.
Although this has already been done, I would like to present the code with the character conversion.


Mission Performed: Order Tracking

Code

Description

Credits


Order Tracking Trigger (done in JASS)
JASS:
    // Prints to a certain player
    function PrintTo takes player p, string s, real dur returns nothing
        call DisplayTimedTextToPlayer(p, 0, 0, dur, s)
    endfunction
 
    // Prints to all players
    function Print takes string s returns nothing
        call PrintTo(GetLocalPlayer(), s, (StringLength(s) * 0.3 + 1.5))
    endfunction
 
    // Main Order tracking ConditionFunc
    function Order_Tracker_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local eventid eventId = GetTriggerEventId()
        local integer order = GetIssuedOrderId()
        local string orderStr = OrderId2String(order)
        local player u_p = GetTriggerPlayer()
 
        local unit u_targ
        local destructable d_targ
        local item i_targ
 
        call PrintTo(u_p, "Ordered Unit: " + GetUnitName(u), 2.5)
        // legacy part...
        //call PrintTo(u_p, "unit type of Ordered Unit: " + Int2Char(GetUnitTypeId(u)), 3.)
        call PrintTo(u_p, "Owner of Ordered Unit: " + GetPlayerName(u_p), 2.5)
        call PrintTo(u_p, "Issued Order: " + orderStr, 3.5)
        call PrintTo(u_p, "Id of issued Order: " + I2S(order), 4.5)
 
        if eventId == EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER then
            call PrintTo(u_p, "Input coordinates: X(" + R2SW(GetOrderPointX(), 1, 1) + "), Y(" + R2SW(GetOrderPointY(), 1, 1) + ")", 5.5)
        elseif eventId == EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER then
            call PrintTo(u_p, "Event target is ambiguous", 4.5)
 
            set u_targ = GetOrderTargetUnit()
            set i_targ = GetOrderTargetItem()
            set d_targ = GetOrderTargetDestructable()
 
            if u_targ != null then
                call PrintTo(u_p, "Target(Unit) of Issued Order: " + GetUnitName(u_targ), 5.5)
            elseif i_targ != null then
                call PrintTo(u_p, "Target(Item) of Issued Order: " + GetItemName(i_targ), 5.5)
            elseif d_targ != null then
                call PrintTo(u_p, "Target(Destructable) of Issued Order: " + GetDestructableName(d_targ), 5.5)
            endif
 
            set u_targ = null
            set i_targ = null
            set d_targ = null
        elseif eventId == EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER then
            call PrintTo(u_p, "Event target is specific to unit only", 3.5)
            call PrintTo(u_p, "Target Unit of Issued Order: " + GetUnitName(GetOrderTargetUnit()), 3.5)
        endif
        set u_p = null
        set eventId = null
        set u = null
    endfunction

    // Activates and Deactivates the trigger.
    function Order_Tracker_Chat takes nothing returns nothing
        if GetEventPlayerChatString() == "-toggle" then
            if IsTriggerEnabled(gg_trg_Order_Tracker) then
                call DisableTrigger(gg_trg_Order_Tracker)
                call PrintTo(Player(0), "Order Id tracking is turned off", 2.)
            else
                call EnableTrigger(gg_trg_Order_Tracker)
                call PrintTo(Player(0), "Order Id tracking is turned back on!", 2.)
            endif
        else
            call ClearTextMessages()
        endif
    endfunction
 
    //===========================================================================
    function InitTrig_Order_Tracker takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        set gg_trg_Order_Tracker = CreateTrigger()
        loop
            exitwhen i > bj_MAX_PLAYER_SLOTS
            call TriggerRegisterPlayerUnitEvent(gg_trg_Order_Tracker, Player(i), EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(gg_trg_Order_Tracker, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(gg_trg_Order_Tracker, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(gg_trg_Order_Tracker, Player(i), EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER, null)
            set i = i + 1
        endloop
        // Why I use Filter instead of Condition is due to Bribe using it... (it is 3 bytes shorter)
        call TriggerAddCondition(gg_trg_Order_Tracker, Filter(function Order_Tracker_Actions))
 
        call TriggerRegisterPlayerChatEvent(t, Player(0), "-toggle", true)
        call TriggerRegisterPlayerChatEvent(t, Player(0), "-clear", true)
        call TriggerAddCondition(t, Filter(function Order_Tracker_Chat))
 
        call Print("Order tracking is enabled by default.")
        call Print("To disable it, type \"-toggle\" as your message and press enter")
        call Print("To enable it, type \"-toggle\" as done above\n")
        call Print("To clear messages, type \"-clear\".")
        set t = null
    endfunction


Order tracking is the act of tracking orders through a trigger. It has a lot of uses, from debugging, to making Phantom Rush (Phantom Lancer, DotA) possible, even to making a Nydus Canal in Warcraft 3 (to be done).

Q: Why is the Character library present?
A: Legacy Answer: {It is to show you the (Usually 7) 8-bit ASCII that represents the units, destructables, items, abilities and even orders. On another note, this one is really not necessary for the tracking of orders but it could help typecast integers into characters.}
It has been moved to the Auxiliary Tab

Q: Why did you write the Character library?
A; ..., that part is just optional... (was mandatory to me, though)

Q: Where is the order tracker?
A: It is found below the label "Order Tracking Trigger"


Thanks to Aniki for the string mapping function.

 

Attachments

  • Order Tracker.w3x
    19.1 KB · Views: 46
Last edited:
Level 13
Joined
Nov 7, 2014
Messages
571
You don't really need a library to convert integers to object ids, a simple function is just fine:
JASS:
function to_base_256 takes integer i returns string
    local string map = "................................ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."
    local string result = ""
    local integer t
    local integer d
    loop
        exitwhen i == 0
        set t = i / 256
        set d = i - t*256
        set result = SubString(map, d, d + 1) + result
        set i = t
    endloop
    return result
endfunction
 
Status
Not open for further replies.
Top