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

[Trigger] Conditions for purchasing an item

Status
Not open for further replies.
Level 3
Joined
Apr 18, 2018
Messages
58
Hey,
I couple of questions I need your help with:
1) I have an Item, that increases hero Chance to Critically strike by 1% each time an Item is purchased. This chance stacks up to 25%. If hero buys 26th Item, than the value returns to 25%. Following question, how can I do, so hero would not be able to buy an item if it is already maxed out?

How this works, I have an array - counter of "how many times an item is purchased".
And with help I came up with a fail safe, if the value of that counter is Greater or Equal to 25, then set the counter variable to 25.
As I understand I need to change condition to "equal to 25". So far I am not able to find an action, that would not allow to buy another item of the same kind. Preferably, with a message that would say "That you already upgraded an ability to its maximum level".

2) I have several Items available at the shop, 3 items. One gives Hero Critical Strike Chance, another Bash and last one Life Steal. However, I want a player only chose one of these three. When he buys one, I want two others not to be available for Hero to purchase.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,220
You'd unfortunately have to "refund" the item on purchase. Return the gold and remove the item from inventory. The player won't notice it since its done instantly.

You COULD try to experiment with GetLocalPlayer() (which I have a tutorial for) in order to remove an item from a shop for only one player but I do not really suggest it as it is fairly risky.
 
Level 3
Joined
Apr 18, 2018
Messages
58
You'd unfortunately have to "refund" the item on purchase. Return the gold and remove the item from inventory. The player won't notice it since its done instantly.

You COULD try to experiment with GetLocalPlayer() (which I have a tutorial for) in order to remove an item from a shop for only one player but I do not really suggest it as it is fairly risky.

How do I refund the Item then? The item does not actually go to inventory, it works like Power Up item, like Tome of Agility or smh like that. So I after hero buys a power up book one out of three, then I will also have to refund whatever he buys next (out of two remaining abilities)? And I can still create a message, that player can only have on of these three abilities, right?
 
Level 3
Joined
Apr 18, 2018
Messages
58
Ohhh, it's not bought from a shop? That makes it tricker.

You'd have to check for issued commands and check if the target is a powerup and then check if you have 25 stacks. If so, force unit to "stop" which would cancel the pickup order.

edit: or does buying a powerup item automatically use it or something?

These Power Up items can be purchased in shop. And once it is purchased a trigger fires, that adds ability to hero, who purchased item. Every time an item is purchased, it increases the level of ability aka Critical Chance. It goes up to 25 stacks. However, hero can buy more, but fail safe will work and will set it back to 25. But there is no gold refund. And I wanted to remove or delete that item from shop, once stacks are full. Or refund gold on purchase, followed by massage "max stacks reached". And I want a hero to be able to purchase only 1 out of 3 items and make him unable to purchase the other two.

