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

Retreiving a unit's ID

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright so basicaly a spell is cast targeting a unit, my trigger detects when the spell is cast. I want to set the target units "Id" to a string variable. And damage it later.

Basicaly I want to know 3 things, do units, when they are on the map walking around and such, have a unique number/string/variation that is specific to that one unit. How would I retreive it and set it to a variable. And how would I later do for example, damage "X" unit for 200. All ideas would be helpful.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

Returns h's handle id. However, the problem with this is that the backwards (I2H) function is rather unstable and a bad idea to use, so only handle to integer conversions should be used.

You could always use an allocation algorithm to set their custom value to a unique idea, for example:

JASS:
globals
    integer CurrentIndex = 0
    integer MaxIndex = 0
    integer array LastIndexes
endglobals

function Allocate takes nothing returns integer
    local integer new = CurrentIndex
    if new == 0 then
        set MaxIndex = MaxIndex + 1
        set new = MaxIndex
    else
        set CurrentIndex = LastIndexes[CurrentIndex]
    endif
    set LastIndexes[new] = -1
    return new
endfunction

function Deallocate takes integer out returns nothing
    set LastIndexes[out] = CurrentIndex
    set CurrentIndex = out
endfunction

In this case, you could just have a unit array which stored the units via that number.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Ah poot, always answering my questions lol. I think I will use the array version, I was thinking about it earlier. Thanks for the advice about the I2H to.

EDIT: Man o man nest, that is some... sweet shit lol. Still not sure how I would go about it exactly though, pretty complex. And I'm working in GUI here so that would be a large hindrance (really should get around to learning jass I keep starting to read tutorials then end up listening to music lol >.>).

EDIT2: Rofl, you dominated your paragraph lol =O.
 
Status
Not open for further replies.
Top