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

[General] Hero buying custom Items (AI).

Status
Not open for further replies.
Level 14
Joined
Jun 15, 2016
Messages
749
Note: This topic focuses on built shops with Shop Sharing and Shop Purchase Item, *not relevant to neutral passive shop with Select Hero.

As the title said, I wanna learn more if custom triggers can do a trick better than basic AI Editor since it only allow us to toggle on/off AI to buy item from any shops or not. The bad things are:
- They can't buy custom items from other faction shops. Except consumable or charged items from original shops (Human, Orc, Undead, Nightelf).
- If transfer custom item to AI, they might not use and even sell it to original shop.

So, the questions about triggers are:
- How to detect if a hero is auto-chosen by a shop of its own faction, when that floating blue arrow indicated each hero per time? a GUI event or vJass function?
- How to force AI to use some items besides of consumable or charged items?

+4RP.
 
Level 12
Joined
Jun 15, 2016
Messages
472
Interesting...

Unfortunately when it comes to barebones AI, the only natives in the common.ai file are SetHeroesBuyItems and SetHeroesTakeItems. Both are pretty self explanatory flags for AI heroes to take items from the ground and buy certain items from who knows which shop. As you can probably tell this doesn't make for a very smart behavior but that's what we got for now.

Even less fortunate, from an small test I just made it seems that a shop does not receive any traceable order when it chooses a hero (only when someone explicitly switches shop user does the shop receive the "neutralinteract" order (with the id 852566). Also, considering the fact that custom items in any faction shop can be very different from their vanilla counterpart, you can't rely on the hard-coded computer behavior to handle those items as needed.

This part:
If transfer custom item to AI, they might not use and even sell it to original shop.
Is also very interesting, and could cause even more complications for you. Could you elaborate more about when AI heroes sell items at the shop, which items and if the flag SetHeroesBuyItems is set to true or false when that happens?

About the request itself:

- How to detect if a hero is auto-chosen by a shop of its own faction, when that floating blue arrow indicated each hero per time? a GUI event or vJass function?
- How to force AI to use some items besides of consumable or charged items?

Since there is no trigger way (that I know of) to check that, that part will probably need to be triggered manually with periodic triggers. These triggers should keep track on the current patron, and update accordingly when a patron leaves, the shop switches patron due to order, etc. This part shouldn't be to difficult.

The second request is much more difficult. since you cannot rely on hard coded behavior, you'll need to code it yourself. The only way I can think of to do this without performing a lot of extra computation is to create some sort of system to classify custom items according to the situation when they are used. That way, you can create a code to iterate over all AI controlled heroes, see if the conditions for using some sort of item are met, if those conditions are met, and there is an item appropriate to the situation, then the hero can use it. Iterating over all heroes like that once every 0.5-1.0 second should allow for a quick enough response time by AI heroes, while keeping the amount of computations performed feasible.
However, note that we overlooked here a big problem you mentioned: hard-coded AI behavior with items. As long as custom items don't cause radically different effects than their base items and are used correctly by the hard-coded behavior, and as long as you can predict and prevent cases when a hero sells an item it shouldn't sell, this system should do at least some good.
 
Status
Not open for further replies.
Top