• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

GetWidgetName

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Can I just use GetUnitName or is there something else i have to do?

e/ GetUnitName throws "cannot convert widget to unit" well why the hell not
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I believe it can't because of the way wc3 saves / interpretes the units / widgets. I thought I saw a get item name but I can't be sure as I am not near my pc right now

nvm got it to work

JASS:
globalls
    private unit temp
    private destructable tempd
    private item tempi
    private Table t
endglobals
function Widget2Unit takes widget w returns unit
    set t.widget[0] = w
    set temp = t.unit[0]
    call t.flush()
    return temp
endfunction
function Widget2Destructable takes widget w returns destructable
    set t.widget[0] = w
    set tempd = t.destructable[0]
    call t.flush()
    return tempd
endfunction
function Widget2Item takes widget w returns item
    set t.widget[0] = w
    set tempi = t.item[0]
    call t.flush()
    return tempi
endfunction
function GetWidgetType takes widget w returns integer
    set t.widget[0] = w
    if t.unit[0] != null then
        call t.flush()
        return 1
    elseif t.item[0] != null then
        call t.flush()
        return 2
    elseif t.destructable[0] != null then
        call t.flush()
        return 3
    endif
    return 0
endfunction
function GetWidgetName takes widget w returns string
    local integer i = GetWidgetType(w)
    if i == 1 then
        return GetUnitName(Widget2Unit(w))
    elseif i == 2 then
        return GetItemName(Widget2Item(w))
    elseif i == 3 then
        return GetDestructableName(Widget2Destructable(w))
    else
        return "Failed"
    endif
endfunction

seems to work as far as i care

e/ why wont TriggerRegisterAnyUnitEventBJ(,EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER) function for issues on destructibles & items?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I'm guessing its just because its a player unit event.

Its detecting the unit issuing an order.

Wether or not the order is on a unit, a point, an item, etc. should not matter

i guess i'll rephrase it: how do i catch unit orders on widgets?

e/ herp.

EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER -> EVENT_PLAYER_UNIT_ISSUED_ORDER

2E/ Nevermind, it just felt like trolling me. ISSUED_ORDER wouldn't work so i switched it to ISSUED_UNIT_ORDER and it worked fine
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
GetObjectName

Though this only retrieves object's names via raw data.

You can also use typecasting.

That would require knowing wether the unit is a destructable, unit, or item because you need to convert the id (theres no GetWidgetTypeId) which would make it longer than my trigger :p
 
e/ why wont TriggerRegisterAnyUnitEventBJ(,EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER) function for issues on destructibles & items?

You should use:
JASS:
constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER      = ConvertPlayerUnitEvent(40)
Instead. EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER is mostly just for compatibility with older maps that might've used it. They added the target order event in a patch iirc.

You use GetOrderTarget() to get the target. It returns a widget. There are also other event responses:
JASS:
constant native GetOrderTargetDestructable  takes nothing returns destructable
constant native GetOrderTargetItem          takes nothing returns item
constant native GetOrderTargetUnit          takes nothing returns unit
If I'm not mistaken, you should be able to check which one isn't null to figure out whether it is a unit, destructable, or item that was targeted. Someone made a script for it a while back, I can't find it though.

EDIT: Found it:
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-order-types-169593/
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
You should use:
JASS:
constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER      = ConvertPlayerUnitEvent(40)
Instead. EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER is mostly just for compatibility with older maps that might've used it. They added the target order event in a patch iirc.

You use GetOrderTarget() to get the target. It returns a widget. There are also other event responses:
JASS:
constant native GetOrderTargetDestructable  takes nothing returns destructable
constant native GetOrderTargetItem          takes nothing returns item
constant native GetOrderTargetUnit          takes nothing returns unit
If I'm not mistaken, you should be able to check which one isn't null to figure out whether it is a unit, destructable, or item that was targeted. Someone made a script for it a while back, I can't find it though.

EDIT: Found it:
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-order-types-169593/

EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER wont work for my map, as none of the events are getting registered. EVENT_PLAYER_UNIT_ISSUED_TARGET_UNIT_ORDER works fine on the other hand. :\
 
Status
Not open for further replies.
Top