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

How do you prevent item purchase on a hero

Status
Not open for further replies.
Level 3
Joined
Apr 16, 2016
Messages
28
I'd like to prevent certain players from purchasing an item from a shop.

If that player attempts to purchase a particular item, it should display a warning message, then the hero should not have the item in the inventory. Also, the stock quantity of the item from the shop should not be decreased.

How do you make the trigger for something like this?
 
Level 3
Joined
Apr 16, 2016
Messages
28
Here's a testing map I've made for you with an custom error message system, explanations are contained whithin the triggers!

PS: You can find more information on how it's done here: http://www.hiveworkshop.com/forums/...ls-279/creating-custom-error-messages-232494/
(Credits to Vexxorian, PurgeandFire and Faith)

I've seen the map, and I'm actually trying to prevent the purchase of an item, not picking one up. I was able to get the item purchase prevention part done, the part I'm having issue on is actually replenishing the stock in the shop.
 
Level 11
Joined
Oct 9, 2015
Messages
721
  • Melee Initialization
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to (Item-type of YourItem)
        • Then - Actions
          • Player - Set (Owner of (Buying unit)) Current gold to (((Owner of (Buying unit)) Current gold) + 100) --100 is just an value example!
          • Item - Remove (Sold Item)
        • Else - Actions
You'll need to do an If/Then/Else for each item if you wish to avoid using hashtables
 
Last edited:
Level 9
Joined
May 21, 2014
Messages
580
Item type of sold item equal to your item

then
Remove item
Set player gold to (current gold of player + (value of your item))

This is the way to go, but another problem is that you cannot simply just get the value of an item.
The only way out I had once was to store all items in a hashtable that contained their values.

  • Melee Initialization
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Sold Item)) Equal to (Item-type of YourItem)
        • Then - Actions
          • Player - Set (Owner of (Buying unit)) Current gold to (((Owner of (Buying unit)) Current gold) + 100) --100 is just an value example!
          • Item - Remove (Sold Item)
        • Else - Actions
You'll need to do an If/Then/Else for each item if you wish to avoid using hashtables

I saw the edit.
But the question remains: How is he going to get the sold item value? 100 is simply just a constant. WHat if the cost is 200? 300? 431?

To really know, I really think hashtable should exist.
 
Last edited by a moderator:
Level 9
Joined
May 21, 2014
Messages
580
As I said, there would be needed an If/Then/Else for each item if hashtables aren't going to be used

Oh I see! I was misguided by the sentence.

If/Then/Else for each item

Yes. You can definitely do this. Performance wise, if you got too many items that needs checking, use a data structure, maybe like an array for simplicity so long as you can store the data.

Using If statements on a LOT of items can become slow. Based on experience... lol.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Level 9
Joined
May 21, 2014
Messages
580
Actually I'd try a different approach, because one if block per item is annoying.

Use: http://www.hiveworkshop.com/forums/spells-569/getitemcost-275308/?prev=search=cost&d=list&r=20

There are other systems with the same functionality if you want it in GUI: http://www.hiveworkshop.com/forums/...-0-1-0-a-245280/?prev=search=cost&d=list&r=20

The GUI system is currently awaiting update. I have contacted deathismyfriend about the GUI version a long time ago about the system because I was supposed to use it. It turned out to be returning to wrong item value for me when I integrated it to my map.

The JASS version seems promising, but tests should still be done if it works correctly upon integration.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Use Object Data Extractor instead to get the gold cost...

Thanks for sharing that.

edit: Not sure if it's buggy or something but I used:
JASS:
native GetUnitGoldCost takes integer unitid returns integer
  • Untitled Trigger 002
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg(I2S(GetUnitGoldCost('hfoo')))
Which wrote 135, which is the gold used for footmen.
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
There are a few fields that do not return values that you think they return... for example, unit abilities are a string :D (it does make sense, but you should take a close look before assuming something.

Also, there are a few fields that do not work, these are ussually tooltips.
 
Status
Not open for further replies.
Top