• 🏆 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] How to grab nearby item?

Status
Not open for further replies.

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
  • Hero - Give (Random item in (Playable map area)) to (Triggering unit)
You can pick an item in a region. Problem is: Regions are no circles, but you can use matching condition to check if the distance is smaller than a certain range.
 
A whole functionating example with leak cleaning.
  • Grap Near Item
    • Events
      • Unit - A unit cast a spell
    • Conditions
      • (Ability being cast) Equal Grab Item
    • Actions
      • Set Loc = (Position of (Triggering unit))
      • -------- Beaware that, this is a/b's total edge length. Means has half range from the center. Here 300. --------
      • Set Rect = (Region centered at Loc with size (600.00, 600.00))
      • Set Item = (Random item in Rect)
      • Hero - Give Item to (Triggering unit)
      • Custom script: call RemoveLocation(udg_Loc)
      • Custom script: call RemoveRect(udg_Rect)
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Random item in rect is a rectangular area to search for items.
As there is no items in range you need to use (items in region matching distance to grabbing unit less than ...) to have an items in range function.
You could also put the distance comparison within the picked items function and let it pick the closest item.
 
Status
Not open for further replies.
Top