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

Buying abilitys

Level 13
Joined
Jun 10, 2007
Messages
780
Buying Abilities

Buying Abilities Through Items

This tutorial will teach you how to make a system allowing the user to buy a skill from a shop (e.g. Avatar) through the purchase of a temporary item that will give you that skill. This can come in handy in games in which you wish for players to customize their heroes. For this tutorial I will use the Infernal and Dark Ritual spells.

The Items
First of all, make a dummy item for each skill you're adding, like this:
Tut Image 1.png
Basically, this will be the item the user buys when they want to learn a specific skill. You may modify any of the values to best suite your map. You will need a new item every time you want a different purchasable skill.

Variables
Next, you will need to create a trigger that gives you the spell, but before you create the triggers, you will need this variable:
Tut Image 2.png
Check 'array'. The variable stores most of the needed information, and you cannot make this trigger without it. To access the Variable Manager, go to the Trigger Editor and look for a green X, or press CTRL+B.
After creating this variable and the object data, you will be ready to start making the trigger.

One-level skills

  • Some Trigger
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Summon Infernal
    • Actions
      • Set skill[(Player number of (Owner of triggering unit))] = Inferno
      • Wait 0.20 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of skill[(Player number of (Owner of triggering unit))] for (Triggering unit)) Less than 1
        • Then - Actions
          • Unit - Add skill[(Player number of (Owner of triggering unit))] to (Triggering unit)
          • Game - Display to (Player group((Owner of triggering unit))) for 10.00 seconds the text: You have bought the...
        • Else - Actions
          • Game - Display to (Player group((Owner of triggering unit))) for 5.00 seconds the text: You already have th...
          • Player - Add 350 to (Owner of triggering unit) Current lumber
Ignore the parts cut off of the trigger - it is just telling you that you bought the skill. Now when somebody buys the Infernal item, it will add the skill to the hero/unit buying it and the item will disappear. This trigger will also give a refund if the spell is already learned. Make this trigger for every spell you want to sell at shops. The included condition is necessary. If you do not include it, whenever you buy any item it will give you the infernal spell, which is definitely not desirable.

Leveling abilities from triggers

For our example of a leveling ability, I will use the Dark Ritual spell.
Again, a dummy item will be used. This item should be very similar to the item used for Infernal - the tooltips, gold cost, icon, etc, should be changed though (If desired).
  • Some Trigger
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Dark Ritual
    • Actions
      • Set skill[(Player number of (Triggering player))] = Dark Ritual
      • Wait 0.20 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of skill[(Player number of (Owner of triggering unit))]for (Triggering unit)) Less than 1
        • Then - Actions
          • Unit - Add skill[(Player number of (Owner of triggering unit))] to (Triggering unit)
          • Game - Display to (All players) for 10.00 seconds the text: Dark Ritual Learned...
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of skill[(Player number of (Owner of triggering unit))] for (Triggering unit)) Less than 3
            • Then - Actions
              • Unit - Increase level of skill[(Player number of (Owner of triggering unit))] for (Triggering unit)
            • Else - Actions
              • Game - Display to (Player group((Owned of triggering unit))) for 5.00 seconds the text: This spell is...
              • Player - Add 100 to (Owner of triggering unit) Current lumber
This would do the same exact thing as the infernal spell, but it will allow you to further level the ability by buying it multiple times. You can set a max on the trigger to also refund it if they attempt to buy the spell more times than the maximum ability level.

Second Way

There are lots of ways to do various things within the World Editor (like a cinematic, for example), and there is another way to do this as well. This way is somewhat easier (if you know how to manage variables) and can be more effective as it is more organized. Only continue if you know the World Editor beyond a novice level.
Variable Setup
First of all, we will need a lot of variables, and we will set them all in a single trigger, so right now create a trigger like this which we will use later.
  • Set Variables
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- We will set our variables here. --------
Now, we will need to create our variables. We will need one for skills, the items, and descriptions (optional).

ScreenShotNum5.png

Skills-Ability Array- Size 1-Value None
Description-String Array- Size 1-Value None
Item-Item-Type Array- Size 1-Value None

