• 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.

GetUnitId() integer to Unit Id ?

Status
Not open for further replies.
Level 8
Joined
Jul 10, 2008
Messages
353
I wanna translate the integer that the GetUnitId() produce to the actual unit id (example, u001).

Is there any function or known snippet that does it?
 

AGD

AGD

Level 16
Joined
Mar 29, 2016
Messages
688
Is there any function or known snippet that does it?
You mean the rawcode(unit-type) right?

If you want it in integer, you can simply use GetUnitTypeId(unit) but if you want it in string, this should do it BJObjectId.
JASS:
local string s = BJObjectId(GetUnitTypeId(unit)).to_str()
There you have it =)
 
Raw codes are just integers represented in ASCII (base 64).

[Snippet] Ascii

There is also a function in the Cheats.j file which does this.

JASS:
function DebugIdInteger2IdString takes integer value returns string
    local string charMap = ".................................!.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."
    local string result = ""
    local integer remainingValue = value
    local integer charValue
    local integer byteno

    set byteno = 0
    loop
        set charValue = ModuloInteger(remainingValue, 256)
        set remainingValue = remainingValue / 256
        set result = SubString(charMap, charValue, charValue + 1) + result

        set byteno = byteno + 1
        exitwhen byteno == 4
    endloop
    return result
endfunction
 
Status
Not open for further replies.
Top