• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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