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

[Solved] AI Hero to pick up items

Status
Not open for further replies.
Level 2
Joined
Jan 1, 2018
Messages
9
First post and a I'm a bit of a mapmaking noob so bear with me.

I want my AI controlled enemy hero "Black Arrow" to pick up items/power ups etc. while farming creeps in my slightly sloppy, highly improvised single player DOTA style map. I don't know how to get Black Arrow to wait until the end of a creep fight to pick up items and I obviously don't want her to go and pick them up mid-fight while creeps are still attacking, so I set the dropped item to teleport to her, to avoid disturbing the fight.

This is my attempt. Why is it not working?

  • Pick Up Items
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Killing unit) Equal to |c007900f2Black Arrow|r 0291 <gen>
      • Healing Equal to False
    • Actions
      • Set ItemA = (Position of (Dying unit))
      • Set ItemB = (Region centered at ItemA with size (800.00, 800.00))
      • Item - Pick every item in ItemB and do (Actions)
        • Loop - Actions
          • Item - Move (Picked item) to (Position of |c007900f2Black Arrow|r 0291 <gen>)
          • Unit - Order |c007900f2Black Arrow|r 0291 <gen> to Right-Click (Picked item)
      • Custom script: call RemoveLocation(udg_ItemA)
      • Custom script: call RemoveRect(udg_ItemB)
Thanks for your help.
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
The problem might be, that the item created from a dying unit is only created after this trigger runs. So Black Arrow tries to pick up items when there are no items yet.
Another problem is, that the order takes some time to be executed. In case there are more items, probably only one is picked up.

Are the items correctly teleported to the hero?
 
Level 2
Joined
Jan 1, 2018
Messages
9
I see, so maybe put in a 1 sec to give the item time to come into the game? I'll try it.

At the moment the items aren't even teleporting.
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
In general it is good practice to add debug messages to a trigger that does not work.
First you want to find out what is not working. Then it's usually quite easy to realize why it does not work and how to fix it.

At first you make sure that the trigger even runs. You can print the trigger name at the beginning of the trigger. If that works fine, if not
either your events or conditions are wrong.

Now you also want to know for which items the trigger is run. Print out the item names in the item group. If no item is printed you might have to add a delay, so the trigger runs after the item was created.

After that if the debug messages all work, the items should be correctly placed at the hero's position.
If the hero still does not pick the items up, the "Unit - Order" action is not working correctly. In that case it is more complicated to fix it.
The order functions are usually harder to debug.

  • Pick Up Items
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Killing unit) Equal to |c007900f2Black Arrow|r 0291 <gen>
      • Healing Equal to False
    • Actions
      • Game - Display to (All players) the text: Pick Up Items
      • Set ItemA = (Position of (Dying unit))
      • Set ItemB = (Region centered at ItemA with size (800.00, 800.00))
      • Item - Pick every item in ItemB and do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (Name of (Picked item))
          • Item - Move (Picked item) to (Position of |c007900f2Black Arrow|r 0291 <gen>)
          • Unit - Order |c007900f2Black Arrow|r 0291 <gen> to Right-Click (Picked item)
      • Custom script: call RemoveLocation(udg_ItemA)
      • Custom script: call RemoveRect(udg_ItemB)
 
Level 2
Joined
Jan 1, 2018
Messages
9
The wait fixed it! :) So it turns out items don't drop exactly at the time of death.

Thanks for your help. I'll certainly be using the debug trick in the future. Here's the final trigger.

  • Pick Up Items
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Killing unit) Equal to |c007900f2Black Arrow|r 0291 <gen>
      • Healing Equal to False
    • Actions
      • Wait 1.00 seconds
      • Set ItemA = (Position of (Dying unit))
      • Set ItemB = (Region centered at ItemA with size (800.00, 800.00))
      • Item - Pick every item in ItemB and do (Actions)
        • Loop - Actions
          • Item - Move (Picked item) to (Position of |c007900f2Black Arrow|r 0291 <gen>)
          • Unit - Order |c007900f2Black Arrow|r 0291 <gen> to Right-Click (Picked item)
      • Custom script: call RemoveLocation(udg_ItemA)
      • Custom script: call RemoveRect(udg_ItemB)
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
So it turns out items don't drop exactly at the time of death.
Actually the item drops kind of at the same time. Item drops in the editor are coverted into a trigger in the map script. The trigger uses the "specific unit dies" event.
I guess a 0 second delay would already be enough.

Here's the final trigger.
Two things:
(dying unit) after the wait can cause problems
referring to dying unit after a wait will not always return the correct unit. Replace it with "triggering unit". Triggering unit is not affected by waits.

Within the "pick every item" you have a point leak: position of "Black Arrow"
 
Level 2
Joined
Jan 1, 2018
Messages
9
How do I fix the leak? I could set BA's position through a point variable (BA_Position) and then "Custom script: call RemoveLocation(udg_BA_Position)". Is there a quicker and tidier way of doing this?
 
Level 15
Joined
Mar 25, 2016
Messages
1,327
Yes, use the point variable. However set the point variable before the "pick every item" and the remove the point after "pick every item". This way you only create the points once instead for every item in range.
In JASS you use coordinates (x,y) instead of points. It is faster, because you don't have to create new objects (points/locations) and instead use real variables. In GUI you cannot work with x,y coordinates unfortunately.
 
Status
Not open for further replies.
Top