Unit in range of item-class

gbubic2

Active Member
Reaction score
0
I am trying to make trigger so that unit (not hero) comes in range of item of class...
And picks it up, and it will keep doing so until it's inventory slot's are full. Can you help me.
 

Angelusz

New Member
Reaction score
2
Since I'm not very advanced at JASS yet, I can only tell you about GUI.

In GUI triggering, it's not possible detect wheter or not a unit is near an item. However, using triggers, you could create a dummy unit on top of every item of the type you want to be auto-picked up. Assign this dummy unit to the item in question and when the unit gets near the dummy unit, remove the dummy unit and give the item to the unit. if the inventory is full, just use conditions so the trigger won't run. This will all be really simple to make.

The effect would be, that if there's like 6 items on the ground next to eachother, the unit will pick all 6 up instantly.

If you need more specific help, in the shape of a trigger, tell me. You didn't tell/show if you have basic GUI/JASS knowledge.

~Angelusz
 

Choppa

www.warcraft-gamers.po.gs
Reaction score
59
Could do something like this...
Code:
Untitled Trigger 001
    Events
        Time - Every 0.10 seconds of game time
    Conditions
    Actions
        Set tempItemPos = (Position of (Last created item))
        Unit Group - Pick every unit in (Units within 200.00 of tempItemPos matching (((Unit-type of (Matching unit)) is A ground unit) Equal to True)) and do (Actions)
            Loop - Actions
                Hero - Give (Last created item) to (Picked unit)
        Custom script:   call RemoveLocation( udg_tempItemPos )
 

Chjoodge

New Member
Reaction score
14
I hope I understood you well.

Code:
Events
Conditions
Actions
    Item - Pick every item in (Playable map area) and do (Actions)
        Loop - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Item-type of (Picked item)) Equal to {Your item here}
                Then - Actions
                    Set APointVariable = (Position of (Picked item))
                    Set AnUnitGroupVariable = (Units within {Your range here} of APointVariable matching (((Matching unit) is A Hero) Equal to False))
                    --------   --------
                    Unit Group - Pick every unit in AnUnitGroupVariable and do (Actions)
                        Loop - Actions
                            For each (Integer A) from 1 to ((Size of inventory for (Picked unit)) - (Number of items carried by (Picked unit))), do (Actions)
                                Loop - Actions
                                    Hero - Create (Item-type of (Picked item)) and give it to (Picked unit)
                    --------   --------
                    Item - Remove (Picked item)
                    --------   --------
                    Custom script:   call RemoveLocation(udg_APointVariable)
                    Custom script:   call DestroyGroup(udg_AnUnitGroupVariable)
                Else - Actions
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Chjoodge's trigger should work well. However, note that you can order the hero to pick it, instead of creating a new item and destroying the old. That is, if you want. You could find this action in Actions > Units > Issue unit order targeting object.
 

gbubic2

Active Member
Reaction score
0
I hope I understood you well.

Code:
Events
Conditions
Actions
    Item - Pick every item in (Playable map area) and do (Actions)
        Loop - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Item-type of (Picked item)) Equal to {Your item here}
                Then - Actions
                    Set APointVariable = (Position of (Picked item))
                    Set AnUnitGroupVariable = (Units within {Your range here} of APointVariable matching (((Matching unit) is A Hero) Equal to False))
                    --------   --------
                    Unit Group - Pick every unit in AnUnitGroupVariable and do (Actions)
                        Loop - Actions
                            For each (Integer A) from 1 to ((Size of inventory for (Picked unit)) - (Number of items carried by (Picked unit))), do (Actions)
                                Loop - Actions
                                    Hero - Create (Item-type of (Picked item)) and give it to (Picked unit)
                    --------   --------
                    Item - Remove (Picked item)
                    --------   --------
                    Custom script:   call RemoveLocation(udg_APointVariable)
                    Custom script:   call DestroyGroup(udg_AnUnitGroupVariable)
                Else - Actions
