1. Join Texturing Contest #30 now in a legendary battle of mythological creatures!
    Dismiss Notice
  2. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  3. Melee Mapping Contest #3 - Results are out! Congratulate the winners and check plenty of new 4v4 melee maps designed for this competition!
    Dismiss Notice
  4. The winners of our cinematic soundtrack competition have been decided! Step by the Music Contest #11 - Results to check the entries and congratulate the winners!
    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 at 2:26 PM.

  1. Lord_Marrowgrath

    Lord_Marrowgrath

    Joined:
    Aug 23, 2011
    Messages:
    527
    Resources:
    8
    Maps:
    4
    Template:
    4
    Resources:
    8
    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 at 2:38 PM
  2. Ziadoma

    Ziadoma

    Joined:
    Jan 24, 2017
    Messages:
    27
    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:
    888
    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:
    27
    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:
    527
    Resources:
    8
    Maps:
    4
    Template:
    4
    Resources:
    8
    Anyway I fixed system (Just created another way to do it) Thank you guys for helping