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

[JASS] GetUnitGoldCost crashes with hero unit types

Level 25
Joined
Feb 2, 2006
Messages
1,689
Hi,
I would like to show unit gold and lumber costs in a tooltip in my custom UI for my paged buttons system.
However, with
JASS:
GetUnitGoldCost
it seems to crash the game when the ID belongs to a hero unit type :(
Is this known behavior?

I have declared the two natives from common.ai in my trigger:

JASS:
native GetUnitGoldCost takes integer unitid returns integer
native GetUnitWoodCost takes integer unitid returns integer

I have no crashes for unit types based on non-hero unit types.

Is there an alternative system to detect the cost like for items? I am thinking about something based on the Transmute ability. It could create a dummy unit, the unit I need the cost of and transmute it etc.
 

Remixer

Map Reviewer
Level 31
Joined
Feb 19, 2011
Messages
1,957
Considering that heroes' gold cost can change through the levels it would not surprise me if there are issues related to the hero unit gold cost, but the gold cost of heroes is based on a formula, so you could just check if the unit is a hero and then calculate its gold cost using that formula. Item's gold cost you can mimic through the Item Custom Value field, so just set the Custom Value of each item to the their corresponding Gold Cost. Otherwise it's going to be a little hard as far as I know.
 
Level 25
Joined
Feb 2, 2006
Messages
1,689
I am already using a system for the item gold and lumber cost based on a dummy shop from Hive which is fine.

My problem is that I store the IDs of unit types only so I would have to store a flag "isHero" or something is there is no other way. True I did not think about the variable cost due to hero revivals. For my system I only need the costs to initially summon/buy them.
 

Remixer

Map Reviewer
Level 31
Joined
Feb 19, 2011
Messages
1,957
I am already using a system for the item gold and lumber cost based on a dummy shop from Hive which is fine.

My problem is that I store the IDs of unit types only so I would have to store a flag "isHero" or something is there is no other way. True I did not think about the variable cost due to hero revivals. For my system I only need the costs to initially summon/buy them.
You could just check if the unit type ID starts with a capital letter, if it does, it's a hero.

Edit: assuming there's a way to do that in JASS (or whatever language you are using).
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
I find it's best to create your own Unit-Type "class" in which you can store an infinite number of custom values. A Hashtable comes to mind, using Unit-Type Id's as the Parent keys. It's best to do this at the very start of your project so that you can fill the Hashtable with new entries as you create them. Not so fun to implement later on when you've got 100's of different Unit-Types to add. But some code goes a long way in saving you time and headache:
vJASS:
function SetupNewUnitTypes takes nothing returns nothing
    call AddNewUnitType( 'Hpal', 400, 150, 1, 2, 3 ) // This function saves the given data to a Hashtable
    call AddNewUnitType( 'hfoo', 150, 0, 4, 8, 50 )
    // ...
endfunction
 
Last edited:
Top