Events
Conditions
Actions
Item - Pick every item in (Playable map area) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Item-type of (Picked item)) Equal to {Your item here}
Then - Actions
Set APointVariable = (Position of (Picked item))
Set AnUnitGroupVariable = (Units within {Your range here} of APointVariable matching (((Matching unit) is A Hero) Equal to False))
-------- --------
Unit Group - Pick every unit in AnUnitGroupVariable and do (Actions)
Loop - Actions
For each (Integer A) from 1 to ((Size of inventory for (Picked unit)) - (Number of items carried by (Picked unit))), do (Actions)
Loop - Actions
Hero - Create (Item-type of (Picked item)) and give it to (Picked unit)
-------- --------
Item - Remove (Picked item)
-------- --------
Custom script: call RemoveLocation(udg_APointVariable)
Custom script: call DestroyGroup(udg_AnUnitGroupVariable)
Else - Actions

CAN YOU HELP ME WITH THIS LAST TWO I CAN'T GET IT WORK I HAVE AN ERROR.
THANK YOU FOR YOUR HELP I DONT UNDERSTAN A THING ABOUT THIS TRIGGER BUT I FOUND EVERYTHING EXCEPT THIS LAST TWO WITH WITCH I HAVE PROBLEM.
THANKS
 

Chjoodge

New Member
Reaction score
14
You can make these with two Custom Script actions. As the string you'll have to specify, enter:

call RemoveLocation(udg_APointVariable)

...for one and the other line for the other. Note that the "APointVariable" and "AnUnitGroupVariable" are actually names of the variables used in the trigger. If you named those variables something else (and you should :)), you'll have to change these parts to the names of your variables.

Btw, check out some memory leak tutorial.
 

gbubic2

Active Member
Reaction score
0
But..

i did all of that i even set that variable
Variable tipe: point
Initial value: None
and i put the right name of variable in. But it is not working.
Please help me :banghead: my eyes will fall out:eek:
Thanks <3
 

Chjoodge

New Member
Reaction score
14
Right-click on the name of your trigger, choose Copy as text, then paste the text here.
 

denmax

You can change this now in User CP.
Reaction score
155
call RemoveLocation(udg_APointVariable)

The most common mistakes are these..

call RemoveLocation( udg_APointVariable )
call RemoveLocation (udg_APointVariable)
call removelocation (udg_APointVariable)
call RemoveLocation(udg_apointvariable)

Remember that it is CaSe SeNsItIvE

And also, are you sure you placed the name of the variable after udg_?
 

gbubic2

Active Member
Reaction score
0
Jup found the mistake :eek:
There is no error anymore, thanks guys! But (i know "but" is annoying word) those units are not picking up items. They are just standing there and watching them. :eek:
How will i get your rep+, where do i click for that?

Thanks! I am new at this all so forgive me for beeing :nuts:
 

denmax

You can change this now in User CP.
Reaction score
155
Jup found the mistake :eek:
There is no error anymore, thanks guys! But (i know "but" is annoying word) those units are not picking up items. They are just standing there and watching them. :eek:
How will i get your rep+, where do i click for that?

Thanks! I am new at this all so forgive me for beeing :nuts:

You can add/minus reputation by clicking the scale in the upper right of every post/reply..

Are you sure your unit has an inventory? If so then did YOU order your unit to get the item? Maybe that's why it's not doing anything, at all..
 

Chjoodge

New Member
Reaction score
14
They are just standing there and watching them. :eek:
That's right. What the trigger I gave you does is that as soon as a unit comes very close to an item, all its free inventory slots are filled with that item and the lying item is removed. Well, at least it should work like that, I didn't test it.

If you want the trigger to work somehow else, you'll need a different trigger.

Note that the trigger works only for non-heroes, as you wanted.

EDIT: Also, what range are you using here?
Code:
Set AnUnitGroupVariable = (Units within [B]{Your range here}[/B] of APointVariable matching (((Matching unit) is A Hero) Equal to False))
 

gbubic2

Active Member
Reaction score
0
No brains

I give up.I have attached map where i tested that trigger. If you would be so kind to check it out and tell me what I am doing wrong. I really appreciate you help!
Thanks!
 

