• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

getting the gold/lumber cost of unit

Status
Not open for further replies.
Level 4
Joined
Jul 13, 2017
Messages
30
how do you make a trigger which add your gold/lumber, based on the trained unit gold/lumber cost?

example:

event - unit finishes training a unit

condition - unit type of trained unit equal to peasant

action - add [trained unit gold cost] to player current gold
action - add [trained unit lumber cost] to player current lumber
action - remove [trained unit] from the game

we would expect to have 75 gold, since the peasant cost 75 gold.. but i cannot find the right function.
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
Declare the native in the map header:
JASS:
native GetUnitGoldCost takes integer unitid returns integer
Use it in one of your functions:
JASS:
function test takes nothing returns nothing
    call BJDebugMsg("A footman consts : "+I2S( GetUnitGoldCost('hfoo')+" gold coins" ) )
endfunction

  • Custom script: set udg_GoldCost = GetUnitGoldCost('hfoo')
As I said you need JassHelper for this native.
 
Level 4
Joined
Jul 26, 2016
Messages
88
i see, but that would take massive effort for every unit type. can anybody do this trigger just for the peasant? just for an example.. i learn much faster through examples..

You could also do it in a roundabout way by ordering a player to train/buy a unit and then checking gold difference, refunding gold or preemtively adding then removing excess gold. Very roundabout way though, would be better to just keep the gold costs saved somewhere as Jampion suggests.
 
Level 4
Joined
Jul 13, 2017
Messages
30
Declare the native in the map header:
JASS:
native GetUnitGoldCost takes integer unitid returns integer
Use it in one of your functions:
JASS:
function test takes nothing returns nothing
    call BJDebugMsg("A footman consts : "+I2S( GetUnitGoldCost('hfoo')+" gold coins" ) )
endfunction

  • Custom script: set udg_GoldCost = GetUnitGoldCost('hfoo')
As I said you need JassHelper for this native.
Im using JassHelper in JNGP, but i cant make it work. Im quite new to Jass.. so I apologize for that. Is it possible that someone post a map example for me to look at? :D
 
Level 4
Joined
Jul 13, 2017
Messages
30
Here it is. The natives in the map header return gold/lumber cost for a unit type (integer).
Kill units to display their costs.
Thank you your map worked, but there is a problem.. why is it that when i import the triggers to my map, and tested it, it just returns to the warcraft main menu? in other words it doesnt let me load the map ingame... it also happens when i delete and retype exactly this -> native GetUnitGoldCost takes integer unitid returns integer <- in your map, and when i tested it this time.. it doesnt let me load the map.. strange...
EDIT: So i figured the solution is to save the map first and reopen it in WE, then you can test it. Still strange.. Anyway, thank you...
 
Last edited:
Status
Not open for further replies.
Top