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

[JASS] Unit name from integer unitid?

Status
Not open for further replies.
Level 2
Joined
Jan 20, 2008
Messages
7
Is there possibility to get unit name from integer unitid? I've wrote a function which will spawn creeps and it takes as a parameter unitid (integer) of creep because CreateUnitAtLoc is using it. I would like to have a possibility to display for players what kind of creep it will be, ie. "Next wave: Footman", not "Next wave: hfoo" :hohum:

I can't use GetUnitName because it needs handle to unit, not unitid. I'm browsing trough functions but I haven't found anything useful. It could be done by creating unit, getting name and removing that unit - but to create unit only for getting it's name is a little bit pointless.
 
Level 1
Joined
Jan 19, 2008
Messages
6
JASS:
constant function StringNum takes nothing returns string
    return "0123456789"
endfunction
constant function StringABC takes nothing returns string
    return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
endfunction
constant function Stringabc takes nothing returns string
    return "abcdefghijklmnopqrstuvwxyz"
endfunction
function S2ID takes string source returns integer
    local integer Id = 0
    local integer n1 = 1
    local integer n2 = 1
    loop
        exitwhen(n1>StringLength(source))
        loop
            exitwhen(n2>10)
            if(SubString(source,n1-1,n1)==SubString(StringNum(),n2-1,n2))then
                set Id=Id+R2I(('0'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
                set n2=n2+1
            else
                set n2=n2+1
            endif                
        endloop
        set n2=1
        loop
            exitwhen(n2>26)
            if(SubString(source,n1-1,n1)==SubString(StringABC(),n2-1,n2))then
                set Id=Id+R2I(I2R('A'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
                set n2=n2+1
            else
                set n2=n2+1
            endif                
        endloop
        set n2=1
        loop
            exitwhen(n2>26)
            if(SubString(source,n1-1,n1) == SubString(Stringabc(),n2-1,n2))then
                set Id=Id+R2I(('a'+n2-1)*Pow(256.00,I2R(StringLength(source)-n1)))
                set n2=n2+1
            else
                set n2=n2+1
            endif                
        endloop
        set n2=1
        set n1=n1+1
    endloop
    return Id
endfunction
function ID2S takes integer int returns string
    local string target=""
    local integer n=0
    local integer dis=0
    loop
        exitwhen(int==0)
        set n=ModuloInteger(int,256)
        if(n>='0' and n<='9')then
            set dis=n-'0'
            set target=SubString(StringNum(),dis,dis+1)+target
        endif
        if(n>='A' and n<='Z')then
            set dis=n-'A'
            set target=SubString(StringABC(),dis,dis+1)+target
        endif
        if(n>='a' and n<='z')then
            set dis=n-'a'
            set target=SubString(Stringabc(),dis,dis+1)+target
        endif
        set int=int/256
    endloop
    return target
endfunction
If use ID2S('hfoo'), it will display "hfoo", not 'hfoo'.

and, S2ID("hfoo") --> 'hfoo'
 
Level 2
Joined
Jan 20, 2008
Messages
7
CreateUnitAtLocByName
It is still using some kind of internal unit names... To create Footman I need to specify "footman" - I can't use unit name.

UnitId2String
It gives me "footman", but I tought it would be "Piechur" (It's Footman in polish:xxd:)

feelerly, I think that you missunderstanded me.

I have a function
JASS:
function SpawnCreep takes integer Creep, integer CreepCount, rect SpawnRegion returns nothing

After creating custom unit based on ie. Undead Ghoul it's unitid will be something like 'u000' and it's "Text - Name" I would set to, let's say "Ghoulish creep". Now if I want to spawn some creeps using my function I would pass 'u000' as a parameter to CreateUnitAtLoc - and Ghoulish creeps are spawning.

But what I want to achieve is to get this "Ghoulish creep" name before spawning and display it to players, so they would know what will spawn in few seconds. As for now only function that I'm aware of and that could get this name is GetUnitName but I need a unit handle as a parameter - not integer unitid.

I can do what I want this way (Creep = 'u000')
JASS:
local unit DummyCreep
set DummyCreep = CreateUnitAtLocByName(Player(11), Creep, SpawnPoint, 270)
call DisplayTextToForce(GetPlayersAll(), GetUnitName(DummyCreep)) // yuhu! it's "Ghoulish creep"
call DisplayTextToForce(GetPlayersAll(), UnitId2String(Creep)) // it's "custom_u000"
call DisplayTextToForce(GetPlayersAll(), ID2S(Creep)) // it's "u000"
call RemoveUnit(DummyCreep)

But, as I said, creating new unit only to get it's name it's a little bit pointless - but if there is no other way then I would do it that way.
 
Level 1
Joined
Jan 19, 2008
Messages
6
oh,I see l.
id name of custom unit will get string ahead of "custom_xxx". let me do some case...
if want get name of unit before spawning, you could likes this:

local unit DummyCreep

set udg_Creep[ 1 ] = 'hfoo'
set udg_Creep[ 2 ] = 'u000'

call DisplayTextToForce(GetPlayersAll(), GetObjectName(Creep[1])) // yee, it is name of id ( Creep[1] ) .
set DummyCreep = CreateUnitAtLocByName(Player(11), Creep[1],
SpawnPoint, 270)

well, i am offline...bye
 
Status
Not open for further replies.
Top