Trigger looks like this:

  • Critical Strike Chance
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Critical Strike Chance
    • Actions
      • Set VariableSet Buying_UnitCSC = (Triggering unit)
      • Set VariableSet Buying_PlayerCSC = (Owner of Buying_UnitCSC)
      • Set VariableSet PlayerNumberCSC = (Player number of Buying_PlayerCSC)
      • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = (CriticalChance_Stacks[PlayerNumberCSC] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Equal to 0
        • Then - Actions
          • Unit - Add Critical Strike Item (+1%/+2%/+3%...etc) to Buying_UnitCSC
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Greater than or equal to 1
            • Then - Actions
              • Unit - Set level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC to CriticalChance_Stacks[PlayerNumberCSC]
              • Game - Display to (All players) the text: (String(CriticalChance_Stacks[PlayerNumberCSC]))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CriticalChance_Stacks[PlayerNumberCSC] Greater than or equal to 25
                • Then - Actions
                  • Game - Display to (All players) the text: |cffff0000Maximum s...
                  • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = 25
                • Else - Actions
 
Level 3
Joined
Apr 18, 2018
Messages
58
These Power Up items can be purchased in shop. And once it is purchased a trigger fires, that adds ability to hero, who purchased item. Every time an item is purchased, it increases the level of ability aka Critical Chance. It goes up to 25 stacks. However, hero can buy more, but fail safe will work and will set it back to 25. But there is no gold refund. And I wanted to remove or delete that item from shop, once stacks are full. Or refund gold on purchase, followed by massage "max stacks reached". And I want a hero to be able to purchase only 1 out of 3 items and make him unable to purchase the other two.

I just need a proper condition and to fin a suitable action, that would do the trick, whether it is a gold refund or removing the item from the shop for a certain player.
 
Level 29
Joined
Feb 18, 2014
Messages
3,592
This is great, thanks, but what happens if acquired item works like Tome of Agility, so physically hero does not have an item...
It would be much easier if you use normal items like @Chaosy said. But if you really want to go with tomes then try this : Create a Dummy unit for each player and index them then add a fake tome (item) to them whenever the hero buys the tome. I attached a test map so you can see how it's done.
  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Dummy_Buyer[1] = DUMMY 0006 <gen>
      • Set Dummy_Buyer[2] = DUMMY 0003 <gen>
      • Set Dummy_Buyer[3] = DUMMY 0004 <gen>
      • Set Dummy_Buyer[4] = DUMMY 0007 <gen>
      • Set Dummy_Buyer[5] = DUMMY 0008 <gen>
      • Set Dummy_Buyer[6] = DUMMY 0009 <gen>
      • -------- etc --------
  • Add Fake Tomes
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Player_Index = (Player number of (Owner of (Hero manipulating item)))
      • -------- Agility --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal Tome of Agility
          • (Dummy_Buyer[Player_Index] has an item of type Tome of Agility (Fake)) Equal to FALSE
        • Then - Actions
          • Hero - Create Tome of Agility (Fake) and give it to Dummy_Buyer[Player_Index]
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Intelligence (Fake))
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Strength (Fake))
        • Else - Actions
      • -------- Intelligence --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Tome of Intelligence
          • (Dummy_Buyer[Player_Index] has an item of type Tome of Intelligence (Fake)) Equal to FALSE
        • Then - Actions
          • Hero - Create Tome of Intelligence (Fake) and give it to Dummy_Buyer[Player_Index]
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Agility (Fake))
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Strength (Fake))
        • Else - Actions
      • -------- Strength --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Tome of Stength
          • (Dummy_Buyer[Player_Index] has an item of type Tome of Strength (Fake)) Equal to FALSE
        • Then - Actions
          • Hero - Create Tome of Strength (Fake) and give it to Dummy_Buyer[Player_Index]
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Agility (Fake))
          • Item - Remove (Item carried by Dummy_Buyer[Player_Index] of type Tome of Intelligence (Fake))
        • Else - Actions
  • Prevent Buying Tomes
    • Events
      • Unit - A unit owned by Neutral Passif Sells an item (from shop)
    • Conditions
    • Actions
      • Set Player_Index = (Player number of (Owner of (Buying unit)))
      • -------- Agility --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal Tome of Agility
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Intelligence (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Strength (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
      • -------- Intelligence --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Tome of Intelligence
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Agility (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Strength (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
      • -------- Strength --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Tome of Strength
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Agility (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Intelligence (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
 

Attachments

  • Prevent Buying Tomes.w3x
    20.1 KB · Views: 19
Level 3
Joined
Apr 18, 2018
Messages
58
  • Prevent Buying Tomes
    • Events
      • Unit - A unit owned by Neutral Passif Sells an item (from shop)
    • Conditions
    • Actions
      • Set Player_Index = (Player number of (Owner of (Buying unit)))
      • -------- Agility --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal Tome of Agility
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Intelligence (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Strength (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
      • -------- Intelligence --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Tome of Intelligence
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Agility (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Strength (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
      • -------- Strength --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to Tome of Strength
          • Or - Any (Conditions) are true
            • Conditions
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Agility (Fake)) Equal to TRUE
              • (Dummy_Buyer[Player_Index] has an item of type Tome of Intelligence (Fake)) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions

So do I have to add trigger "Remove Sold Item" to this part of trigger? In given map example, I can still buy any Tome. It shows the message, though.
 

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,379
These Power Up items can be purchased in shop. And once it is purchased a trigger fires, that adds ability to hero, who purchased item. Every time an item is purchased, it increases the level of ability aka Critical Chance. It goes up to 25 stacks. However, hero can buy more, but fail safe will work and will set it back to 25. But there is no gold refund. And I wanted to remove or delete that item from shop, once stacks are full. Or refund gold on purchase, followed by massage "max stacks reached". And I want a hero to be able to purchase only 1 out of 3 items and make him unable to purchase the other two.

Trigger looks like this:

  • Critical Strike Chance
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Critical Strike Chance
    • Actions
      • Set VariableSet Buying_UnitCSC = (Triggering unit)
      • Set VariableSet Buying_PlayerCSC = (Owner of Buying_UnitCSC)
      • Set VariableSet PlayerNumberCSC = (Player number of Buying_PlayerCSC)
      • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = (CriticalChance_Stacks[PlayerNumberCSC] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Equal to 0
        • Then - Actions
          • Unit - Add Critical Strike Item (+1%/+2%/+3%...etc) to Buying_UnitCSC
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Greater than or equal to 1
            • Then - Actions
              • Unit - Set level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC to CriticalChance_Stacks[PlayerNumberCSC]
              • Game - Display to (All players) the text: (String(CriticalChance_Stacks[PlayerNumberCSC]))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • CriticalChance_Stacks[PlayerNumberCSC] Greater than or equal to 25
                • Then - Actions
                  • Game - Display to (All players) the text: |cffff0000Maximum s...
                  • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = 25
                • Else - Actions
This trigger just needs to be adjusted slightly.

So it'll look like:
If level of crit equal to 0 -> add crit ability and Set Stacks equal to 1 (or you could set Stack's default value to 1)
ELSE
If level of crit less than 25 -> Set Stacks = Stacks + 1 and Set level of crit equal to Stacks
ELSE
Refund gold and display maximum text message

And here's a trick to easily refund gold. Change all of your Tome's PRIORITY stat to match the Gold Cost. So if your Tome costs 500 gold, set it's priority to 500 as well. Then use this action:
  • Player - Add (Item: (Item being manipulated)'s Integer Field: Priority ('ipri')) to (Triggering player) Current gold
Unfortunately, you can't get the Gold Cost using this method because Blizzard still hasn't added it (it's probably the most important stat but hey what do you expect), but using Priority to mimic Gold Cost works just fine. Priority has no actual use on Items so this is super convenient.
 

Attachments

  • example.png
    example.png
    24.6 KB · Views: 24
  • priority gold cost.png
    priority gold cost.png
    87.1 KB · Views: 40
Last edited:
Level 3
Joined
Apr 18, 2018
Messages
58
This trigger just needs to be adjusted slightly.

So it'll look like:
If level of crit equal to 0 -> add crit ability and Set Stacks equal to 1 (or you could set Stack's default value to 1)
ELSE
If level of crit less than 25 -> Set Stacks = Stacks + 1 and Set level of crit equal to Stacks
ELSE
Refund gold and display maximum text message

  • Critical Strike Chance
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Critical Strike Chance
    • Actions
      • Set VariableSet Buying_UnitCSC = (Triggering unit)
      • Set VariableSet Buying_PlayerCSC = (Owner of Buying_UnitCSC)
      • Set VariableSet PlayerNumberCSC = (Player number of Buying_PlayerCSC)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Equal to 0
        • Then - Actions
          • Unit - Add Critical Strike Item (+1%/+2%/+3%...etc) to Buying_UnitCSC
          • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = 1
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC) Less than 25
            • Then - Actions
              • Set VariableSet CriticalChance_Stacks[PlayerNumberCSC] = (CriticalChance_Stacks[PlayerNumberCSC] + 1)
              • Unit - Set level of Critical Strike Item (+1%/+2%/+3%...etc) for Buying_UnitCSC to CriticalChance_Stacks[PlayerNumberCSC]
              • Game - Display to (All players) the text: (String(CriticalChance_Stacks[PlayerNumberCSC]))
            • Else - Actions
              • Player - Add (Item: (Item being manipulated)'s Integer Field: Priority ('ipri')) to (Triggering player).Current gold
              • Game - Display to (All players) the text: |cffff0000Maximum S...
I did it like this, for gold Refund and it worked. Thanks, a lot.
 
Level 29
Joined
Feb 18, 2014
Messages
3,592
So do I have to add trigger "Remove Sold Item" to this part of trigger? In given map example, I can still buy any Tome. It shows the message, though.
I just realized that you are trying to add a real item via tomes, I thought you are trying to prevent the player from buying the same tome. Anyways, here's what you need to do :
  • Acquire Item Agility
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to Tome of Agility
    • Actions
      • Wait 0.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • ((Buying unit) has an item of type Crown of Kings +5) Equal to TRUE
              • ((Buying unit) has an item of type Mask of death) Equal to TRUE
        • Then - Actions
          • Game - Display to (All players) the text: You cannot buy this...
        • Else - Actions
          • Hero - Create Ring of Protection +5 and give it to (Buying unit)
 

Attachments

  • Prevent Buying Tomes.w3x
    19.4 KB · Views: 22
Last edited:
Status
Not open for further replies.
Top