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

Created units spawns with wrong color

Status
Not open for further replies.
I use a lot of "create x units at loc" in my map.
Almost all of these units have a custom player color set under each unit (Art - Team Color).
Each unit inherit this color if preplaced in the editor.
However. When created via triggers they will always spawn with the default color of the owning player (in this case Teal).

In the spawning trigger I can't set the color to the one I want because all units have different colors (based on model and the general tone of said model).

Is there something I can do about this?
 
If I understood you right, you only would want to change the unit's colour? - There is a an action Unit - Change Colour Of Unit (LastCreatedUnit)

Heh yeah I know. I tried to explain in the last post that I can't use that function.
In the spawning trigger I can't set the color to the one I want because all units have different colors...

Since all units use different colors I can't detect what color I need to set the unit in question to.
 
Level 11
Joined
Dec 19, 2012
Messages
411
If you want the unit to change color but not owner use this : Unit - Change Color

If you want the unit to change color(or retain color) and owner use this : Unit - Change Owner

EDIT:
Since all units use different colors I can't detect what color I need to set the unit in question to.

What do you mean? Hope you could clarify the problem. ( Got the answered in the next post , now trying to figure out how to help you)
 
If you want the unit to change color but not owner use this : Unit - Change Color

If you want the unit to change color(or retain color) and owner use this : Unit - Change Owner

Am I not saying it right?

I know those functions, but cannot use them because:
When I spawn a unit I will have to set the color. So far so good.
If I use the "set color" function I will need to know exactly what unit is spawned to be able to tell what color to set.
However.
The spawned units are random so there is no way I can tell what type of unit is spawned. Therefore I cannot "set color" because I will never know what color to set it to.
 
Level 11
Joined
Dec 19, 2012
Messages
411
Am I not saying it right?

I know those functions, but cannot use them because:
When I spawn a unit I will have to set the color. So far so good.
If I use the "set color" function I will need to know exactly what unit is spawned to be able to tell what color to set.
However.
The spawned units are random so there is no way I can tell what type of unit is spawned. Therefore I cannot "set color" because I will never know what color to set it to.

Can't you just add some conditions after the units spawn to check units type?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I hate telling bad news, but as far as I know that editor fields only works for preplaced units.When you preplace them to map, world editor automatically generates a code that changes unit's color in the background.(I checked map file's war3map.j, someone else with jass knowledge will confirm this.)
 
Ok, yes... then didn't understand you.

Hm, clean solution I think about is using hashtable then. Basicly:

In reality UnitType is an integer. So you can save a specific playerHandle in Column UnitType, Row 0.

You have to save all needed values you need in init trigger. (and 0 for second key was just an example)

In creation trigger you can load the player out of hashtable: Column UnitType, Row 0. Think this should work. :)

I think you might need at least few custom scripts for it. Maybe acceptable gui implementation would be: (in init)
  • Set UnitType = UnitType_1
  • Custom script: set udg_Id = udg_UnitType
  • Hashtable - Save Handle Of YourPlayer_1 as Id of 0 in YourHashtable
  • ...
  • Set UnitType = UnitType_2
  • Custom script: set udg_Id = udg_UnitType
  • Hashtable - Save Handle Of YourPlayer_2 as Id of 0 in YourHashtable
  • ...
Later if you create unit you can get unitTypeIdf again with:
  • Custom script: GetUnitTypeId(YourUnit)
And you can load the player with Keys: Id, 0.

Hope it helped, try it yourself first. If you have problems just ask. :)

Edit: Id is an integer variable, UnitType is an unittype variable.
 
And you can load the player with Keys: Id, 0.

Hope it helped, try it yourself first. If you have problems just ask. :)

I already have all my units indexed. I use simple unit array variables because I didn't think myself strong enough in using hashtables.
And it all works great, except this color deal of course.

Can you elaborate on why using hashtables would solve the color issue?
 
No I didn't but I have enough knowledge to know how hashtables work.

What I am asking is how would you get a unit's color by using hashtables?
Since all the spawned units are owned by player 3 (teal). It's only the color which changes, not the owning player.

I get I can get the specific unit type through a hashtable, just as with array.
But I don't get how I can get the color of a specific unit using either.
 
Hm yeah. So in array terms I would create a color array with the size of all units able to be spawned.

Since I use a unit's Point Value to detect a unit type:
Fx.
Murloc has a point value of 1
Satyr has a point value of 2
Iron Golem 3 and so on.

Then I would set the color array.
Set Color_Array[1] = Yellow
Set Color_Array[2] = Red
Set Color_Array[3] = Green
and so forth.

In the spawn trigger I can then check the spawned unit's point value and get the color by referring to the color array.
(I guess this is what a hashtable simplifies).

If that's sorta what you mean, I'll go with a standard array, since I'm so far in the production of the map that I don't want to challenge my hashtable skills and maybe screw a lot up.
 
Yes if you index your unit types by your own, in this case it's better to use normal array.

But use Player_array, not colour_array. Because I think in the action your refer to a player's colour.

Then you don't would need hashtable anymore for this. But just a tip... using hashtable in general can be very useful... maybe you could try to challenge your skills here anyway. :p
 
But use Player_array, not colour_array. Because I think in the action your refer to a player's colour.

Nah.
In the trigger I will set the last created unit's color to Color_Array[Point Value of last created unit]

Heh well I very much see why using hashtables to this kind of job is the better choice, and eventhough I think I could pull it off, I'm not going to.
Maybe in the future when the map has been released I'll a one point do a major overhaul where I use hashtables instead. But not at the time being.
 
Status
Not open for further replies.
Top