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

Prevent Item From Being Dropped

Status
Not open for further replies.
What JASS code is needed to prevent a specific item from being dropped?
JASS:
function Item_Lose takes nothing returns nothing
    local unit Hero=GetTriggerUnit()
    local item Item=GetManipulatedItem()
    if(GetItemTypeId(I)=='item')then
        call Prevent_Item_From_Being_Dropped(Hero,Item)
    endif
    set Hero=null
    set Item=null
endfunction
The above function is [basically] what my event handling for dropping items is. This function is registered as a condition. There is a similar trigger for getting an item and another trigger for using an item. They are called Item_Get and Item_Use respectively. My problem is that I don't know what code to write to implement the function Prevent_Item_From_Being_Dropped. This function has to retain the original item's handle id and other data, as well as remaining in the same slot of Hero. Any ideas?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
It seems like I am saying this at least once a day.

Use 0.0 second TSA or 0.0 second timer or TriggerSyncReady().


  • Untitled Trigger 002
    • Events
      • Unit - A unit Loses an item
    • Conditions
    • Actions
      • ----------- Use one of options here ---------------
      • Hero - Give (Item being manipulated) to (Hero manipulating item)
 
Level 25
Joined
May 11, 2007
Messages
4,651
Is it only for this specific item, or do you want it for several items?
Because if it's just one item, then you can do what DD_Legion suggests, and have another copy of the item that is droppable.

So if your item is "Death Mask"
Then you create two copies, one droppable and one not. Then use triggers to give the heroes that is supposed to be able to drop it the one version, while giving the others the other item.
 
I've fixed my issue. Here is the solution.
JASS:
function PreventDrop_Callback takes nothing returns nothing
    local timer Callback=GetExpiredTimer()
    local integer CallbackId=GetHandleId(Callback)
    local unit Hero=LoadUnitHandle(Hash,CallbackId,0)
    local item Item=LoadItemHandle(Hash,CallbackId,1)
    local integer Slot=LoadInteger(Hash,CallbackId,0)
    call DisableTrigger(Event_ItemLose)
    call DisableTrigger(Event_ItemGet)
    call UnitAddItem(Hero,Item)
    call UnitDropItemSlot(Hero,Item,Slot)
    call EnableTrigger(Event_ItemLose)
    call EnableTrigger(Event_ItemGet)
    call DestroyTimer(Callback)
    set Callback=null
    set Hero=null
    set Item=null
    call FlushChildHashtable(Hash,CallbackId)
endfunction
function PreventDrop takes unit Hero,item Item,integer Slot returns nothing
    local timer Callback=CreateTimer()
    local integer CallbackId=GetHandleId(Callback)
    call SaveUnitHandle(Hash,CallbackId,0,Hero)
    call SaveItemHandle(Hash,CallbackId,1,Item)
    call SaveInteger(Hash,CallbackId,0,Slot)
    call TimerStart(Callback,0,false,function PreventDrop_Callback)
    set Callback=null
endfunction
function ItemLose takes nothing returns nothing
    local unit Hero=GetTriggerUnit()
    local item Item=GetManipulatedItem()
    local item TestItem=null
    local integer Slot=0
    call DisplayTextToPlayer(udg_Local,0,0,GetUnitName(Hero)+" dropped a "+GetItemName(Item)+".")
    if GetItemTypeId(Item)=='I007'then
        loop
            set TestItem=UnitItemInSlot(Hero,Slot)
            if TestItem==Item then
                call PreventDrop(Hero,Item,Slot)
                set Slot=5
            endif
            set TestItem=null
            exitwhen Slot==5
            set Slot=Slot+1
        endloop
    endif
    set Hero=null
    set Item=null
    set TestItem=null
endfunction
 
Status
Not open for further replies.
Top