• 🏆 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!

Setting string name of hero

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

Is it possible to set the string name of a hero unit you create, or change it?

For example, suppose I have the following string names for a single Dreadlord hero: ["Detheroc", "Balnazzar", "Algamon"],

and then at some point I get a handle on an actual Dreadlord unit in the map.

Is there a function or native I can call to change it's name?

Or, if I can't dynamically modify it, when I create a hero unit, can I decide what name it will get?
 
You can't dynamically modify it.

You can sort of determine the name (out of the presets in the object editor). You just need to run a loop. You would create the hero:
JASS:
loop
    set hero = CreateUnit(Player(0), 'wtfdreadlordrawcodeis', 0, 0...)
    set name = GetHeroProperName(hero)
    if (name == "Detheroc") then  
        exitwhen true
    else
        call RemoveUnit(hero)
    endif
endloop

eh, it is kind of a hacky way to do it, but I tried it out before and it appears to work. It is based on chance though, so it may take many iterations to complete. :\ Also, if a hero already has that name, it'll append II or something to it (depending on how many there are in the map), so be sure to watch out for that or it'll cause an infinite loop.

There is no direct way to manipulate a hero's name. If I were you, I would consider making multiple objects in the object editor, each one with a different name (i.e. one for "Detheroc", one for "Balnazzar", etc.).
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
You can't dynamically modify it.

You can sort of determine the name (out of the presets in the object editor). You just need to run a loop. You would create the hero:
JASS:
loop
    set hero = CreateUnit(Player(0), 'wtfdreadlordrawcodeis', 0, 0...)
    set name = GetHeroProperName(hero)
    if (name == "Detheroc") then  
        exitwhen true
    else
        call RemoveUnit(hero)
    endif
endloop

eh, it is kind of a hacky way to do it, but I tried it out before and it appears to work. It is based on chance though, so it may take many iterations to complete. :\ Also, if a hero already has that name, it'll append II or something to it (depending on how many there are in the map), so be sure to watch out for that or it'll cause an infinite loop.

There is no direct way to manipulate a hero's name. If I were you, I would consider making multiple objects in the object editor, each one with a different name (i.e. one for "Detheroc", one for "Balnazzar", etc.).

Yes I was considering doing that, creating a hero repeatedly until I get the desired name. In my case there are only two names "Name Male" and "Name Female" for each hero, so it would be pretty fast to get the right one.

But doing in that way, surely it's really deterministic and depends on whatever pseudo random number generator they are using, can't we just fix the seed for it in each instance?

I thought of just making separate objects for each one, but then I would have to go and change everything, because all my data for each hero hinges on its unitType, and this will obviously be different if I had two objects for each hero, since they would not share the same unitType.

Basically I just need a way to relate the gender of the hero to make it obvious (these are heroes like quilboars and ghouls mind you ^^), and I figured I could put it in the string name. I suppose then there is no way to give heroes nicknames (e.g. pokemon, you *can* name each pokemon whatever you want).

I suppose I could also just add an ability that displays this information, though I really can't use up command card realty. I guess also a dummy buff could work too.

But how far do the roman numerals go? I can just use substring to check for the important characters, right?

Also is there a way to turn off the roman numerals? I am thinking of the map now, and there are multiples instances of heroes with the same name (e.g. "Ghoul") but they do not have any roman numerals (name is still "Ghoul").
 
I thought of just making separate objects for each one, but then I would have to go and change everything, because all my data for each hero hinges on its unitType, and this will obviously be different if I had two objects for each hero, since they would not share the same unitType.

Will it be hard to copy the data from one to another?
 
Status
Not open for further replies.
Top