• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Get Unit Icon Path?

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
Hi everybody, I am currently making a custom ui that uses my own way of displaying the enemy's hp and icon:

1619273501511.png

1619273542628.png



Currently the way I use to change the texture of the backdrop(icon) is by storing the following data and looping though them to check which unit type it is:

  • Enemy Bars Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet i = 1
      • Set VariableSet Bar_Unit_Type[i] = test 1
      • Set VariableSet Bar_Unit_Path[i] = ReplaceableTextures\CommandButtons\BTNFootman.tga
      • -------- - --------
      • Set VariableSet i = (i + 1)
      • Set VariableSet Bar_Unit_Type[i] = test 2
      • Set VariableSet Bar_Unit_Path[i] = ReplaceableTextures\CommandButtons\BTNRifleman.tga
      • -------- - --------
      • Set VariableSet i = (i + 1)
      • Set VariableSet Bar_Unit_Type[i] = test 3
      • Set VariableSet Bar_Unit_Path[i] = ReplaceableTextures\CommandButtons\BTNGrunt.tga
      • -------- - --------
      • Set VariableSet i = (i + 1)
      • Set VariableSet Bar_Unit_Type[i] = Tauren Chieftain
      • Set VariableSet Bar_Unit_Path[i] = ReplaceableTextures\CommandButtons\BTNHeroTaurenChieftain.tga
      • -------- - --------
      • Set VariableSet i = (i + 1)
      • Set VariableSet Bar_Unit_Type[i] = Blood Mage
      • Set VariableSet Bar_Unit_Path[i] = ReplaceableTextures\CommandButtons\BTNHeroBloodElfPrince.tga
      • -------- - --------
      • Set VariableSet Bar_Unit_Max = i
      • -------- - --------
This is a bit of a hassle when having to do with over 100 units in an RPG Map, so I thought of using a simple method to get the Unit Name:
  • select unit name
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Custom script: local framehandle char = BlzGetFrameByName("CharacterIcon" , 0)
      • -------- ------------------------- --------
      • -------- Check to see if there is "space" in unit name and remove it e.g Mountain Giant --------
      • Set VariableSet UnitName = (Name of (Triggering unit))
      • For each (Integer i) from 1 to (Length of UnitName), do (Actions)
        • Loop - Actions
          • Game - Display to (All players) for 5.00 seconds the text: (i + ((String(i)) + (: + (Substring(UnitName, i, i)))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring(UnitName, i, i)) Equal to
            • Then - Actions
              • Set VariableSet UnitName = ((Substring(UnitName, 1, (i - 1))) + (Substring(UnitName, (i + 1), 20)))
              • Game - Display to (All players) for 5.00 seconds the text: (Found "space" in + (String(i)))
            • Else - Actions
      • Game - Display to (All players) for 5.00 seconds the text: (Final result: + UnitName)
      • -------- ------------------------- --------
      • -------- Check to see if unit is a hero. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A Hero) Equal to True
        • Then - Actions
          • Set VariableSet UnitName = (ReplaceableTextures\CommandButtons\BTNHero + (UnitName + .blp))
        • Else - Actions
          • Set VariableSet UnitName = (ReplaceableTextures\CommandButtons\BTN + (UnitName + .blp))
      • -------- ------------------------- --------
      • Custom script: call BlzFrameSetTexture(char, udg_UnitName ,0, true)
Although this only works with default unit names...if a unit has a custom name it doesn't get the correct icon path.

It really is a shame that this trigger can't get a unit's icon path:
1619274021257.png


So I came here to ask if it's possible using JASS to directly get a unit's icon path OR if there is a better way to do this in general.
 

Attachments

  • Get Unit Name.w3m
    10.1 KB · Views: 32
Status
Not open for further replies.
Top