• 🏆 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!

[JASS] Item drop issue

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
The below function runs when an item is dropped, I'm trying to check if the last dropped item is inside the rect "Grave_Site"

'1' message runs but not the 2nd message. I'm droping an item right inside the rect though, is this not how you detect a dropped item using 'GetLastRemovedItem()' ?

Thanks.

JASS:
function onDrop takes nothing returns nothing

local item lastItem = GetLastRemovedItem()

  call DisplayTextToForce(GetPlayersAll(),"1")
   if (RectContainsItem(lastItem, gg_rct_Grave_Site) == true ) then
   call DisplayTextToForce(GetPlayersAll(),"2")
  endif


endfunction
 

function InitTrig_unitDropsItem takes nothing returns nothing
   
    set gg_trg_unitDropsItem = CreateTrigger()
     call TriggerRegisterAnyUnitEventBJ( gg_trg_unitDropsItem, EVENT_PLAYER_UNIT_DROP_ITEM )
      call TriggerAddAction(gg_trg_unitDropsItem ,  function onDrop  )
endfunction
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
is this not how you detect a dropped item using 'GetLastRemovedItem()' ?
No, it's not. That BJ returns bj_lastRemovedItem which is only set by this function:
JASS:
function UnitRemoveItemSwapped takes item whichItem, unit whichHero returns nothing
    set bj_lastRemovedItem = whichItem
    call UnitRemoveItem(whichHero, whichItem)
endfunction
so if you're not using that function it won't be the right item. You're not using that function, it's in response to the drop event which does not set that variable. What you want to use is GetManipulatedItem().
 
Level 12
Joined
Dec 2, 2016
Messages
733
No, it's not. That BJ returns bj_lastRemovedItem which is only set by this function:
JASS:
function UnitRemoveItemSwapped takes item whichItem, unit whichHero returns nothing
    set bj_lastRemovedItem = whichItem
    call UnitRemoveItem(whichHero, whichItem)
endfunction
so if you're not using that function it won't be the right item. You're not using that function, it's in response to the drop event which does not set that variable. What you want to use is GetManipulatedItem().



I'm trying to detect if an item is dropped inside a rect, but even though the item is dropped inside it doesn't seem to fire off the rest of the function.
This part never fires, or something is wrong. Any ideas what I'm doing wrong? Thanks.
JASS:
   if (RectContainsItem(lastItem, gg_rct_Grave_Site) == true ) then


JASS:
function onDrop takes nothing returns nothing

local integer ID_GRAVE = 'I017'
local integer ID_MASSIVE_GRAVE = 'I00O'
local integer ID_UNHOLY_GRAVE = 'I028'
local integer ID_DUMMY = 'h01V'


local item lastItem = GetManipulatedItem()
local unit u = GetTriggerUnit()
local unit dummy

   if (RectContainsItem(lastItem, gg_rct_Grave_Site) == true ) then
   if (GetItemTypeId(lastItem) == (ID_GRAVE)) then
   call CreateNUnitsAtLoc(GetItemCharges(lastItem) , (ID_DUMMY), GetOwningPlayer(u), GetRectCenter(gg_rct_Grave_Spit), bj_UNIT_FACING)
     call IssueBuildOrderByIdLocBJ( GetLastCreatedUnit(), 'u005', GetRandomLocInRect(gg_rct_Grave_Spit) )
   endif
  endif
endfunction
   

function InitTrig_unitDropsItem takes nothing returns nothing
   
    set gg_trg_unitDropsItem = CreateTrigger()
     call TriggerRegisterAnyUnitEventBJ( gg_trg_unitDropsItem, EVENT_PLAYER_UNIT_DROP_ITEM )
      call TriggerAddAction(gg_trg_unitDropsItem ,  function onDrop  )
endfunction
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
As I see it all is right and it should work. Perhaps you've set the rawcode of the ID_GRAVE variable wrong and it's failing the next if block. Other than that my best guess is that rect isn't the rect you think it is or it isn't in the place you think it is or you're not actually dropping the item in the rect.

You can use BJDebugMsg() in conjunction with I2S() and GetHandleId() to see some information about the variables being used by the function when it runs. I would suggest that.

Also you're leaking two locations: center of the rect and the random point in the rect.
 
Level 13
Joined
May 10, 2009
Messages
868
If I recall correctly, that event fires before the actual item drop. So, you are probably getting different coordinates from GetItemX/Y functions. Check it out by adding a simple TriggerSleepAction function before getting the item position.
 
Status
Not open for further replies.
Top