• 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.

[JASS] One item on same type

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
Hi, i was trying something new, simple item system.

JASS:
scope Items
    globals
        private constant string MESSAGE = "You already have item of this type equipped"
        private constant integer WEAPON_SLOT = 2
        private constant itemtype WEAPON_TYPE = ITEM_TYPE_CAMPAIGN
    endglobals
    
    private struct IS
    
        private static method onGet takes nothing returns nothing
            local item i = GetManipulatedItem()
            local unit u = GetTriggerUnit()
            local player o = GetTriggerPlayer()
            local real x = GetUnitX(u)
            local real y = GetUnitY(u)
            
            if GetItemType(i) == WEAPON_TYPE then
            
                //Move item to slot WEAPON_SLOT
            
                if i != UnitItemInSlot(u, WEAPON_SLOT) and GetItemType(i) == GetItemType(UnitItemInSlot(u, WEAPON_SLOT)) then
                    call UnitDropItemPoint(u, i, x, y)
                    call SimError(o, MESSAGE)
                else
                    call BJDebugMsg("weapon")
                endif
            
            endif
            
        endmethod
    
        private static method onInit takes nothing returns nothing
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM, function thistype.onGet)
        endmethod
    
    endstruct
endscope

So what i want to do it:

When unit get item this is moved to specific slot but if unit already has item of this type item is dropped.
In this code items are dropped if unit already has item of same type but error is not displayed and item is not moving to specific slot because i don't rly know how to do this - i was trying UnitDropItemSlot
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
JASS:
scope Items
    globals
        private constant string MESSAGE = "You already have item of this type equipped"
        private constant integer WEAPON_SLOT = 2
        private constant itemtype WEAPON_TYPE = ITEM_TYPE_CAMPAIGN
    endglobals
    
    private struct IS
    
        private static method onGet takes nothing returns nothing
            local item i = GetManipulatedItem()
            local unit u = GetTriggerUnit()
            local player o = GetTriggerPlayer()
            local real x = GetUnitX(u)
            local real y = GetUnitY(u)
            local item temp
            
            if GetItemType(i) == WEAPON_TYPE then
                set temp = UnitItemInSlot(u, WEAPON_SLOT)
                
                                   // Slot if full, but item is not of type WEAPON.
                                   // Swap places
                if temp == null or GetItemType(temp) != WEAPON_TYPE then
                    call UnitDropItemSlot(u, i, WEAPON_SLOT)// Orders unit to move i to slot WEAPON_SLOT.
                else
                    call UnitRemoveItem(u, i)// Drops item on the unit coordinates
                    call SimError(o, MESSAGE)
                endif
                set temp = null
            endif
            
        endmethod
    
        private static method onInit takes nothing returns nothing
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM, function thistype.onGet)
        endmethod
    
    endstruct
endscope

UnitDropItemSlot is a unit order which will fire the unit issued target order event.
Hence it may fail for paused units
 
Status
Not open for further replies.
Top