1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Item drop issue

Discussion in 'Triggers & Scripts' started by Rugarus, Oct 5, 2019.

  1. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    709
    Resources:
    0
    Resources:
    0
    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.

    Code (vJASS):

    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
     
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,901
    Resources:
    1
    Spells:
    1
    Resources:
    1
    No, it's not. That BJ returns bj_lastRemovedItem which is only set by this function:
    Code (vJASS):
    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().
     
  3. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    709
    Resources:
    0
    Resources:
    0


    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.
    Code (vJASS):

       if (RectContainsItem(lastItem, gg_rct_Grave_Site) == true ) then
     



    Code (vJASS):


    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

     
     
  4. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,901
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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.
     
  5. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    742
    Resources:
    2
    Spells:
    2
    Resources:
    2
    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.
     
  6. Rugarus

    Rugarus

    Joined:
    Dec 2, 2016
    Messages:
    709
    Resources:
    0
    Resources:
    0
    Yep that's it. Thanks guys.