• 🏆 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 can I detect if a player is buying an item from a shop?

Status
Not open for further replies.
Level 5
Joined
Feb 1, 2009
Messages
111
More specifically, is there a way to set a variable to the amount of gold spent when a player buys a shop item ? I am trying to restrict a player from buying something if his level is too low for the item and this would help.

Edit :

I actually would just need to know how to detect if a player has targetted a shop to buy an item. So the event of clicking on a shop ?
 
Last edited by a moderator:
Level 26
Joined
Aug 18, 2009
Messages
4,097
There is the unit event EVENT_UNIT_SELL_ITEM (playerunitevent EVENT_PLAYER_UNIT_SELL_ITEM).

GetSoldItem() returns the sold item, GetBuyingUnit() the buyer.

To get an item's gold cost, you can presave them in a data structure or make a workaround à la "order dummy shop to sell the item and look at the gold count before and after".
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Do like said above use a item gold cost system to get the gold the item costs. Then use the event to check if unit sells item.
Use an ITE to check if that unit is required lvl to buy the item. If it is not the required lvl remove the item add back gold / lumber and display a message.

I have a item / unit gold / lumber cost system in the spell section that you can use.
http://www.hiveworkshop.com/forums/spells-569/item-unit-cost-system-v1-0-0-3-a-245280/
 
Level 10
Joined
Apr 18, 2009
Messages
576
Edit :

I actually would just need to know how to detect if a player has targetted a shop to buy an item. So the event of clicking on a shop ?

Something like this?

  • Shop Selection
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Goblin Merchant
    • Actions
 
Status
Not open for further replies.
Top