HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[HELP] How to pickup items without clicking

01-10-2008, 12:30 AM#1
Elhyse
I'm making an all keyboard control map and by all keyboard it means I can't click on items to pick them up. I've been toying with my Trigger Editor but I just can't find a way to create this. Basically I had this algorithm in mind:

1.Unit casts Pickup Weapon(Spell was based on Roar so that I don't have to target using my mouse).

2.Script will attempt to locate the nearest item from unit position.

3.a.If script detects an item, picks up the detected item and adds it to inventory slot 1(upper left slot).

3.b. If script does not find any item near the unit, prints a message saying "No weapons were found."


But I just can't find a way to make my unit pick up an item...

Help ASAP this is the final thing I need for my map.
01-10-2008, 12:51 AM#2
TaintedReality
Collapse JASS:
native          UnitAddItem             takes unit whichUnit, item whichItem returns boolean

Can't find it in GUI for some reason, seems very odd that it wouldn't be in there. If you don't know JASS, do this: make two variables, a unit variable called TempUnit and an item variable called TempItem. TempUnit will hold the unit picking up the item, TempItem will hold the item to be picked up.

Trigger:
Actions
Set TempUnit = (Casting Unit or whatever)
Set tempUnit = (Item being picked up)
Custom script: call UnitAddItem(udg_TempUnit,udg_TempItem)
01-10-2008, 01:21 AM#3
xombie
Quote:
Originally Posted by TaintedReality
Can't find it in GUI for some reason

Thats because you wasn't lookin in the right place :P

Trigger:
Untitled Trigger 001
Events
Conditions
Collapse Actions
Hero - Give (Last created item) to (Triggering unit)

Strange though how they have it in the 'Hero' subsection, considering regular units can have items too.
01-10-2008, 01:36 AM#4
TaintedReality
Ahh. I looked under Item and Unit, but didn't think of Hero.
01-10-2008, 02:21 AM#5
Elhyse
But how will I make my hero detect that there is a nearby item so that when I press my Pick Up Weapon spell, the hero will find the nearest item and then work your script.
01-10-2008, 02:33 AM#6
xombie
Trigger:
Untitled Trigger 001
Events
Conditions
Collapse Actions
Collapse Item - Pick every item in (Playable map area) and do (Actions)
Loop - Actions

Try to loop through every item and get the X/Y coordinates of it, then compare the distances to the casting unit. The item with the lowest distance will be your closest. Mind you, you're going to have to create a region around the casting unit, which isn't very difficult, but remember to remove the region afterwards.
01-10-2008, 02:36 AM#7
Elhyse
Please do mister xombie. Thank you and i'm very sorry for the trouble. Noob trigger guy here. ^^
01-10-2008, 02:38 AM#8
xombie
Sorry, I edited my post after learning that there was already a function for it :P

*edit*

Here, this is a snippet of what the code should kind of look like:
Trigger:
Untitled Trigger 001
Events
Conditions
Collapse Actions
Set TempPoint = (Position of (Triggering unit))
Set TempRegion = (Region centered at TempPoint with size (500.00, 500.00))
Collapse Item - Pick every item in TempRegion and do (Actions)
Loop - Actions
Custom script: call RemoveRect(udg_TempRegion)

The Custom script part is for removing the region (actually a rect) so that it doesn't leak. Hope this helps.
01-10-2008, 03:17 AM#9
Elhyse
Mister Xombie!

Your script worked like a charm!

Yay I can pick up items whenever I press G!

Thank you so much!!
01-10-2008, 03:18 AM#10
xombie
Glad to be of service.

Oh and its just xombie, no mister.