HELP WITH PURCHASING HERO ABILITIES

Status
Not open for further replies.
Level 7
Joined
Feb 13, 2022
Messages
87
The Situation: I want the player heroes in my game to be able to select/purchase their powers from a building using lumber for the cost. Each hero will still share one power that is level restricted. Any suggestions on how to do this? Do I need to do it via triggers or can I use the object editor for this? I saw for the techtrees for buildings there is no option for selling hero/unit abilities, only options for selling items and units. Any help is much appreciated!
 

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,640
I imagine most people use Items (tomes in particular) for the abilities. Then they use triggers to detect which Item was purchased and either Add or Increase the level of the Ability for the purchasing Hero.

You can use a Hashtable or an Array/For Loop to link these Items/Abilities together to create an easy to use system that works off of 1-2 triggers.

Array example:
  • Setup Abilities
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet AbilityItem[1] = Blizzard (item)
      • Set VariableSet AbilityItem[2] = Storm Bolt (item)
      • Set VariableSet AbilitySpell[1] = Blizzard (spell)
      • Set VariableSet AbilitySpell[2] = Storm Bolt (spell)
  • Learn Abilities
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to AbilityItem[(Integer A)]
            • Then - Actions
              • Unit - Increase level of AbilitySpell[(Integer A)] for (Buying unit)
              • Unit - Add AbilitySpell[(Integer A)] to (Buying unit)
            • Else - Actions
Adding an ability to a unit that already has it will result in nothing happening. So with the above design it should either Add the ability or increase it's level if it's already learned. Creating and using Variables for the (Sold Item) and (Buying unit) would help make this more efficient.

You can even modify this trigger so that it first checks the level of AbilitySpell for the Buying unit before doing anything else. This could be used for a refund system if the ability is already at max level.

IE: If level of AbilitySpell for (Buying unit) is Less than 5 THEN Increase/add ability ELSE Add 1 lumber to (Owner of (Buying unit)).
 
Last edited:
Level 7
Joined
Feb 13, 2022
Messages
87
I imagine most people use Items (tomes in particular) for the abilities. Then they use triggers to detect which Item was purchased and either Add or Increase the level of the Ability for the purchasing Hero.

You can use a Hashtable or an Array/For Loop to link these Items/Abilities together to create you an easy to use system that works off of 1-2 triggers.

Array example:
  • Setup Abilities
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet AbilityItem[1] = Blizzard (item)
      • Set VariableSet AbilityItem[2] = Storm Bolt (item)
      • Set VariableSet AbilitySpell[1] = Blizzard (spell)
      • Set VariableSet AbilitySpell[2] = Storm Bolt (spell)
  • Learn Abilities
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to AbilityItem[(Integer A)]
            • Then - Actions
              • Unit - Increase level of AbilitySpell[(Integer A)] for (Buying unit)
              • Unit - Add AbilitySpell[(Integer A)] to (Buying unit)
            • Else - Actions
Adding an ability to a unit that already has it will result in nothing happening. So with the above design it should either Add the ability or increase it's level if it's already learned. Creating and using Variables for the (Sold Item) and (Buying unit) would help make this more efficient.

You can even modify this trigger so that it first checks the level of AbilitySpell for the Buying unit before doing anything else. This could be used for a refund system if the ability is already at max level.

IE: If level of AbilitySpell for (Buying unit) is Less than 5 THEN Increase/add ability ELSE Add 1 lumber to (Owner of (Buying unit)).

I imagine most people use Items (tomes in particular) for the abilities. Then they use triggers to detect which Item was purchased and either Add or Increase the level of the Ability for the purchasing Hero.

You can use a Hashtable or an Array/For Loop to link these Items/Abilities together to create you an easy to use system that works off of 1-2 triggers.

Array example:
  • Setup Abilities
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet AbilityItem[1] = Blizzard (item)
      • Set VariableSet AbilityItem[2] = Storm Bolt (item)
      • Set VariableSet AbilitySpell[1] = Blizzard (spell)
      • Set VariableSet AbilitySpell[2] = Storm Bolt (spell)
  • Learn Abilities
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to AbilityItem[(Integer A)]
            • Then - Actions
              • Unit - Increase level of AbilitySpell[(Integer A)] for (Buying unit)
              • Unit - Add AbilitySpell[(Integer A)] to (Buying unit)
            • Else - Actions
Adding an ability to a unit that already has it will result in nothing happening. So with the above design it should either Add the ability or increase it's level if it's already learned. Creating and using Variables for the (Sold Item) and (Buying unit) would help make this more efficient.

You can even modify this trigger so that it first checks the level of AbilitySpell for the Buying unit before doing anything else. This could be used for a refund system if the ability is already at max level.

IE: If level of AbilitySpell for (Buying unit) is Less than 5 THEN Increase/add ability ELSE Add 1 lumber to (Owner of (Buying unit)).
Thank You for the respond! I should have clarified one thing, after the hero purchases their power (item) I want them to still have to learn the ability (abilities). As is this current trigger makes it so the player auto gets the power when they purchases it. Any idea what I would need to change to make this work?
Otherwise this was super useful, thank you for your time!
 
