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

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.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
It's possible using JassHelper and custom natives.
Apart from that you could store it in a hashtable for every unit type. This is probably easier than using arrays, because arrays do not support such high indices.
 

Jampion

Code Reviewer
Level 15
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
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Here it is. The natives in the map header return gold/lumber cost for a unit type (integer).
Kill units to display their costs.
 

Attachments

  • GetUnitCost.w3x
    16.7 KB · Views: 213
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:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
If you use JassHelper, it's important to save the map everytime before testing. If the map is modified and not saved (indicated by a * after the map name), you cannot test it.
 
Status
Not open for further replies.
Top