• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Buying Units trigger?

Status
Not open for further replies.
Level 5
Joined
Jun 13, 2012
Messages
113
So this trigger is for an Ai. My map heavily based on merc camps, i need to have a trigger, when the ai hero steps near the merc camp or steps in the region, the ai will buy units listed in the merc camp. I do not see any triggers for that in netural buildings or in issue order. Does train unit count as buying unit? if not what trigger can i use for this?
 
Level 5
Joined
Jul 12, 2016
Messages
59
You could make it so that the AI doesn't actually buy anything, but instead you remove the stock of your units from the merc camp and spawn the units instead, something along the lines of this:

  • AI Buy
    • Events
      • Unit - A unit comes within 256.00 of Mercenary Camp (Lordaeron Summer) 0000 <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Neutral Building - Remove Footman from Mercenary Camp (Lordaeron Summer) 0000 <gen>
      • Neutral Building - Add Footman to Mercenary Camp (Lordaeron Summer) 0000 <gen> with 0 in stock and a max stock of 1
      • Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Position of Mercenary Camp (Lordaeron Summer) 0000 <gen>) facing Default building facing degrees
Adding and removing unit stock with triggers is a bit funky though, you can't manipulate unit stocks that are default to the merc camp in the object editor, so you'll instead have to add them through a separate trigger at map initialization or something. Also, you need to make sure that your merc camps have the "Sell Units" ability, otherwise it also doesn't work.

As for your second question, the event you're looking for is "Generic Unit Event - A unit Sells a unit".

Edit: I just realised that the trigger doesn't take into account if the merc camp doesn't have any stock for the unit remaining, so you'd have to add a condition to check for that. I don't think there's an easy build-in condition to check for if a merc camp has a unit in stock, so the way I'd go around solving it would probably be setting up a bunch of timers that track when units are being bought.
 
Last edited:
Level 5
Joined
Jun 13, 2012
Messages
113
You could make it so that the AI doesn't actually buy anything, but instead you remove the stock of your units from the merc camp and spawn the units instead, something along the lines of this:

  • AI Buy
    • Events
      • Unit - A unit comes within 256.00 of Mercenary Camp (Lordaeron Summer) 0000 <gen>
    • Conditions
      • ((Owner of (Triggering unit)) controller) Equal to Computer
    • Actions
      • Neutral Building - Remove Footman from Mercenary Camp (Lordaeron Summer) 0000 <gen>
      • Neutral Building - Add Footman to Mercenary Camp (Lordaeron Summer) 0000 <gen> with 0 in stock and a max stock of 1
      • Unit - Create 1 Footman for (Owner of (Triggering unit)) at (Position of Mercenary Camp (Lordaeron Summer) 0000 <gen>) facing Default building facing degrees
Adding and removing unit stock with triggers is a bit funky though, you can't manipulate unit stocks that are default to the merc camp in the object editor, so you'll instead have to add them through a separate trigger at map initialization or something. Also, you need to make sure that your merc camps have the "Sell Units" ability, otherwise it also doesn't work.

As for your second question, the event you're looking for is "Generic Unit Event - A unit Sells a unit".

Ya for the "Generic Unit Event - A unit Sells a unit" that only works for player. Was wondering if there was an action or condition that would relate to the event. But it seems like from what you provide me it doesnt seem like there is.
 
Level 5
Joined
Jun 13, 2012
Messages
113
You could make the trigger I posted additionally run the "Sell a unit" trigger that you want to run.
Thing is it wont work for ai. As the event requires a unit to be bought, and only the player can buy a unit. Unless there is away to make the ai buy a unit then the event would work. so what i was trying to say is that, if there is a action or condition that we can use to literally buy from merc camp then the event would work. So for bad grammer english not my first language
 
Level 5
Joined
Jun 13, 2012
Messages
113
Thing is it wont work for ai. As the event requires a unit to be bought, and only the player can buy a unit. Unless there is away to make the ai buy a unit then the event would work. so what i was trying to say is that, if there is a action or condition that we can use to literally buy from merc camp then the event would work. Sorry for bad grammer english not my first language
 
Level 3
Joined
Mar 18, 2020
Messages
20
Units do not buy units from shops, players do. This means there isn't an order ID for a unit to buy a unit from a shop, which means you can't order a unit to buy a unit.

As DrunkenDirt suggested, the best way to do this is probably to simulate buying a unit from a shop with triggers for the AI. Checking if they have enough gold, etc., if so, then create the unit. Make sure you set the position of the selling unit as a variable and remove it afterward to prevent leaks (call RemoveLocation (udg_TempPoint)).

You can derive a system to check for a unit being in stock or not with a separate set of triggers and timers for each mercenary camp (e.g., every 60 seconds, set stock of a camp to stock + 1 unless stock is at stock maximum).
 
Status
Not open for further replies.
Top