Now that are variables are properly set, we may continue on. Go to the trigger you set up. Now we will place our variables in that trigger. Go to Action -> New Action -> All -> Set Variable by right clicking Actions.

  • Set Variables
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- We will set our variables here. --------
      • -------- Each number corresponds to only 1 skill. So, the Inferno variable will ALWAYS be 0, and Dark Ritual will ALWAYS have 1. Do not change these up as you will experience glitches. --------
      • Set skills[0] = Inferno
      • Set skills[1] = Dark Ritual
      • Set Items[0] = Summon Infernal
      • Set Items[1] = Dark Ritual
      • Set Description[0] = <Your info here>
      • Set Description[1] = Dark Ritual is a level 1 normal ability with 3 levels.
If you do not see square brackets to place numbers in your variables, then you didn't make the variable an array, and you must fix the variables. Do so by reading rereading the beginning of the tutorial.
Keep setting variables for each item, skill, and description in this trigger. Now that this trigger is done and our variables are set, we may continue on.

The Second Way - The Trigger

We want it to make it so when a unit buys the item it will add the ability. Thus, make a new trigger. The event should be as follows:

  • Unit - A unit Acquires an item
A generic event that is perfect for what we are doing. Make sure the items purchased in shops (Dark Ritual, Infernal) have there own category, I will use Powerup for mine. Now create this condition:

  • (Item-class of (Item being manipulated)) Equal to Powerup
(Change Powerup to the category you have your purchasable items in) The item being manipulated is the one the object buys. Now to finish up this trigger, do these actions:

  • Actions
    • For each (Integer A) from 0 to <Last array slot you used>, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Items[(Integer A)] Equal to (Item-type of (Item being manipulated))
  • (Level of skill[(Player number of (Owner of triggering unit))]for (Triggering unit)) Less than 1
    • Then - Actions
  • Game - Display to (All players) for 1.00 seconds the text: Spell Learned...
  • Unit - Add skill[(Player number of (Owner of triggering unit))] to (Triggering unit)
    • Custom script: exitwhen true
    • Else - Actions
    • Game - Display to (Player group((Owned of triggering unit))) for 5.00 seconds the text: This spell is...
    • Player - Add [Gold Amount] to (Owner of triggering unit) Current lumber
DOWNLOAD DEMO

Edits

Edit1: Did what Steel_Cold Suggested.
Edit2: Added more information and used trigger tags.
Edit3: Made it more clear and simple (Will add the second way to do this).
Edit4: Added a second way to do this and 2 mirrors to download the demo.
Edit5: Added another variable screenshot and fixed up way one a tad.
Edit6: Fixed up way one again and added text part to way number 2.
Edit7: Finalized way 2 actions so that it will get approved.
Edit8: Engrish improved from 3 years ago: the tutorial is now better understandable :D.
~Thanks to everyone who helped in this tutorial (Including Purplepoot, myself, and some people who suggested content to be placed here)
 
Last edited:
Level 11
Joined
Oct 13, 2005
Messages
233
Here are my suggestions:
  • I would suggest using
    • tags for the triggers instead of posting the images of them. [*]In addition, I recommend you explain in some detail what each trigger does because all you're doing right now is just posting triggers with very little or no information.
    • [/LIST]
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
I myself don't care a lot about spelling errors in posts, but in a tutorial you should not make such errors as "dissapear" or "there" instead of "their".

Now that you used trigger tags, you can remove the attachments. Other than that, it's a useful tutorial to newbies I guess
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
The method could be majorly improved, eg;

-Create an ability array, Skills
-Create an Item-type array, Items
-Create a string array, descriptions

  • Init
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Set Skills[0] = Dark Ritual
      • Set Items[0] = Purchase Dark Ritual
      • Set Descriptions[0] = "Dark Ritual"
      • Set Skills[1] = Frost Nova
      • Set Items[0] = Purchase Frost Nova
      • Set Descriptions[1] = "Frost Nova"
      • ...
  • Buy
    • Events
      • Unit - A Unit Acquires an Item
    • Conditions
      • (Item-class of (Acquired Item)) Equal to <item class for purchased skills>
    • Actions
      • For Each Integer A from 0 to <last slot in the Skills array>, do Actions
        • Loop - Actions
          • If (All Conditions are True) Then do (Then actions) Else do (Else actions)
            • If - Conditions
              • Items[(For Loop Integer A)] Equal to (Item-Type of (Acquired Item))
            • Then - Actions
              • -------- add all the add ability stuff here, display message from Descriptions[0] --------
              • Custom script: exitwhen true
            • Else - Actions
