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

[Trigger] Putting hero icon on multiboard

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
I can't think an easy way to do that.

The only way that I think is looping trough all heroes until find the selected one and them put the icon on the multiboard.
But that way I will need to manually add each icon path string and an IF for EVERY SINGLE hero in the game :(

Any better idea?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
The most efficent way is to store them in a system like a hash table (array) and so you can fetch an icon directly from the hero type integer and thus avoid any loops at all. That is suprizingly fast and so really is no problem.

But that way I will need to manually add each icon path string

Unfortunatly, every way results in you having to do that. Thus you better get used to the idea as WC3 does not let you fetch a unit's icon string via trigger script.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Its the only way which I use

and what is the "LOLZ IVE TO MANUALLLYYYY ADD FOR EACH" ?
Even if you have 500 heroes it wouldnt take 10 minutes
just copy past copy past copy past and finally with Find-Repleace repleace "\"s with "\\"s
 
Level 12
Joined
Mar 23, 2008
Messages
942
The most efficent way is to store them in a system like a hash table (array) and so you can fetch an icon directly from the hero type integer and thus avoid any loops at all. That is suprizingly fast and so really is no problem.

Unfortunatly, every way results in you having to do that. Thus you better get used to the idea as WC3 does not let you fetch a unit's icon string via trigger script.
How does Hash Table works?
I know Table uses integer...
 
Level 12
Joined
Mar 23, 2008
Messages
942
Basically from a hero type integer you are given a unique array index, inwhich to find the string. This avoids any loops as it is a diret method of fetching the string and so is more efficent with lots of heroes.

I didn't understand right.
Could you give me an example in jass?

"I have a unit-type W, that is my hero and the string path X"

Thanks!
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
Basicly he means this:
local integer i=GetUnitTypeID(Some_Unit)

So this would get that ID from the Object editor like 'hfoo' - for a footmen, 'hpea' for a peasant and so on. For a custom hero would be something like 'H010'. Wc3 reads that as an integer.
So we could use something like:
set udg_Icon_Array['hfoo']="string..."

But 'hfoo' is a rather big number. So we have to decrease it a little.
For instance if all your heroes' ids start from 'U000' and go on like 'U001' 'U002' and so on(you should use JNGP for this part). You could do something like this:
JASS:
local integer i=GetUnitTypeID(Some_Unit-'U000')
local string a=udg_Icon_Array[i]
So "i" would be 0,1,2 and so on.

P.s. For when you define the actual path, just use 1,2,3,4 and so on.
 
Level 12
Joined
Mar 23, 2008
Messages
942
Basicly he means this:
local integer i=GetUnitTypeID(Some_Unit)

So this would get that ID from the Object editor like 'hfoo' - for a footmen, 'hpea' for a peasant and so on. For a custom hero would be something like 'H010'. Wc3 reads that as an integer.
So we could use something like:
set udg_Icon_Array['hfoo']="string..."

But 'hfoo' is a rather big number. So we have to decrease it a little.
For instance if all your heroes' ids start from 'U000' and go on like 'U001' 'U002' and so on(you should use JNGP for this part). You could do something like this:
JASS:
local integer i=GetUnitTypeID(Some_Unit-'U000')
local string a=udg_Icon_Array[i]
So "i" would be 0,1,2 and so on.

P.s. For when you define the actual path, just use 1,2,3,4 and so on.

My heroes have both letters or numbers as the last char.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
That does not matter(i.e. 'U00f'-'U00d' should be 2).
The important thing is that your heroes have to have consecutive IDs. That can be achieved with JNGP.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Hero[0] = 'U000'
Hero[1] = 'U001'
etc

Icon[0] = <icon of 'U000'>
Icon[1] = <icon of 'U001'>
etc

function GetIcon takes integer id returns string
local integer i == 0
loop
exitwhen Icon == ""
if Hero == id then
return Icon
endif
set i = i+1
endloop
debug call BJDebugMsg("Warning no icon for "+GetObjectName(id)+" has been found")
endfunction

Im not sure about GetObjectName but there is a function like that as I remember
 
Level 12
Joined
Mar 23, 2008
Messages
942
Hero[0] = 'U000'
Hero[1] = 'U001'
etc

Icon[0] = <icon of 'U000'>
Icon[1] = <icon of 'U001'>
etc

function GetIcon takes integer id returns string
local integer i == 0
loop
exitwhen Icon == ""
if Hero == id then
return Icon
endif
set i = i+1
endloop
debug call BJDebugMsg("Warning no icon for "+GetObjectName(id)+" has been found")
endfunction

Im not sure about GetObjectName but there is a function like that as I remember


I prefer the direct thing than doing a loop to find the hero...
Thanks anyway.

----------------------

@spiwn

Yes, they all have the same 3 char as the first ones.
Thanks for the tip, I also used it with my item system to convert them to tomes ^^
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
I know but its hard to configure it so it wont exceed array limit coz I dont think that there is anyone knows the object id range
 
Level 5
Joined
Dec 20, 2008
Messages
67
best way is to have 2 arrays ...
one with the icon paths
and another one with the hero-unit ids ..so you can do something like this:
JASS:
globals
    constant integer MAXPLAYERS = 12 //update this
    unit array PlayerHero[MAXPLAYERS]    
    constant integer MAXHEROS = 30 //update this
    string array HeroIcons[MAXHEROS]
    integer array HeroIds[MAXHEROS]  
endglobals

function GetHeroIndex takes unit hero returns integer
    local integer j = 0
    loop
        exitwhen j > MAXHEROS
        if GetUnitTypeId(hero)==HeroIds[j] then
            return j
        endif
        set j = j +1
    endloop
    debug call BJDebugMsg("No valid hero")
    return -1
endfunction

function SetupIcons takes multiboard mb returns nothing
    local integer heroId
    local integer i = 0
    local multiboarditem mbitem
    loop
        exitwhen i > MAXPLAYERS
        set mbitem = MultiboardGetItem(mb,i,0)
        call MultiboardSetItemIcon(mbitem,HeroIcons[GetHeroIndex(PlayerHero[i])])
        call MultiboardReleaseItem(mbitem)
        set i = i +1
    endloop
    set mbitem = null
endfunction

you would have to setup the HeroIcons and HeroIds arrays manually of course (example below)...and you would have to setup the PlayerHero array when you create the heros..
JASS:
function SetupHeroVars takes nothing returns nothing
    set HeroIds[0] = 'Hamg' //archmage
    set HeroIcons[0] = "ReplaceableTextures\\CommandButtons\\BTNHeroArchMage.blp"
    set HeroIds[1] = 'Hblm' //bloodmage
    set HeroIcons[1] = "ReplaceableTextures\\CommandButtons\\BTNHeroBloodElfPrince.blp"
    ///...
endfunction
 
Status
Not open for further replies.
Top