• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] How to drop items

Status
Not open for further replies.
I want a trigger so that when a hero picks up an item, say Crown of the Kings while he already has one, then he drops the Crown of the Kings that's picked up, (AKA: He can only have only Crown of the Kingsx1 and if he picks another one while having one in his inventory then the second one will be dropped)

How is it possible to do that?
Giving +4 Reputation and credits to anyone who helps out.
 
Level 9
Joined
Feb 28, 2017
Messages
195
I think this should do it

  • Trigger1
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item carried by (Hero manipulating item) of type Crown of Kings +5)) Equal to Crown of Kings +5
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
        • Else - Actions
      • Do nothing
 
Level 16
Joined
Mar 25, 2016
Messages
1,327
Loop through the inventory for the same item-type and then drop the item that is picked up.
It's important, that the item in the inventory is not the same item as the picked up item.
You could optimize it by storing some values to variables.
  • Drop
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer A)))
              • (Item being manipulated) Not equal to (Item carried by (Triggering unit) in slot (Integer A))
            • Then - Actions
              • Hero - Drop (Item being manipulated) from (Triggering unit)
              • Skip remaining actions
            • Else - Actions
 
I think this should do it

  • Trigger1
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item carried by (Hero manipulating item) of type Crown of Kings +5)) Equal to Crown of Kings +5
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
        • Else - Actions
      • Do nothing

This trigger drops the item when it's picked up, I want the hero to have only one crown of the kings and drop a second one if it's picked up, your trigger makes me drop the crown of the kings even if I don't already have it in my inventory.
 
Level 9
Joined
Feb 28, 2017
Messages
195
Ok, second attempt

  • Trigger1
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item carried by (Hero manipulating item) of type Crown of Kings +5)) Equal to Crown of Kings +5
          • (Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type Crown of Kings +5)
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
        • Else - Actions
      • Do nothing
 
Ok, second attempt

  • Trigger1
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item carried by (Hero manipulating item) of type Crown of Kings +5)) Equal to Crown of Kings +5
          • (Item being manipulated) Not equal to (Item carried by (Hero manipulating item) of type Crown of Kings +5)
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
        • Else - Actions
      • Do nothing
It worked! +Rep
 
alterntive from me

paste this function to the map header:
JASS:
function UnitCountItemsOfPickedType takes nothing returns integer
    local integer itemId = GetItemTypeId(GetManipulatedItem())
    local integer i=0
    local integer count=0
    loop
        if GetItemTypeId(UnitItemInSlot(GetManipulatingUnit(), i))==itemId then
            set count=count+1
        endif
        set i=i+1
        exitwhen i==bj_MAX_INVENTORY
    endloop
    return count
endfunction

and trigger to use
  • pick crown
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Crown of Kings +5
    • Actions
      • Custom script: if UnitCountItemsOfPickedType() > 1 then
      • Hero - Drop (Item being manipulated) from (Hero manipulating item)
      • Custom script: endif
you can use diffrent allowed number for items, like you can allow to carry 2 items of given type; to do that use if UnitCountItemsOfPickedType() > 2 then
 
Status
Not open for further replies.
Top