1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Putting hero icon on multiboard

Discussion in 'Triggers & Scripts' started by Saishy, Feb 18, 2009.

  1. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    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?
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  3. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    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
     
  4. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    How does Hash Table works?
    I know Table uses integer...
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,547
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    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.
     
  6. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    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!
     
  7. spiwn

    spiwn

    Joined:
    Apr 27, 2008
    Messages:
    1,228
    Resources:
    0
    Resources:
    0
    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:
    Code (vJASS):
    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.
     
  8. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    My heroes have both letters or numbers as the last char.
     
  9. spiwn

    spiwn

    Joined:
    Apr 27, 2008
    Messages:
    1,228
    Resources:
    0
    Resources:
    0
    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.
     
  10. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    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
     
  11. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0


    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 ^^
     
  12. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    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
     
  13. Akolyt0r

    Akolyt0r

    Joined:
    Dec 20, 2008
    Messages:
    53
    Resources:
    3
    Icons:
    3
    Resources:
    3
    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:
    Code (vJASS):

    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..
    Code (vJASS):

    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