1. The contestants were to create water structures for the 20th Terraining Contest. Choose one in the public poll!
    Dismiss Notice
  2. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  3. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  4. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[General] Removing selected items on hero inventory slot 6

Discussion in 'World Editor Help Zone' started by Lord_Marrowgrath, Apr 15, 2019.

  1. Lord_Marrowgrath

    Lord_Marrowgrath

    Joined:
    Aug 23, 2011
    Messages:
    602
    Resources:
    9
    Maps:
    5
    Template:
    4
    Resources:
    9
    Hello all. I want to save hero slot 6 for specific items. I did many methods by triggers but my system removes all items on slot 6.

    For example:

    Only Gem items not drops when hero wear on slot 6. Other items drop/remove instantly from slot 6 when wear it.

    +Rep for helping.
     
    Last edited: Apr 15, 2019
  2. Ziadoma

    Ziadoma

    Joined:
    Jan 24, 2017
    Messages:
    28
    Resources:
    0
    Resources:
    0
    Best would be to show your code, so we can tell you whats wrong with it and how to fix it. Otherwise I am sure there should be already a tutorial on this side about that.
     
  3. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    895
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    hey, here you have:
    Code (vJASS):

    globals  
        hashtable           g_ItemHash=InitHashtable()
        trigger                 g_trg_ItemSwitch=CreateTrigger()
    endglobals
    //-----------------------------------------------------------------

    function IsItemAllowedForSlot5 takes item itm returns boolean
        local integer itemId=GetItemTypeId(itm)
        return itemId=='gemt' // or itemId=='frgd' or ...... list here all item that  can be carried in slot5
    endfunction
    //-----------------------------------------------------------------
    //------------ITEM PICK UP-------------------------------------
    //-----------------------------------------------------------------
    function Trig_ItemWeapon_Pickup takes nothing returns nothing
        local unit u=GetManipulatingUnit()
        local item itm=GetManipulatedItem()
        local item itm5=UnitItemInSlot(u, 5)
        if itm==itm5 and (not IsItemAllowedForSlot5(itm5)) then
            call UnitRemoveItem(u, itm)
        elseif IsItemAllowedForSlot5(itm) then //move to slot5
            call UnitDropItemSlot(u, itm, 5)
        endif
        set u=null
        set itm=null
        set itm5=null
    endfunction

    //-----------------------------------------------------------------
    //------------ITEM SWITCHED IN INVENTORY---------------------------
    //-----------------------------------------------------------------
    function Trig_ItemWeaponSwitchInInventory_Cond takes nothing returns boolean
        local integer ord = GetIssuedOrderId()
        return (ord==852002 or ord==852003 or ord==852004 or ord==852005 or ord==852006 or ord==852007)
    endfunction
    //-------------------------------------------------------------
    function Trig_ItemWeaponSwitchInInventory_Child takes nothing returns nothing //runs when any item was moved in inventory
        local timer t = GetExpiredTimer()
        local unit u = LoadUnitHandle(g_ItemHash, GetHandleId(t), 0)//ordered unit
        local item itm5=UnitItemInSlot(u, 5)
        local integer i=0
       
        loop//unit has item5 in diffrent slot?
            exitwhen i>5
            if IsItemAllowedForSlot5(UnitItemInSlot(u, i)) then
                exitwhen true
            endif
            set i=i+1
        endloop
       
        if i<5 then //yes, the item is in wrong slot number "i" 0,1,2,3 or 4
            call DisableTrigger(g_trg_ItemSwitch)
            call IssueTargetOrderById(u, 852007, UnitItemInSlot(u, i)) //reverse player switching
            //call BJDebugMsg("reversed switching")
            call EnableTrigger(g_trg_ItemSwitch)
           
        else //no, unit has not item5-type in inventory
            if itm5!=null and (not IsItemAllowedForSlot5(itm5)) then
                call UnitRemoveItem(u, itm5)
                //call BJDebugMsg("no gem, dropping item from slot 5")
            endif
        endif

        //---
        call FlushChildHashtable(g_ItemHash, GetHandleId(t))
        call DestroyTimer(t)
        set t = null
        set u=null
    endfunction
    //---------------------------------------------------------------------
    function Trig_ItemWeaponSwitchInInventory takes nothing returns nothing
        local timer t=CreateTimer()  
        call SaveUnitHandle(g_ItemHash, GetHandleId(t), 0, GetOrderedUnit())
        call TimerStart(t, 0.00, false, function Trig_ItemWeaponSwitchInInventory_Child)  
        set t=null
    endfunction

    //===========================================================================
    //===========================================================================
    function InitTrig_ItemSlotRestriction takes nothing returns nothing
        local trigger t=CreateTrigger() // item picked up
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
        call TriggerAddAction(t, function Trig_ItemWeapon_Pickup)

        call TriggerRegisterAnyUnitEventBJ(g_trg_ItemSwitch, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
        call TriggerAddCondition(g_trg_ItemSwitch, Condition(function Trig_ItemWeaponSwitchInInventory_Cond))
        call TriggerAddAction(g_trg_ItemSwitch, function Trig_ItemWeaponSwitchInInventory)
    endfunction
     
     
  4. Ziadoma

    Ziadoma

    Joined:
    Jan 24, 2017
    Messages:
    28
    Resources:
    0
    Resources:
    0
    Oh sorry I can't help you with vjass, I only use gui.
     
  5. Lord_Marrowgrath

    Lord_Marrowgrath

    Joined:
    Aug 23, 2011
    Messages:
    602
    Resources:
    9
    Maps:
    5
    Template:
    4
    Resources:
    9
    Anyway I fixed system (Just created another way to do it) Thank you guys for helping