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

[TRIGGER] Getting name of Unit

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
I want to get the name of the unit with the 068 after it and ect. This picture I attach hopefully lets you know what i need

309788-5320ea44de8f6ad5fcbd39f533ee2c87.jpg


LUA/JASS Please help
 

Attachments

  • name.png
    name.png
    5.7 KB · Views: 113
Level 5
Joined
Jun 12, 2018
Messages
148
I don't get what you mean, 068 is just an index automatically generated after the unit name when you put a unit over the map.
 
Level 6
Joined
Mar 7, 2011
Messages
124
hmm interesting. like swatosj said, the number at the end is just an index that is used to ID editor placed objects. all objects (units, doodads, etc) that you place in the editor translate to either a jass or lua representation. say i place a demon hunter at (x=11500, y=12500) and then save my map using JASS as my scripting language. if i were to look at the .j file thats generated from a JASS map, located inside the map's mpq, id see lines of JASS for storing the unit as a global variable, creating it at init, and then modifying it. it'd look something like

JASS:
unit gg_unit_Edem_0001= null

...

set gg_unit_Edem_0001=BlzCreateUnitWithSkin(p, 'Edem', 11500, 12500, 45.000, 'Edem')

the ID youre talking about is part of the global variable's name. the only way i can think of to programmatically interact with variable names like you want with JASS is through text macro's and a loop that iterated the id part of the variable name ("0001", "0002" .. etc). this would be much more elegant in Lua, where i think you can natively iterate property names in an object and also interact with those property names as strings

either lua or jass, the above also only lets you get from a world editor ID to a unit reference. if you wanted to get from a unit reference to its original WorldEditor ID you would want to use a unit indexer. a unit indexer is important whenever you want to access custom data using only a unit as your starting point. you could create a new array to store each unit's WorldEditor ID, and then use the unit's index to store/access that data
 
Level 8
Joined
Jun 16, 2008
Messages
333
Let me elaborate a little more...

so what I am trying to do is stream line making units patrol to regions. I want to name the region something I can refer from the unit like gg_unit_Edem_0001

I just want to know if there is a way I can
GetUnitsOfPlayerAll(Player(15))
and get gg_unit_Edem_0001 so i can split and put in an array. If I print GetEnumUnit(), I get a long number.


From your post, it seems that it is a variable so Ill look into working around that, but would there be any other way around this idea? Can I make it so I can see what GetEnumUnit() prints to display in World Editor?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
You could save the Unit-Type Id into a Table.

Example:
Lua:
--First let's create our Region Table
Regions = {}

--Next let's get our units Unit-Type Id
local id = GetUnitTypeId(YourUnit) --Now we're getting your unit's ID. This will be some integer like 13845062

--Now we use that Unit-Type ID as the Index in our Table
Regions[id] = Put Your Region Here For That Unit-Type
I think that's sort of what you wanted? From that point on all you have to do is something like:

A unit enters entire map -> local id = GetUnitTypeId(Entering Unit) -> Order Entering Unit to Patrol to Regions[id]
 
Last edited:
Level 6
Joined
Mar 7, 2011
Messages
124
I use W3X Tools (Beta) to make units automatically cast/patrol to regions in levels, based on their in-editor information.
thats a cool tool, its great for JASS maps that want to centralize simple content's definition all in one spot, or just be lazy about making this stuff. i like this option best if youre already locked into dealing with JASS but still are looking into automating this stuff. you dont want the textmacro hell thats your only in-map JASS alternative to it (that i can think of)

With Lua one can enumerate the global/root node for all named elements. Such as all variables for such units.
i was hoping youd come in to say exactly this! if you can use Lua for your map then youve got some really good in map automation options to this topic, i think much more like what iown_azz was originally hoping for, and these options wouldnt require an external tool
 
Level 8
Joined
Jun 16, 2008
Messages
333
I think that's sort of what you wanted? From that point on all you have to do is something like:
The only thing about this is that I can't see that number in world editor

I use W3X Tools (Beta) to make units automatically cast/patrol to regions in levels, based on their in-editor information.
I tried but I got an error and left it on the thread of the tool... Im using LUA BTW

i was hoping youd come in to say exactly this! if you can use Lua for your map then youve got some really good in map automation options to this topic, i think much more like what iown_azz was originally hoping for, and these options wouldnt require an external tool
Atleast someone knows what Dr Super Good is talking about because I have no clue...
 
Level 6
Joined
Mar 7, 2011
Messages
124
if you imagine globals in JASS you might think of each as being its own isolated thing, but in reality theyre all more like siblings, children of some global namespace model. many languages represent that namespace as a dictionary object, if youre familiar with those. in JASS, you dont have programmatic access to that global object, just direct access to its individual children (the global variables you/blizz has defined and exposed). dsg is saying that in Lua you do have access to that global object, and you can reference the collection of its children, meaning all globals in your map. this means you can iterate the global object's children and apply your desired auto patrol logic elegantly using Lua's tools

another thing that works for your benefit in Lua is that you can reference the properties of an object either by literal or by string name (object.property Vs. object["property"]). this is useful when it comes to using a convention to map from: auto-patrol unit global name -> rect global name, because you're dealing with strings at that point
 
Level 8
Joined
Jun 16, 2008
Messages
333
if you imagine globals in JASS you might think of each as being its own isolated thing, but in reality theyre all more like siblings, children of some global namespace model. many languages represent that namespace as a dictionary object, if youre familiar with those. in JASS, you dont have programmatic access to that global object, just direct access to its individual children (the global variables you/blizz has defined and exposed). dsg is saying that in Lua you do have access to that global object, and you can reference the collection of its children, meaning all globals in your map. this means you can iterate the global object's children and apply your desired auto patrol logic elegantly using Lua's tools

another thing that works for your benefit in Lua is that you can reference the properties of an object either by literal or by string name (object.property Vs. object["property"]). this is useful when it comes to using a convention to map from: auto-patrol unit global name -> rect global name, because you're dealing with strings at that point
You got all that from what he said! lol amazing! do you have to know what the units global parent variable is by any chance? I assume it would be in the map file data but Im like warcraft 3, reforged to this game since 2010 when i was a baby... so i dont know any of the tools that can help
 
Status
Not open for further replies.
Top