Level 2
Joined
Feb 3, 2019
Messages
3
Not sure if you still need help with this but I think I've managed to do what you were asking by using the Engineering Upgrade ability: A hero purchases an ability from a shop, that hero can then use their skill points to increase the level of that ability?
Each spell requires 3 things:
Item (itemType_Abilities) : The item the shop sells, I just copy and pasted the icons and tooltips from the spells to the items.
Actual Spell (ability_Actual) : The actual ability you want to give the hero that you put skill points into
Upgrade Spell (ability_Upgrade) : A spell based on the Tinker's 'Engineering Upgrade' spell.
-For Basic abilities change the 'Data - Ability Upgrade 1' to 'Dummy Ability(Basic), [Whatever spell you want to grant the hero goes here]'
-For Ultimate abilities change the 'Data - Ability Upgrade 1' to 'Dummy Ability(Ultimate), [Whatever spell you want to grant the hero goes here]'

In the object editor change the heroes spells to Dummy Ability(Basic), Dummy Ability(Basic), Dummy Ability(Basic), Dummy Ability(Ultimate).
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player - Disable Dummy Ability (Basic) for Player 1 (Red)
      • Player - Disable Dummy Ability (Ultimate) for Player 1 (Red)
      • -------- Variable Initialization --------
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[1] = Chain Lightning
      • Set VariableSet ability_Actual[1] = Chain Lightning
      • Set VariableSet ability_upgrade[1] = Chain Lightning (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[2] = Blizzard
      • Set VariableSet ability_Actual[2] = Blizzard
      • Set VariableSet ability_upgrade[2] = Blizzard (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[3] = Battle Roar
      • Set VariableSet ability_Actual[3] = Battle Roar
      • Set VariableSet ability_upgrade[3] = Battle Roar (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[4] = Storm Bolt
      • Set VariableSet ability_Actual[4] = Storm Bolt
      • Set VariableSet ability_upgrade[4] = Storm Bolt (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[5] = Critical Strike
      • Set VariableSet ability_Actual[5] = Critical Strike
      • Set VariableSet ability_upgrade[5] = Critical Strike (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[6] = Feral Spirit
      • Set VariableSet ability_Actual[6] = Feral Spirit
      • Set VariableSet ability_upgrade[6] = Feral Spirit (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[7] = Frost Armor
      • Set VariableSet ability_Actual[7] = Frost Armor
      • Set VariableSet ability_upgrade[7] = Frost Armor (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[8] = Vampiric Aura
      • Set VariableSet ability_Actual[8] = Vampiric Aura
      • Set VariableSet ability_upgrade[8] = Vampiric Aura (Upgrade)
      • -------- ----- --------
      • -------- Ultimates --------
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[9] = Inferno
      • Set VariableSet ability_Actual[9] = Inferno
      • Set VariableSet ability_upgrade[9] = Inferno (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[10] = Phoenix
      • Set VariableSet ability_Actual[10] = Phoenix
      • Set VariableSet ability_upgrade[10] = Phoenix (Upgrade)
      • -------- ----- --------
      • Set VariableSet itemType_Abilities[11] = Starfall
      • Set VariableSet ability_Actual[11] = Starfall
      • Set VariableSet ability_upgrade[11] = Starfall (Upgrade)
      • For each (Integer A) from 1 to 8, do (Neutral Building - Add itemType_Abilities[(Integer A)] to Murloc Stop 'N Shop 0020 <gen> with 1 in stock and a max stock of 1)
      • For each (Integer A) from 9 to 11, do (Neutral Building - Add itemType_Abilities[(Integer A)] to Murgul's Ultimates. 0002 <gen> with 1 in stock and a max stock of 1)

This is kind of just a quick fix so you dont waste lumber on abilities you've already purchased.
  • ShopSell
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 11, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Sold Item)) Equal to itemType_Abilities[(Integer A)]
            • Then - Actions
              • Neutral Building - Remove (Item-type of (Sold Item)) from all marketplaces
              • Unit - Add ability_upgrade[(Integer A)] to (Buying unit)
              • Unit - For (Buying unit), Ability ability_upgrade[(Integer A)], Disable ability: False, Hide UI: True
            • Else - Actions

This trigger is required because reforged broke Engineering Upgrade somehow, without this trigger the purchased abilities will still show the icons, tooltips and art values of the original dummy unit ability.
  • LearnChange
    • Events
      • Unit - A unit Learns a skill
    • Conditions
    • Actions
      • Custom script: set udg_ability_tempHeroSkill = GetLearnedSkill()
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of ability_tempHeroSkill for (Learning Hero)) Equal to 1
        • Then - Actions
          • Unit - Remove ability_tempHeroSkill from (Learning Hero)
          • Unit - Add ability_tempHeroSkill to (Learning Hero)
        • Else - Actions

Here's the map anyway if you wanna test it out.
 

Attachments

  • BuyAbilities.w3m
    32.2 KB · Views: 9
Status
Not open for further replies.
Top