• 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.

Reduce cost of unit with trigger

Level 3
Joined
Mar 20, 2024
Messages
14
Hey yall, i was wondering if there was a way to use triggers to reduce the gold/lumber cost of a unit in the middle of a game.

For example:
Footman costs 200 gold
Player researches tech "supplies".
Now footman costs 100 gold.

Any help is appreciated.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
A less ideal work-around might be to "refund" 100 gold to the player every time a footman finishes training. This could be reflected with the upgrade tooltip. This could in theory happen when the footman is queued, with the refund being removed if the footman is cancelled, but the coding for that would be a lot more difficult to avoid potential exploits.
 
Level 3
Joined
Mar 20, 2024
Messages
14
A less ideal work-around might be to "refund" 100 gold to the player every time a footman finishes training. This could be reflected with the upgrade tooltip. This could in theory happen when the footman is queued, with the refund being removed if the footman is cancelled, but the coding for that would be a lot more difficult to avoid potential exploits.
Yeah this wouldn't work for this specific scenario.

What i am actually looking to do with it is reduce the cost of a unit based on the number of players in the game. Make it cheaper if there are less players. (It's a co-op game and buying the unit gives a bonus to all players, so it should cost less if there are less players to benefit from it. At least that's the idea)
 
Level 3
Joined
Mar 20, 2024
Messages
14
Is the unit spawned or trained? If you just want to spawn a unit after clicking its button you should be able to use Charge Gold & Lumber and alter the cast cost with the ability field manipulation natives.
If i understand you right, you can charge gold/lumber to cast an ability, and alter the cost of the ability with triggers? What would that look like? Is that still doable in gui?
 
Level 42
Joined
Feb 27, 2007
Messages
5,330
CG&L is an ability; it’s what spawns the Tiny town halls. You give that ability to the shop, and it can be cast only when a player has the correct resources. Detect that cast and spawn the special unit for the caster.

Complications arise if a neutral shop is the one that should be selling these units, because then knowing which player cast the spell is harder.

Look at the abilities action category and you will see things like “set ability integer level field” and the like. Those can be changed dynamically for any ability, but it does require you to work with the field names as shown in the Object Editor, and some fields are simply unsupported.

Gold/lumber cost would be integer fields that might or might not be level-dependent. I don’t know how CG&L scales with level off the top of my head. Look for the cost field, find its 4-character identifier (like ‘Emcs’), and see if you can also find that field in the integer (or integer level) fields a trigger will let you change.
 
Level 3
Joined
Mar 20, 2024
Messages
14
CG&L is an ability; it’s what spawns the Tiny town halls. You give that ability to the shop, and it can be cast only when a player has the correct resources. Detect that cast and spawn the special unit for the caster.

Complications arise if a neutral shop is the one that should be selling these units, because then knowing which player cast the spell is harder.

Look at the abilities action category and you will see things like “set ability integer level field” and the like. Those can be changed dynamically for any ability, but it does require you to work with the field names as shown in the Object Editor, and some fields are simply unsupported.

Gold/lumber cost would be integer fields that might or might not be level-dependent. I don’t know how CG&L scales with level off the top of my head. Look for the cost field, find its 4-character identifier (like ‘Emcs’), and see if you can also find that field in the integer (or integer level) fields a trigger will let you change.
Okay that sounds pretty neat. Ill give it a shot. But worst case scenario ill have to find another work around. Thanks for all the help!
 
Level 13
Joined
Feb 5, 2018
Messages
551
You could have an upgrade with unit availabilty change. Make the 100 gold cost Footman available while disabling the 200g gold cost footman. I have not tested this in practice, but it seems like a straight forward upgrade to solve this issue.

1715426520296.png
 
Top