HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Item Drop Event

07-12-2005, 04:03 PM#1
Zoxc
How to deteced if a unit drops a item, not removing them?

When using the item drop event, it fires when I use Item - Remove Item
07-12-2005, 04:39 PM#2
TheGreatCheese
You could try putting in a condition that checks to see if the unit still has the item.
07-12-2005, 04:39 PM#3
weaaddar
Check if the items hp is above 0.
07-13-2005, 07:41 AM#4
Zoxc
I got another problem. I can create items in this trigger?

I'm trying to replace the item with a 'No equiped item' item. So its not left empty.

Another problem is that this trigger lauches before the drop, then I got no clue where the unit wants to drop the item.
07-13-2005, 03:23 PM#5
weaaddar
I'd suggest looking at DT4a for solutions around it.

Essientially the drop event fires as soon as the unit is in range to drop an item but not when he physically drops the item. So the item is still in his inventory when this trigger runs. Also do not try ordering the unit to drop the item as it will cause warcraft III to crash instantly without any error message. (This is really awesome when you don't know this because you'll just keep trying it over and over again... :/ ).

My general solution is a timer of zero. Essientially I call a function that launches a timer of zero and creates the item for the hero. A timer of zero is slower than instantaneously, but faster then the fastest wait, and is not detectable by human beings.


something like...
(you need a global gamecache var called obj)

Code:
function objects takes nothing returns gamecache
	if(udg_obj==null)then
		set udg_obj=InitGameCache("obj.w3v")
	endif
	return udg_obj
endfunction

function T_getHero takes timer t returns unit
	return GetStoredInteger(objects(),I2S(H2I(t)),"m_hero")
	return null
endfunction

function T_getItem takes timer t returns item
	return GetStoredInteger(objects(),I2S(H2I(t)),"m_item")
	return null
endfunction

function T_getItem2 takes timer t returns item
	return GetStoredInteger(objects(),I2S(H2I(t)),"m_item2")
	return null
endfunction

function reAdd_child takes nothing returns nothing
	local timer t=GetExpiredTimer()
	local unit hero=T_getHero(t)
	local item bag=T_getItem(t)
	call UnitAddItem(hero,bag)
	call FlushStoredMission(objects(),I2S(H2I(t)))
	call DestroyTimer(t)
	set t=null
	set hero=null
	set bag=null
endfunction

function reAddItem takes unit hero,item it returns nothing
	local timer t=CreateTimer()
	local gamecache gc=objects()
	call StoreInteger(objects(),I2S(H2I(t)),"m_hero",H2I(hero))
	call StoreInteger(objects(),I2S(H2I(t)),"m_item",H2I(it))
	call TimerStart(t,0,false,function reAdd_child)
	set t=null
	set gc=null
endfunction

Which is a function that will add an item after a timer of zero to a hero. (Stolen from BagAttrSSA)
07-13-2005, 10:38 PM#6
Zoxc
Thx, I did take a look at DT4a first, but I didn't want to read your messy trigger :P ( or I where to lazy :-/ )
07-13-2005, 10:50 PM#7
weaaddar
DT4a isn't messy. DT4a is generally the cleanest code you'll find for esoteric and wacky item related nonsense. Just because I don't comment regularly doesn't mean the codes bad.