The wait in your above trigger makes it unweildy, also the fact that you would either have to have a trigger for every item, or a giant mass of if-statements.
 
Level 13
Joined
Jun 10, 2007
Messages
780
Ill try to update it.

Edit: Updated the tutorial with fixed spelling mistakes (some didnt catch most), I added the second way to add to do this (Thx PurplePoop +Repz0r) Fixed up the triggers and organized the tutorial, Hopefully it may have a chance at approval now. I made 2 ways to do it (1 is harder but better for people who want really dont wand to use variables) and 2 (uses variables and harder things but is easier to do). Added 2 download mirrors incase of one not working ( I dont know why) :smile:
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
I finally got around to updating it - now, it could use some more work on your part.

  • In way 1, you use Triggering Player. This will not work in this case (a Unit triggers the event) - you will need Owner of (Triggering Unit).
  • Could you please actually include the most useful actions for the Second way (i.e. the part where it actually displays the message and such - people reading the tutorial may want to know that)?
 

.L.

.L.

Level 2
Joined
Oct 26, 2008
Messages
15
Something is worng...

Well, In this manner, If they bought 8 or more different abilities, then the other abilities wouldn't show up, Do you have a solution for this, like making ability limits. ex. Number of skill allowed : 4, or something like that. but overall 4/5
 
Level 2
Joined
Feb 7, 2009
Messages
25
wery nice and usefull! i did something like this, but i made you upgrade a skill =P
 
Level 9
Joined
May 22, 2009
Messages
491
I have played this on Battle.Net Diablo except if you drop the scroll you loose the spell but it dosent have to do that and I found a way to make the script work easily tell me if its buggy. Nice tutorial also.

Unit - Paladin 0000 <gen> Acquires an item
(Item-type of (Item being manipulated)) Equal to Scroll Of Healing
Unit - Add Heal to (Triggering unit)
But this is for a certain unit only but you can change that.
 
Level 6
Joined
Feb 26, 2008
Messages
171
Hmm your 2nd way is wrong, totaly wrong! Sorry to say that... There's just some errors and some variable problems, there we go: a fix
(taken from my map (used your system and fixed the bugs))

  • Buy weapon Main
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Artifact
    • Actions
      • Item - Make (Item being manipulated) Invulnerable
      • For each (Integer Integer01) from 0 to 1, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item[Integer01] Equal to (Item-type of (Item being manipulated))
              • (Level of Skills[Integer01] for (Triggering unit)) Less than 1
            • Then - Actions
              • Game - Display to (All players matching ((Matching player) Equal to (Owner of (Triggering unit)))) the text: |cff00FF00Notice:|r...
              • Game - Display to (All players matching ((Matching player) Equal to (Owner of (Triggering unit)))) the text: (|cff00FF00Notice:|r + Description[Integer01])
              • Unit - Add Skills[Integer01] to (Triggering unit)
              • Custom script: exitwhen true
            • Else - Actions
              • Game - Display to (All players matching ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)))) the text: |cff00FF00Notice:|r...
EDIT: I even made a remove ability trigger, it's even easier to do than the add ability one:
  • Drop weapon Main
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Artifact
    • Actions
      • For each (Integer Integer01) from 0 to 1, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item[Integer01] Equal to (Item-type of (Item being manipulated))
              • (Level of Skills[Integer01] for (Triggering unit)) Greater than or equal to 1
            • Then - Actions
              • Game - Display to (All players matching ((Matching player) Equal to (Owner of (Triggering unit)))) the text: |cff00FF00Notice:|r...
              • Unit - Remove Skills[Integer01] from (Triggering unit)
              • Custom script: exitwhen true
            • Else - Actions
              • Game - Display to (All players matching ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)))) the text: |cff00FF00Notice:|r...
