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

[Solved] How do I make an ability that costs gold or lumber?

Level 5
Joined
Aug 16, 2018
Messages
39
Hello, I'm making a map full of custom heroes, and there's an ability that involves lumber, and I want it to decrease the player's current lumber and be disabled when the required cost isn't there.
I've tried this
  • Lob Lumber Cost
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Lob Lumber
    • Actions
      • Set Lumber = (Player 1 (Red) Current lumber)
      • Player - Set Player 1 (Red) Current lumber to -20
and these to disable and enable it.
  • Lob Lumber Disable
    • Events
      • Player - Player 1 (Red)'s Current lumber becomes Less than 20.00
    • Conditions
    • Actions
      • Player - Disable Lob Lumber for Player 1 (Red)
  • Lob Lumber Enable
    • Events
      • Player - Player 1 (Red)'s Current lumber becomes Greater than or equal to 20.00
    • Conditions
    • Actions
      • Player - Enable Lob Lumber for Player 1 (Red)
I saw this in a post from 2009 but it doesn't seem to be working, also if there's a better or easier way feel free to tell me, I couldn't find any ability other than "Charge gold and lumber" that allows to set a gold and lumber cost.
 
Last edited:
Level 20
Joined
Aug 29, 2012
Messages
826
Something like this should work:

  • Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (YourAbilityHere)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current lumber) Greater than or equal to 20
        • Then - Actions
          • -------- If true, these actions run --------
          • Player - Add -20 to (Owner of (Triggering unit)).Current lumber
        • Else - Actions
          • -------- If not, only these will run ------
--

The big "If" is an "If /Then / Else multiple functions", and the condition inside is an integer check

I think the issue with you trigger was the "set lumber to -20". "Set" means "change to a fixed value", so in this case the game would try to set the player's lumber to a negative value, which I don't think is possible.
An alternative would be this:

  • Player - Set (Owner of (Triggering unit)).Current lumber to (((Owner of (Triggering unit)) Current lumber) - 20)
With an arithmetic function you saw in your other topic, but it's easier to use "add" and a negative amount :p
 
Level 5
Joined
Aug 16, 2018
Messages
39
Something like this should work:

  • Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (YourAbilityHere)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current lumber) Greater than or equal to 20
        • Then - Actions
          • -------- If true, these actions run --------
          • Player - Add -20 to (Owner of (Triggering unit)).Current lumber
        • Else - Actions
          • -------- If not, only these will run ------
--

The big "If" is an "If /Then / Else multiple functions", and the condition inside is an integer check

I think the issue with you trigger was the "set lumber to -20". "Set" means "change to a fixed value", so in this case the game would try to set the player's lumber to a negative value, which I don't think is possible.
An alternative would be this:

  • Player - Set (Owner of (Triggering unit)).Current lumber to (((Owner of (Triggering unit)) Current lumber) - 20)
With an arithmetic function you saw in your other topic, but it's easier to use "add" and a negative amount :p
Yeah, I thought that my -20 trigger was a problem because, when I used the ability it gets rid of all of my lumber not just 20, just a quick question, is the if condition in the "multiple functions" action a "real comparison" or something else? because I can't find ((Owner of (Triggering unit)) Current lumber).
 
Level 5
Joined
Aug 16, 2018
Messages
39
Something like this should work:

  • Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (YourAbilityHere)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current lumber) Greater than or equal to 20
        • Then - Actions
          • -------- If true, these actions run --------
          • Player - Add -20 to (Owner of (Triggering unit)).Current lumber
        • Else - Actions
          • -------- If not, only these will run ------
--

The big "If" is an "If /Then / Else multiple functions", and the condition inside is an integer check

I think the issue with you trigger was the "set lumber to -20". "Set" means "change to a fixed value", so in this case the game would try to set the player's lumber to a negative value, which I don't think is possible.
An alternative would be this:

  • Player - Set (Owner of (Triggering unit)).Current lumber to (((Owner of (Triggering unit)) Current lumber) - 20)
With an arithmetic function you saw in your other topic, but it's easier to use "add" and a negative amount :p
Never mind I found it.....
 
Level 5
Joined
Aug 16, 2018
Messages
39
Something like this should work:

  • Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (YourAbilityHere)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current lumber) Greater than or equal to 20
        • Then - Actions
          • -------- If true, these actions run --------
          • Player - Add -20 to (Owner of (Triggering unit)).Current lumber
        • Else - Actions
          • -------- If not, only these will run ------
--

The big "If" is an "If /Then / Else multiple functions", and the condition inside is an integer check

I think the issue with you trigger was the "set lumber to -20". "Set" means "change to a fixed value", so in this case the game would try to set the player's lumber to a negative value, which I don't think is possible.
An alternative would be this:

  • Player - Set (Owner of (Triggering unit)).Current lumber to (((Owner of (Triggering unit)) Current lumber) - 20)
