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

Is there a trigger to buy units from shops?

Status
Not open for further replies.
Level 28
Joined
Jun 4, 2007
Messages
1,479
So let's say you have a Troll in there that costs 50 gold.

  • Buy Unit
    • Events
      • Unit - A unit comes within 350.00 of Ziggurat 0002 <gen>
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Owner of (Triggering unit)) Current gold) Greater than 50
        • Then - Actions
          • Player - Add -50 to (Owner of (Triggering unit)) Current gold
          • Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Position of Ziggurat 0002 <gen>) facing Default building facing (270.0) degrees
        • Else - Actions
Pretty simple though. If you have more units in the Merchant, wich is pretty likely, you should put a delay on lower prices (a wait action just before the If, Then, Else action).
Example:
2000 - no delay
1500 - wait 0.1 seconds
1350 - wait 0.2 seconds
1000 - wait 0.3 seconds
500 - wait 0.4 seconds
200 - wait 0.5 seconds
100 - wait 0.6 seconds
50 - wait 0.7 seconds

These prices are just examples. What I want to show you is that the lower the price gets, the higher delay you make before buying it. If you do that the AI will only buy the most expensive unit he... it can aford. Lets say it has 2010 gold, then it will buy the 2000 gold unit and nothing more cause it's out of gold. If it has 1560 gold, it will buy the 1500 gold unit and then the 50 gold unit.
 
Level 28
Joined
Jun 4, 2007
Messages
1,479
Well you'll have to add a condition that causes only the AI units to buy from the shop. You can buy whatever you want but the AI's are restricted to the trigger functions.
Add all AI controlled units to a unit group (variable), and then make the following condition:

Boolean - Unit is in Unit Group Equal to True

Then only the AI units will buy from the shop.
 
Status
Not open for further replies.
Top