Unit name to unit ID

Ghostwind

o________o
Reaction score
172
Is there any way to get a unit's ID from its unit name?

For example if Player 1 types "footman" I want it to set a variable to the footman's unit ID, or if they type "grunt" to set it to the grunt's unit ID, etc.
 

Builder Bob

Live free or don't
Reaction score
249
Is there any way to get a unit's ID from its unit name?

For example if Player 1 types "footman" I want it to set a variable to the footman's unit ID, or if they type "grunt" to set it to the grunt's unit ID, etc.

Unit's can have the same name without issues in the object editor, so no, it is not possible without making your own function that picks units from a list with the unit's names as the identifier.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JASS:
constant native UnitId takes string  unitIdString returns integer


JASS:
constant native UnitId2String takes integer unitId returns string


GetUnitName returns a localized string, depends of the warcraft language installed, if you don't have change the name yourself.
For example "Footman" in English, "Fantassin" in French.

The function UnitId takes the English default name of the unit id , even if you have changed the unit name. It isn't case sensitive.
If it's a custom id, then the string will be "custom_<id>".

I suggest you to test these functions and change the name of your units if you don't have understood me.

Also UnitId2String is bugged, it always returns null when it is a saved game loaded.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
If you really wanted to do this, you'd have to make two string arrays or a string and integer array. If someone enters one, output the other.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top