And that's the trigger where the gold refound happens:
  • Return money
    • Events
      • Unit - A unit Pawns an item (to shop)
    • Conditions
    • Actions
      • For each (Integer Integer01) from 0 to 1, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Item[Integer01] Equal to (Item-type of (Sold Item))
              • (Level of Skills[Integer01] for (Triggering unit)) Greater than or equal to 1
            • Then - Actions
              • Game - Display to (All players matching ((Matching player) Equal to (Owner of (Triggering unit)))) the text: |cff00FF00Notice:|r...
              • Player - Add (Integer((Current life of (Sold Item)))) to (Owner of (Triggering unit)) Current gold
              • Hero - Drop (Sold Item) from (Triggering unit)
              • Item - Remove (Sold Item)
              • Custom script: exitwhen true
            • Else - Actions
              • Game - Display to (All players matching ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)))) the text: <Empty String>
:thumbs_up::thumbs_up::thumbs_up:
:wink::wink::wink:
:grin::grin::grin:

If you put (Owner of (Trigger unit)) instead of the Integer01 then the array will be equal to the number of the player like player purple is player 4 so it'll add him the skill[4] but what if you only had 2 spells setted up like in your example and that instead of being the player red, you'd be player gray, then you won't have any spell added to your hero! :O credit me or rep me :thumbs_up:

You should also add a fonction for people who want the ability removed when the hero removes the item or do an event like activating the spell from the item (thunder clap based without dmg, buff, stuff...).

Edit please! Also edit your DEMO MAP and add credit if you put in my fix :O
Else it's flawless! People should always use 2nd way because the 1rst way is way too long! (Open the Battle Mage map and you'll see how long is the spell trigger for buy ability)

Edit: I personaly use the item HP as the cost recover cause I need it for my map but normally in your way of doing things it's better
 
Last edited:
Level 4
Joined
Jun 4, 2009
Messages
70
The first one was great! GOD JOB!!

This helped me alot, i had a trigger before but i could only buy 1 ability and the nothing happened on rest + at max lvl i could still buy ability and loose lumber/gold so thx alot!
 
Level 3
Joined
Oct 11, 2013
Messages
29
I really cant find
(Level of skill[(Player number of (Owner of triggering unit))] for (Triggering unit)) Less than 1

which is used in the trigger, what trigger do i start with to end with Level of skill?

and i`ve also having a HUGE problem with the

Set skill[(Player number of (Owner of triggering unit))] = Inferno

I have made 2 inferno. 1 builded on the Item that cast inferno´s ( like in the guide )
and one based on the spell that cast inferno´s..

in the guide they refer to the item being used.... but when i try edit the trigger, it can only find the spell ( when using custom ).. but i did look in all items as well, no custumized item there eiter...

So what am i doing wrong?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
@TO
You should make your triggers more efficient so you don't mislead people.
Also don't use waits or Integer A / B.
You also leak player groups (force).
Edit8: Engrish improved from 3 years ago: the tutorial is now better understandable :D.
English not Engrish (I don't really care about spelling but i though you would like to know.
Take a look at my tutorial Things a GUIer Should Know

I finally got around to updating it - now, it could use some more work on your part.

  • In way 1, you use Triggering Player. This will not work in this case (a Unit triggers the event) - you will need Owner of (Triggering Unit).

You should use triggering Player rather than owner of triggering unit.
It is a player unit event which means that triggering player will catch the unit picks up item event.
Check here.
JASS:
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )

Note: Almost all of the Generic unit events in GUI will register a triggering player catch.
 
Level 3
Joined
Oct 11, 2013
Messages
29
Hi there, i'm trying to make custom spells following the guide here.
it's not the first time i try, but i always find a wall in this sentence.
(Item-type of (Item being manipulated)) Equal to Summon Infernal

i can't find neither the summon infernal or the dark ritual.

most times it look like this:
(Item-type of (Item being manipulated)) Equal to Summon Infernal

but nothing happen when people buy the stone.

then i tried the dark ritual, to se if i could find the right source there..
But the only time i can find Dark ritual is, with a much longer sentence.

looking like this.

Summon Infernal Equal to (Random level (Level of Dark Ritual for (Triggering unit)) Any Class item-type)

pls help, its so frustrating, that i can't climb that wall.
 
Top