1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[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:
    620
    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:
    899
    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:
    620
    Resources:
    9
    Maps:
    5
    Template:
    4
    Resources:
    9
    Anyway I fixed system (Just created another way to do it) Thank you guys for helping