With an arithmetic function you saw in your other topic, but it's easier to use "add" and a negative amount :p
This solves the lumber cost problem, it works great, but now I was wondering if you could help me disable/enable and ability when the Lumber cost is met.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
There's an ability called Charge Gold and Lumber if you need something that casts without a target.

Also, you could periodically check the player's resources and disable/enable the ability depending on the outcome. The Event would be a Periodic Interval or Timer. The Condition would be an Integer Comparison. The Action would be one of the many Enable/Disable ability actions.
 
Level 5
Joined
Aug 16, 2018
Messages
39
There's an ability called Charge Gold and Lumber if you need something that casts without a target.

Also, you could periodically check the player's resources and disable/enable the ability depending on the outcome. The Event would be a Periodic Interval or Timer. The Condition would be an Integer Comparison. The Action would be one of the many Enable/Disable ability actions.
how do I disable the ability if the player has less than 20 lumber?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
You can do it like this with an If Then Else action:
  • Events
    • Time - Every 0.10 seconds
  • Conditions
  • Actions
    • If all conditions are true then do actions
      • If - Conditions
      • (YourPlayer's Current lumber) Less than 20
    • Then - Actions
      • Player - Disable YourAbility for YourPlayer
    • Else - Actions
      • Player - Enable YourAbility for YourPlayer
Replace YourPlayer and YourAbility with the Player and Ability.

If there's multiple Players with this ability then you will need to store them in a Player Group variable and use the Pick Each Player action to loop over said group. Then you would apply the above Actions inside of the loop, but change YourPlayer to (Picked player). This will run the Actions once for each Player in the group.

You should try googling "Hiveworkshop X" where X is the subject that you're confused about. For example, if you don't understand the Player Group thing then search "Hiveworkshop player groups".
 
Last edited:
Level 5
Joined
Aug 16, 2018
Messages
39
You can do it like this with an If Then Else action:
  • Events
    • Time - Every 0.10 seconds
  • Conditions
  • Actions
    • If all conditions are true then do actions
      • If - Conditions
      • (YourPlayer's Current lumber) Less than 20
    • Then - Actions
      • Player - Disable YourAbility for YourPlayer
    • Else - Actions
      • Player - Enable YourAbility for YourPlayer
Replace YourPlayer and YourAbility with the Player and Ability.

If there's multiple Players with this ability then you will need to store them in a Player Group variable and use the Pick Each Player action to loop over said group. Then you would apply the above Actions inside of the loop, but change YourPlayer to (Picked player). This will run the Actions once for each Player in the group.

You should try googling "Hiveworkshop X" where X is the subject that you're confused about. For example, if you don't understand the Player Group thing then search "Hiveworkshop player groups".
it seems to work half, the ability gets disabled but it doesn't get re-enabled, also the ability disappears when it gets disabled, any idea how to fix it?
 
Level 5
Joined
Aug 16, 2018
Messages
39
You can do it like this with an If Then Else action:
  • Events
    • Time - Every 0.10 seconds
  • Conditions
  • Actions
    • If all conditions are true then do actions
      • If - Conditions
      • (YourPlayer's Current lumber) Less than 20
    • Then - Actions
      • Player - Disable YourAbility for YourPlayer
    • Else - Actions
      • Player - Enable YourAbility for YourPlayer
Replace YourPlayer and YourAbility with the Player and Ability.

If there's multiple Players with this ability then you will need to store them in a Player Group variable and use the Pick Each Player action to loop over said group. Then you would apply the above Actions inside of the loop, but change YourPlayer to (Picked player). This will run the Actions once for each Player in the group.

You should try googling "Hiveworkshop X" where X is the subject that you're confused about. For example, if you don't understand the Player Group thing then search "Hiveworkshop player groups".
Never mind I found out what my problem was.
 
Level 5
Joined
Aug 16, 2018
Messages
39
You can do it like this with an If Then Else action:
  • Events
    • Time - Every 0.10 seconds
  • Conditions
  • Actions
    • If all conditions are true then do actions
      • If - Conditions
      • (YourPlayer's Current lumber) Less than 20
    • Then - Actions
      • Player - Disable YourAbility for YourPlayer
    • Else - Actions
      • Player - Enable YourAbility for YourPlayer
Replace YourPlayer and YourAbility with the Player and Ability.

If there's multiple Players with this ability then you will need to store them in a Player Group variable and use the Pick Each Player action to loop over said group. Then you would apply the above Actions inside of the loop, but change YourPlayer to (Picked player). This will run the Actions once for each Player in the group.

You should try googling "Hiveworkshop X" where X is the subject that you're confused about. For example, if you don't understand the Player Group thing then search "Hiveworkshop player groups".
Thank you all for the help, it works now.
 
Top