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

[Trigger] Custom Ability Level up Script

Status
Not open for further replies.
Level 1
Joined
May 27, 2021
Messages
3
Trying to get a typical custom hero ability sold in shop. using the item technique I have gotten the ability to add. but not upgrade. what am I missing or syntax mix-up. the intent was to create the nested loop for intB 1-30 ( ability level cap) and setting the var AbilityLevel (integer) to add +1 each time the ability is repurchased should be what's happening; However, it never upgrades the level only sets to level 1.

rejuv.PNG
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
the loop "for each integer B" all goes off at once. it is just setting and resetting that immediately 30 times in a row.

so much of what you are doing here is confusing.

I think this should do what you want:

  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Inferno Stone
    • Actions
      • Item - Remove (Item being manipulated)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Acid Bomb for (Triggering unit)) Equal to 0
        • Then - Actions
          • Unit - Add Acid Bomb to (Triggering unit)
        • Else - Actions
          • Unit - Increase level of Acid Bomb for (Triggering unit)


also - check the bottom of this to see how to post triggers:
 
Last edited:
Level 1
Joined
May 27, 2021
Messages
3
Thanks! I actually managed to get it right, and it works wonderfully now!

posted for anyone who needs a template
rejuv.PNG
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
It's good that you got it working but there's a lot wrong with your trigger.

1) This trigger will break the moment a different unit or a different ability is purchased due to how you're using the Variables.
2) Your use of variables seems incorrect. You can get the level of a unit's ability whenever you want using functions provided by blizzard:
  • Set Variable AbilityLevel = (Level of Rejuvenation for (Triggering unit) + 1)
3) The For Loop from 1 to 6 is unnecessary.
4) You don't have to Add the ability to the unit each time it acquires the Item. As Cheshire showed you, you only need to add the ability if the unit doesn't already have it.
5) You don't need to Set the level of the ability. Simply Increase it using the Action Cheshire used.
6) "Do nothing" is a useless Action that is no different than a Comment. It's fine to leave the Else - Actions empty.

Also, you can easily add that Text Message to Cheshire's trigger as well. I think the ideal setup would be something like this:
  • Example
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Rejuvenation (Item)
    • Actions
      • Set VariableSet Ability = Rejuvenation (Ability)
      • Set VariableSet AbilityLevel = ((Level of Ability for (Triggering unit)) + 1)
      • Set VariableSet AbilityName = Rejuvenation
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AbilityLevel Equal to 1
        • Then - Actions
          • Unit - Add Ability to (Triggering unit)
          • Game - Display to (Player group((Owner of (Triggering unit)))) for 1.00 seconds the text: (Purchased: + (AbilityName + ( / Level: + (String(AbilityLevel)))))
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • AbilityLevel Less than or equal to 30
            • Then - Actions
              • Unit - Increase level of Ability for (Triggering unit)
              • Game - Display to (Player group((Owner of (Triggering unit)))) for 1.00 seconds the text: (Purchased: + (AbilityName + ( / Level: + (String(AbilityLevel)))))
            • Else - Actions
      • Item - Remove (Item being manipulated)

Or a shortened version that should still work fine even though it's always trying to add the ability:
  • Example 2
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Rejuvenation (Item)
    • Actions
      • Set VariableSet Ability = Rejuvenation (Ability)
      • Set VariableSet AbilityLevel = ((Level of Ability for (Triggering unit)) + 1)
      • Set VariableSet AbilityName = Rejuvenation
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AbilityLevel Less than or equal to 30
        • Then - Actions
          • Unit - Add Ability to (Triggering unit)
          • Unit - Set level of Ability for (Triggering unit) to AbilityLevel
          • Game - Display to (Player group((Owner of (Triggering unit)))) for 1.00 seconds the text: (Purchased: + (AbilityName + ( / Level: + (String(AbilityLevel)))))
        • Else - Actions
      • Item - Remove (Item being manipulated)

I attached a map with the triggers in it if you wanted to copy/paste them.

I know it's a nice feeling getting your trigger to work on your own but I highly recommend doing it like this so you won't run into any issues.
 

Attachments

  • Ability Purchase Example.w3m
    17.6 KB · Views: 22
Last edited:
Level 1
Joined
May 27, 2021
Messages
3
Looks like i had the oversight on other players throwing that array out of wack. thanks for the catch i've setup the cleaned action you've provided and it works wonders thanks for the assist guys. Now the next hurdle is limiting the purchase of unique spells to 12( available ui space ). Theoretically the player can simply dump gold and still trigger each purchase event beyond the amount of spells they can use.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,535
Have an Integer Array that keeps track of the number of skills learned for each player. Use the player's number as the index in the array.

So if AbilityLevel is Equal to 1 then increase this new variable by 1 ---> Set Variable PlayerSkillsLearned[player number] += 1.

Then add a new If Then Else to the start of the trigger. This will check to see if PlayerSkillsLearned[player number] is equal to 12. If it is then you can give a refund/display a text message to the player telling them that they've reached their limit and the skill couldn't be learned. Then use the function "Skip remaining actions" to end the trigger early.

This will result in the player being unable to purchase a skill beyond their 12th one.

Refunding Gold can be handled in multiple ways. One way I like to do it is to take advantage of the item's Priority Stat which is often times a useless stat anyway:
  • Player - Add (Item: (Item being manipulated)'s Integer Field: Priority ('ipri')) to (Owner of Triggering unit) Current gold

That Action will add Gold to the player based on the Priority stat of the purchased Item. Priority is a value that you can set in the Object Editor which I believe influences how the AI purchases items (could be wrong). So if you wanted to do this then you'd need to go through all of your purchasable Items (Skills) and set their Priority to be equal to their Gold cost.

Ideally we would just reference the Gold Cost directly but for whatever reason it's not available in the Integer Field action. Note that there may be some other "unused" stats on the Items that could use to represent Gold cost instead.
 
Last edited:
Status
Not open for further replies.
Top