• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Automatic item pick up

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2010
Messages
312
A project i'm working on requires heroes in a pre defined group to automatically pickup items in a certain area around their current position. I cant seem to find any spells or threads about this so maybe its something easy that I cant think of haha

  • Auto Pick Up
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • Set temp_point = (Position of (Picked unit))
          • Unit - Order R_Hero[(Player number of (Owner of (Picked unit)))] to Right-Click (Random item in (Region centered at temp_point with size (750.00, 750.00)))
          • Custom script: call RemoveLocation(udg_temp_point)
The heroes are placed in the R_Hero group after they have been created. Thanks in advance!
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
If you prefer GUI (although I'd recommend you rather use the system suggested above), I made one of these in my Ancient Protector map (in sig):

  • Auto Item Pickup Copy
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in PlayerForce and do (Actions)
        • Loop - Actions
          • Set tempplayerid = (Player number of (Picked player))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (PlayerHero[tempplayerid] is dead) Equal to False
            • Then - Actions
              • Set temploc = (Position of PlayerHero[tempplayerid])
              • Region - Center Rock Gather Range <gen> on temploc
              • Item - Pick every item in Rock Gather Range <gen> and do (Actions)
                • Loop - Actions
                  • Hero - Give (Picked item) to PlayerHero[tempplayerid]
              • Custom script: call RemoveLocation(udg_temploc)
            • Else - Actions
  • Create a region on the map, the size of which will be the pickup range. Save that to a variable, and reference that in the "pick every item" above.
  • PlayerHero[] is the unit variable I use to refer to each player's hero.
  • It might bug a bit with powerups; since they are removed but not really removed. Something like that.
 
Level 9
Joined
Apr 23, 2010
Messages
312
Thanks a lot guys!

@rulerofiron99, Yes it does bug a bit with power ups by continuously giving the same power up to the hero. I tried a couple different things to fix this and got it to only give it twice but thats still not going to cut it. Heres what i've done...
  • Auto Pick Up
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set temp_point = (Position of (Picked unit))
              • Region - Center AutoPickup <gen> on temp_point
              • Item - Pick every item in AutoPickup <gen> and do (Actions)
                • Loop - Actions
                  • Hero - Give (Picked item) to (Picked unit)
                  • Item - Remove (Picked item)
              • Custom script: call RemoveLocation(udg_temp_point)
            • Else - Actions
Creating the item and giving it to the hero is even worse, it crashed my computer.
 
Level 9
Joined
Apr 23, 2010
Messages
312
Then you'll probably have to trigger a special case for powerups.

In the "pick every item" loop, use an if/then/else to check if the item is a powerup, and then rather order the hero to right click it instead of giving it to the hero.

Yup i've fixed the issue.

  • Auto Pick Up
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set temp_point = (Position of (Picked unit))
              • Region - Center AutoPickup <gen> on temp_point
              • Item - Pick every item in AutoPickup <gen> and do (Actions)
                • Loop - Actions
                  • Set temp_point_2 = (Position of (Picked item))
                  • Hero - Give (Picked item) to (Picked unit)
                  • Special Effect - Create a special effect at temp_point_2 using Abilities\Spells\Undead\DarkRitual\DarkRitualTarget.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Undead\DarkRitual\DarkRitualTarget.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • If (((Picked unit) has an item of type Topaz) Equal to True) then do (Player - Add 25 to (Owner of (Picked unit)) Current gold) else do (Do nothing)
                  • If (((Picked unit) has an item of type Sapphire) Equal to True) then do (Hero - Modify Intelligence of (Picked unit): Add 1) else do (Do nothing)
                  • If (((Picked unit) has an item of type Ruby) Equal to True) then do (Hero - Modify Strength of (Picked unit): Add 1) else do (Do nothing)
                  • If (((Picked unit) has an item of type Emerald) Equal to True) then do (Hero - Modify Agility of (Picked unit): Add 1) else do (Do nothing)
                  • Item - Remove (Picked item)
              • Custom script: call RemoveLocation(udg_temp_point)
            • Else - Actions
Thanks again!
 
Each 0.1 seconds and for each item in region you would do this gold & stats modifying actions.

Maybe you would want to do so only when it has picked up this itemType you check via condition?

If so you need to check after the PickUp action, if itemType of pickedItem was your matching itemType and if unit has succesfully picked up the item. (boolean comparisson, if unit owns the item)
 
Level 9
Joined
Apr 23, 2010
Messages
312
@IcemanBo,I thought I already was checking the item type via boolean? Just not using the multiple actions IFE.

@Chaosy, Thanks, I like the range better than the region, less boxy :)

  • Auto Pick Up
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set temp_point = (Position of (Picked unit))
              • Item - Pick every item in (Playable map area) and do (Actions)
                • Loop - Actions
                  • Set temp_point_2 = (Position of (Picked item))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Integer((Distance between temp_point and temp_point_2))) Less than or equal to 350
                    • Then - Actions
                      • Hero - Give (Picked item) to (Picked unit)
                      • Special Effect - Create a special effect at temp_point_2 using Abilities\Spells\Human\Polymorph\PolyMorphDoneGround.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Undead\DeathPact\DeathPactTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • If (((Picked unit) has an item of type Topaz) Equal to True) then do (Player - Add 25 to (Owner of (Picked unit)) Current gold) else do (Do nothing)
                      • If (((Picked unit) has an item of type Sapphire) Equal to True) then do (Hero - Modify Intelligence of (Picked unit): Add 1) else do (Do nothing)
                      • If (((Picked unit) has an item of type Ruby) Equal to True) then do (Hero - Modify Strength of (Picked unit): Add 1) else do (Do nothing)
                      • If (((Picked unit) has an item of type Emerald) Equal to True) then do (Hero - Modify Agility of (Picked unit): Add 1) else do (Do nothing)
                      • Item - Remove (Picked item)
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_temp_point)
              • Custom script: call RemoveLocation(udg_temp_point_2)
            • Else - Actions
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Checking every item in the whole map using a distance calculation is a very bad idea if there are going to be lots of items.