Attachments

  • brains.w3x
    13.3 KB · Views: 150

denmax

You can change this now in User CP.
Reaction score
155
I dun' really get what your trying to do.

Do you want the unit to keep picking the item up until its inventory slot it full but still the item is there OR make any UNIT unable to pick up the item?
 

gbubic2

Active Member
Reaction score
0
It is like this: You play warcraf map like any other, you build (for example) 5 footmans and a hero. And you attack some enemies, those enemies drop some items, and that items are: lets say charged type. So, point is that I don’t need to order each footman to pick up every and each item. When footman comes close enough he will pick (charged type item) it up by it self until he’s slots are full.
Lets say you have in group 5 footmans and 5 riflemans and they come in range of charged type item. Rifleman will not pick up that item because he uses “permanent type” item. And footman needs to know that charged type is his type of item and he will without your order come to that item and pick it up. :cool:

Thanks for your time!
 

Chjoodge

New Member
Reaction score
14
Oh. Now that is very different from what I understood from the op. *Sigh.* :)

I've got a boring lesson ahead of me now, so I'll trigger that for you and post it here later.
 

Chjoodge

New Member
Reaction score
14
Here you go.

Code:
Data initialization
    Events
        Map initialization
    Conditions
    Actions
        -------- =================================================================================== --------
        Set AutoItemPickUp_Table_UnitType[1] = Footman
        Set AutoItemPickUp_Table_ItemClass[1] = Permanent
        --------   --------
        Set AutoItemPickUp_Table_UnitType[2] = Rifleman
        Set AutoItemPickUp_Table_ItemClass[2] = Charged
        --------   --------
        Set AutoItemPickUp_Table_UnitType[3] = Sorceress
        Set AutoItemPickUp_Table_ItemClass[3] = Purchasable
        -------- =================================================================================== --------
        -------- This sets the range at which the unit will go automatically pick up its item --------
        Set AutoItemPickUp_Range = 400.00
        -------- =================================================================================== --------
        -------- This saves how many (Unit-type)>>(Item-class) matches have you specified. --------
        Set AutoItemPickUp_TableSize = 3

Code:
Periodic check
    Events
        Time - Every 0.50 seconds of game time
    Conditions
    Actions
        -------- For each item: --------
        Item - Pick every item in (Playable map area) and do (Actions)
            Loop - Actions
                -------- For each item-class that is to be auto-picked up: --------
                For each (Integer AutoItemPickUp_ForIndex) from 1 to AutoItemPickUp_TableSize, do (Actions)
                    Loop - Actions
                        -------- If we found an item-class of our picked item in our table: --------
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                (Item-class of (Picked item)) Equal to AutoItemPickUp_Table_ItemClass[AutoItemPickUp_ForIndex]
                            Then - Actions
                                -------- Build an unit group of nearby units of the appropriate type and with a free inventory slot --------
                                Set AutoItemPickUp_Point = (Position of (Picked item))
                                Set AutoItemPickUp_UnitGroup = (Units within AutoItemPickUp_Range of AutoItemPickUp_Point matching (((Unit-type of (Matching unit)) Equal to AutoItemPickUp_Table_UnitType[AutoItemPickUp_ForIndex]) and (((Size of inventory for (Matching unit)) - (Number of items carried by (Matching unit)))
                                -------- For each such unit: --------
                                Unit Group - Pick every unit in AutoItemPickUp_UnitGroup and do (Actions)
                                    Loop - Actions
                                        Unit - Order (Picked unit) to Right-Click (Picked item)
                                --------   --------
                                Custom script:   call RemoveLocation(udg_AutoItemPickUp_Point)
                                Custom script:   call DestroyGroup(udg_AutoItemPickUp_UnitGroup)
                            Else - Actions

Tested and works. See the attached map. All the things you need to set up are in the first trigger.
 

Attachments

  • AutoItemPickUp.w3x
    15.4 KB · Views: 149

gbubic2

Active Member
Reaction score
0
Thank YOU so much for this!! <3
I would never made this by my selfe. I can't even understand that you can understand how to make things like this!:eek:
Anyway thanks alot!!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top