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

[System] Costs - GetUnitCost & GetItemCost

Level 17
Joined
Apr 27, 2008
Messages
2,455
Hmm, UnitId2String(id) != null is useful to know if an integer is a valid unit rawcode, not especially an hero rawcode, plus if you care about loaded games you should use that instead.
Never tried but maybe using IsUnitType with UNIT_TYPE_HERO works as intended, or check if the unit has the ability 'AHer', or some attribute that only an hero has.

EDIT : Just realized that you can also do that (still if you don't care about loaded games coz of this bug):

JASS:
function IsHero takes integer rawcode returns boolean
   return UnitId2String(rawcode) != null and IsHeroUnitId(rawcode)
endfunction

It will work because an hero have his first rawcode letter as an uppercase. (again it's a nice trick to convert an unit in an hero and the opposite using newgen worldeditor)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
So even with newgen just capitalizing the rawcode turns it into a hero?
Yep, and the same for turns it an hero to an unit (first character anything else than an uppercase letter)

But like i said IsUnitHeroId will return true for 'Fake' 'Fuck' 'Boob' 'L337', as it only checks for the first rawcode character, even if the rawcode doesn't exist.

If not, there's the native "IsUnitIdType(id, UNIT_TYPE_HERO)"

Need to be tested though.

But anyway i'm with Magtheridon96 here, it's totally silly to still use the natives functions in this library ...
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Sigh.

IsUnitIdType(id, UNIT_TYPE_HERO) returns true for 'Hpal' as it does for 'LULZ' which does not exist in my object editor. In fact, IsUnitIdType seems to only work for UNIT_TYPE_HERO (if you call it working) as it says 'Hpal' as an id is not a ground unit.

So, yet again, Blizzard provides us with an incomplete API. IsUnitIdType is another useless native.

Edit:

This library will also bug with GetUnitUserData thanks to chaos and similar abilities. Better just remove the library requirement of Unit Indexer and stick with straight unit type id's.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
The IsUnitType thing is fine as it would just return 0 for a non existing unit =). Anyways, that's a case that would never happen (if it did, the person would need to fix it as that'd be an obvious bug in their map ^^).


And bribe, it's perfectly fine as is.


If you want to get a unit's type id cost (considering chaos), then there are functions for that.
JASS:
*       function GetUnitTypeIdGoldCost takes integer unitTypeId returns integer
*       function GetUnitTypeIdWoodCost takes integer unitTypeId returns integer

If you want to get a unit's actual cost, then there are also functions for that (what gold was actually put into the unit excluding any custom ability upgrades).
JASS:
*       function GetUnitTotalGoldCost takes unit whichUnit returns integer
*           -   Gets total unit gold cost including prior upgrades
*       function GetUnitTotalWoodCost takes unit whichUnit returns integer
*           -   Gets total unit wood cost including prior upgrades
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
It will bug with Chaos when the unit transforms, it will display an incorrect gold cost.

No, it will return the correct gold cost >.>.

UnitTotalGoldCost or w/e is the gold you actually spent by buying it/upgrades, it ignores chaos.

If you want chaos, then you use unit type id gold cost... I already mentioned this.

You also missed the important correction I told you about in this post

I don't see a problem with the unit creation and I already said IsUnitType is fine, but since you are so insistent, I added debug statements.


Chaos matter is closed. You can keep bringing it up, but you are just going to keep hearing the same answer from me.


And there is a very specific reason I coded it this way... to retrieve the proper gold/lumber cost of hexed units and so on, or units with buffs on (perhaps temporary chaos). So no, there is no way I'm ever going to change it no matter how much you plead, lol.


I specially need the upgrade tracking in this and I specifically need it to ignore Chaos and other such abils >: P. You are commenting on behaviors I purposefully coded ; D.
 
I didn't mean with the debug statements actually, after talking with Troll-Brain about it I figured it should be up to the user to not be retarded. I meant you have an errro with this line:

set u = CreateUnit(p, UNITS_GET_COST, WorldBounds.maxX, WorldBounds.maxX, 0)

How could I have missed that xD
It should be
set u = CreateUnit(p, UNITS_GET_COST, WorldBounds.maxX, WorldBounds.maxY, 0)
 
Top