Rather use a combination of our methods:
  • From my method, create and move a region along. Make this region as big as the circle.
  • Check the distances to items within this region, from Chaosy's method.

The temp_point_2 location removal must be done within the loop, or it will leak plenty.
 
Level 9
Joined
Apr 23, 2010
Messages
312
@rulerofiron99, Ok I see what you mean. Took your suggestion and have made a combination of the two and fixed the remove temp point 2 by placing it in the loop.

@IcemanBo, So do you mean there should be an additional trigger checking the item once it's been picked up, and then doing the actions? Sorry if i seem confused.
 
Each 0.1 seconds and for each item in region you would do this gold & stats modifying actions.

Maybe you would want to do so only when it has picked up this itemType you check via condition?

If so you need to check after the PickUp action, if itemType of pickedItem was your matching itemType and if unit has succesfully picked up the item. (boolean comparisson, if unit owns the item)
Read last line. No extra trigger is needed, but only checks. (If-block)
 
Level 9
Joined
Apr 23, 2010
Messages
312
ALright sounds good. How does it look now?

  • Auto Pick Up
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Heroes and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Set temp_point = (Position of (Picked unit))
              • Region - Center AutPickUp <gen> on temp_point
              • Item - Pick every item in AutPickUp <gen> and do (Actions)
                • Loop - Actions
                  • Set temp_point_2 = (Position of (Picked item))
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Integer((Distance between temp_point and temp_point_2))) Less than or equal to 300
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Item carried by (Picked unit) in slot 1) Equal to EmptySlot
                          • (Item carried by (Picked unit) in slot 2) Equal to EmptySlot
                          • (Item carried by (Picked unit) in slot 3) Equal to EmptySlot
                          • (Item carried by (Picked unit) in slot 4) Equal to EmptySlot
                          • (Item carried by (Picked unit) in slot 5) Equal to EmptySlot
                          • (Item carried by (Picked unit) in slot 6) Equal to EmptySlot
                    • Then - Actions
                      • Hero - Give (Picked item) to (Picked unit)
                      • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Spells\Other\Monsoon\MonsoonBoltTarget.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • Special Effect - Create a special effect at temp_point_2 using Abilities\Spells\Human\Polymorph\PolyMorphDoneGround.mdl
                      • Special Effect - Destroy (Last created special effect)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Picked item)) Equal to Topaz
                        • Then - Actions
                          • Player - Add 25 to (Owner of (Picked unit)) Current gold
                          • Floating Text - Create floating text that reads +25 at temp_point_2 with Z offset 12.50, using font size 10.00, color (95.00%, 95.00%, 10.00%), and 0.00% transparency
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Picked item)) Equal to Ruby
                        • Then - Actions
                          • Hero - Modify Strength of (Picked unit): Add 1
                          • Floating Text - Create floating text that reads +1 at temp_point_2 with Z offset 12.50, using font size 10.00, color (100.00%, 10.00%, 10.00%), and 0.00% transparency
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Picked item)) Equal to Sapphire
                        • Then - Actions
                          • Hero - Modify Intelligence of (Picked unit): Add 1
                          • Floating Text - Create floating text that reads +1 at temp_point_2 with Z offset 12.50, using font size 10.00, color (35.00%, 50.00%, 100.00%), and 0.00% transparency
                        • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Item-type of (Picked item)) Equal to Emerald
                        • Then - Actions
                          • Hero - Modify Agility of (Picked unit): Add 1
                          • Floating Text - Create floating text that reads +1 at temp_point_2 with Z offset 12.50, using font size 10.00, color (10.00%, 100.00%, 10.00%), and 0.00% transparency
                        • Else - Actions
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Set the velocity of (Last created floating text) to 50.00 towards 90.00 degrees
                      • Floating Text - Change the lifespan of (Last created floating text) to 3.25 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 0.75 seconds
                      • Floating Text - Show (Last created floating text) for (Player group((Owner of (Picked unit))))
                      • Item - Remove (Picked item)
                    • Else - Actions
                  • Custom script: call RemoveLocation(udg_temp_point_2)
              • Custom script: call RemoveLocation(udg_temp_point)
            • Else - Actions
 
Status
Not open for further replies.
Top