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

[Solved] Question about drop item?

Status
Not open for further replies.
Level 1
Joined
Oct 25, 2016
Messages
4
please can someone teach me how to make hero drop item if he already has the same item?
 
you use the Event - Unit aquiers Item.
set an counter to =0
You loop through full inventory
if item-Type at current inventory slot = gained item-Type -> counter +1

after loop check if counter is bigger than 1.

If it is
deactivade the current Trigger
and drop the gained item.
then activade the current Trigger again.​

We deactivade the current Trigger to avoid endless recursive loops which crashes the game.
 
Level 13
Joined
Nov 7, 2014
Messages
571
JASS:
library InventoryRules initializer init

globals
    private code on_item_pickup_handler
endglobals

private function init takes nothing returns nothing
    local trigger t

    // setup the event
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)

    // and its handler
    call ExecuteFunc(SCOPE_PRIVATE + "set_on_item_pickup_handler")
    call TriggerAddAction(t, on_item_pickup_handler)

    call ExecuteFunc(SCOPE_PRIVATE + "carry_1_of_items_init")
endfunction

globals
    private integer array carry_1_of_items
    private integer carry_1_of_items_count
endglobals
private function carry_1_of_items_init takes nothing returns nothing
    set carry_1_of_items[1] = 'ratf' // claws of attack +15
    set carry_1_of_items[2] = 'ckng' // crown of kings +5
    set carry_1_of_items[3] = 'modt' // mask of death
    set carry_1_of_items_count = 3
endfunction

private function on_item_pickup takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item picked_it = GetManipulatedItem()
    local integer picked_it_id = GetItemTypeId(picked_it)
    local item curr_it
    local integer curr_it_id
    local integer inv_size = UnitInventorySize(u)
    local integer i
    local integer j
    local real x
    local real y

    set i = 0
    loop
        exitwhen i >= inv_size
        set curr_it = UnitItemInSlot(u, i)

        // skip over empty slots and the item we've just picked
        if curr_it != null and curr_it != picked_it then
            set curr_it_id = GetItemTypeId(curr_it)

            // we drop the item we've just picked if we already have an item of the same type
            if picked_it_id == curr_it_id then

                set j = 1
                loop
                    exitwhen j > carry_1_of_items_count
                    if curr_it_id == carry_1_of_items[j] then
                        exitwhen true
                    endif
                    set j = j + 1
                endloop

                // but only if its in the carry-1-of-items list
                if j <= carry_1_of_items_count then
                    set x = GetItemX(picked_it)
                    set y = GetItemY(picked_it)

                    // call UnitDropItemPoint(u, picked_it, GetUnitX(u), GetUnitY(u))
                    // call SetItemPosition(picked_it, x, y)
                    // call IssueImmediateOrder(u, "stop")

                    // SetItemPosition seems to remove the item from the unit's inventory on its own
                    call SetItemPosition(picked_it, x, y)

                    // TODO: error message, sound?

                    exitwhen true
                endif

            endif

            //
        endif

        set i = i + 1
    endloop

    set u = null
    set picked_it = null
    set curr_it = null
endfunction
private function set_on_item_pickup_handler takes nothing returns nothing
    set on_item_pickup_handler = function on_item_pickup
endfunction

endlibrary

The above vJass script should work, but I don't how to convert it to GUI (if that's what you were expecting).
 
Gui code of my post.
  • Unique Item
    • Ereignisse
      • Unit - A unit Acquires an item
    • Bedingungen
    • Aktionen
      • Set Punkt = (Position of (Item being manipulated))
      • Set Counter = 0
      • For each (Integer A) from 1 to 6, do (Actions)
        • Schleifen - Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) equal (==) Item-type of (Item being manipulated))
            • Then - Actions
              • Set Counter = (Counter + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Counter > 1
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Item - Move (Item being manipulated) to Punkt
          • Trigger - Turn on (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_Punkt)
But I recommand some kind of warning/Info that items are unique.
 
Level 1
Joined
Oct 25, 2016
Messages
4
JASS:
library InventoryRules initializer init

globals
    private code on_item_pickup_handler
endglobals

private function init takes nothing returns nothing
    local trigger t

    // setup the event
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)

    // and its handler
    call ExecuteFunc(SCOPE_PRIVATE + "set_on_item_pickup_handler")
    call TriggerAddAction(t, on_item_pickup_handler)

    call ExecuteFunc(SCOPE_PRIVATE + "carry_1_of_items_init")
endfunction

globals
    private integer array carry_1_of_items
    private integer carry_1_of_items_count
endglobals
private function carry_1_of_items_init takes nothing returns nothing
    set carry_1_of_items[1] = 'ratf' // claws of attack +15
    set carry_1_of_items[2] = 'ckng' // crown of kings +5
    set carry_1_of_items[3] = 'modt' // mask of death
    set carry_1_of_items_count = 3
endfunction

private function on_item_pickup takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local item picked_it = GetManipulatedItem()
    local integer picked_it_id = GetItemTypeId(picked_it)
    local item curr_it
    local integer curr_it_id
    local integer inv_size = UnitInventorySize(u)
    local integer i
    local integer j
    local real x
    local real y

    set i = 0
    loop
        exitwhen i >= inv_size
        set curr_it = UnitItemInSlot(u, i)

        // skip over empty slots and the item we've just picked
        if curr_it != null and curr_it != picked_it then
            set curr_it_id = GetItemTypeId(curr_it)

            // we drop the item we've just picked if we already have an item of the same type
            if picked_it_id == curr_it_id then

                set j = 1
                loop
                    exitwhen j > carry_1_of_items_count
                    if curr_it_id == carry_1_of_items[j] then
                        exitwhen true
                    endif
                    set j = j + 1
                endloop

                // but only if its in the carry-1-of-items list
                if j <= carry_1_of_items_count then
                    set x = GetItemX(picked_it)
                    set y = GetItemY(picked_it)

                    // call UnitDropItemPoint(u, picked_it, GetUnitX(u), GetUnitY(u))
                    // call SetItemPosition(picked_it, x, y)
                    // call IssueImmediateOrder(u, "stop")

                    // SetItemPosition seems to remove the item from the unit's inventory on its own
                    call SetItemPosition(picked_it, x, y)

                    // TODO: error message, sound?

                    exitwhen true
                endif

            endif

            //
        endif

        set i = i + 1
    endloop

    set u = null
    set picked_it = null
    set curr_it = null
endfunction
private function set_on_item_pickup_handler takes nothing returns nothing
    set on_item_pickup_handler = function on_item_pickup
endfunction

endlibrary

The above vJass script should work, but I don't how to convert it to GUI (if that's what you were expecting).

great, can you tell me how to add my item? i need it for 1 item Power of Tread.
i dont know nothing about vjass. thank you

Gui code of my post.
  • Unique Item
    • Ereignisse
      • Unit - A unit Acquires an item
    • Bedingungen
    • Aktionen
      • Set Punkt = (Position of (Item being manipulated))
      • Set Counter = 0
      • For each (Integer A) from 1 to 6, do (Actions)
        • Schleifen - Aktionen
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) equal (==) Item-type of (Item being manipulated))
            • Then - Actions
              • Set Counter = (Counter + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Counter > 1
        • Then - Actions
          • Trigger - Turn off (This trigger)
          • Item - Move (Item being manipulated) to Punkt
          • Trigger - Turn on (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation(udg_Punkt)
But I recommand some kind of warning/Info that items are unique.

oh thank you, under (test)
 
Last edited by a moderator:
Status
Not open for further replies.
Top