System Extended Inventory System

Tom Jones

N/A
Reaction score
437
Extended Inventory System v1.5c​

Purpose:
Easy extension of unit inventories to create bags, backpacks, etc.

Screen shots:
screeniee.jpg


Requirements:
Latest NewGen editor.

Code:
  • vJass.
  • MUI.
  • Should be leakless.
JASS:
library ExtendedInventorySystem 
//#######################################################################################
//#Extended Inventory System v1.5c - By Tom Jones.
//#######################################################################################
//#Requirements:
//#1) NewGen Editor with JassHelper v0.9.G.1
//#
//#Implementation:
//#1) Copy/paste this trigger from this map to your map.
//#
//#Usage:
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call ExtendUnitInventory(unit,size) returns boolean
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   This will extends a unit's inventory with the size given. Returns true if
//#   succesful, false if the unit already has extended inventory. Size should be
//#   divisable by six.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryDisable(unit,boolean)
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryDisabled(unit) returns boolean
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryAutomove(unit,boolean) 
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   This will enable automoving of items from the main inventory to the extended
//#   inventory.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryAutomoves(unit) returns boolean
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryAddItem(unit,item,integer) returns item 
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Sends an item to or removes an item from the extended inventory. Integer determines 
//#   which page the item should be added to. Note that adding an item to a hidden page
//#   will remove the given item and the item returned can't be seen by UnitHasItem(...), 
//#   UnitItemInSlot(...), etc.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryGetItemById(unit,integer) returns item
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Returns the first item in the inventory that meets the integer argument.
//#   Note that the integer can be either a slot id ranging from 0 to the size of the 
//#   extended inventory or an item rawcode.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryHasItemById(unit,integer) returns boolean
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Integer argument can be both a slot id ranging from 0 to the size of the extended
//#   inventory or an item rawcode.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryHasItem(unit,item) returns boolean
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryDisplayPage(unit,integer)
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Displays the page equal to the integer argument. Each page has six slots and 
//#   their id range from 1 to size of the extended inventory. Page ids not in this range
//#   will display the main inventory, page id 1 displays the main inventory.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call InventoryGetPage(unit) returns integer
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Returns the id of the currently displayed page.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call SetMaxStackById(integer id,integer value) 
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Requires Extended Inventory Item Stack module.
//#
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   call SetMaxStackById(integer,integer) 
//#   ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
//#   Requires Extended Inventory Item Stack module.
//#
//#Notes:
//#1) This system wont require you to predefine any items. It does however rely on 
//#   bug, and should thus be used with care. 
//#2) The bug: UnitAddItemToSlotById(...) is able to take a negative value as argument.
//#   The interesting part is that items added this way wont appear on the hero, however
//#   their effects will. Also note that not all negative values can be used. Values -1
//#   to -12 will cause a memeory reference error on exit. Values below -21 will cause a
//#   critical error.
//#3) Please report any bugs or errors by PM&#039;ing me on <a href="http://www.TheHelper.net" target="_blank" class="link link--external" rel="nofollow ugc noopener">www.TheHelper.net</a> or posting them
//#   in this thread:
//#
//#Changelog:
//#   v1.00a - Initial draft.
//#   v1.2b  - Release.
//#   v1.5a  - Changes to the source code.
//#            Added Extended Inventory Stack v1.1
//#            Added Extended Inventory IconTag v1.1
//#            Changed Example B.
//#   v1.5c  - Changed InventoryAddItem(unit,item,boolean) to InventoryAddItem(unit,item,integer)
//#            Changes to the source code to accomodate the above change.
//#            Added Extended Inventory Item Stack v.1.2
//#
//#######################################################################################

//#######################################################################################
//#Extended Inventory System API.
//#######################################################################################
private keyword inventory

function UnitExtendInventory takes unit u, integer size returns boolean
    if u:inventory &gt; 0 then
        return false
    endif
    call inventory.extend(u,size)
    return true
endfunction

function InventoryDisable takes unit u, boolean flag returns nothing
    call u:inventory.disable(flag)
endfunction

function InventoryDisabled takes unit u returns boolean
    return u:inventory.disabled
endfunction

function InventoryAutomove takes unit u, boolean flag returns nothing
    set u:inventory.automove = flag
endfunction

function InventoryAutomoves takes unit u returns boolean
    return u:inventory.automove
endfunction

function InventoryAddItem takes unit u, item whichitem, integer page returns item
    return u:inventory.additem(whichitem,page)
endfunction

function InventoryGetItemById takes unit u, integer id returns item 
    return u:inventory.getitem(id)
endfunction

function InventoryHasItemById takes unit u, integer id returns boolean
    local inventory this = u:inventory
    local integer i = 0
    
    loop
        exitwhen this.getitem(id) != null or i == this.size
        set i = i+1
    endloop
    return i &lt; this.size
endfunction

function InventoryHasItem takes unit u, item whichitem returns boolean
    local inventory this = u:inventory
    local integer i = 0
    
    loop
        exitwhen this.getitem(i) == whichitem or i == this.size
        set i = i+1
    endloop
    return i &lt; this.size
endfunction

function InventoryDisplayPage takes unit u, integer page returns nothing
    call u:inventory.turnpage(page)
endfunction

function InventoryGetPage takes unit u returns integer
    return u:inventory.page
endfunction

function SetMaxStackById takes integer id, integer max returns nothing
    call inventory.setstack(id,max)
endfunction

function GetMaxStackById takes integer id returns integer
    return inventory.getstack(id)
endfunction

//#######################################################################################
//#Hashing.
//#######################################################################################
globals
    private constant integer DEDUCT = 0x100000
    private constant integer HASH = 8192
endglobals

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

//#######################################################################################
//#Slot type.
//#######################################################################################
public struct slot 
    static slot last = 0
    slot next
    inventory current
    item thisitem
    integer itemid
    integer charges
    integer page
    integer id
    boolean free

    method operator item= takes item whichitem returns nothing
        if whichitem != null and .last == this then
            set .last = 0
            set .thisitem = whichitem
        elseif whichitem == null and .last != this then
            set .thisitem = null
            set .itemid = 0
            set .charges = 0
            set .free = true
        elseif whichitem != null then
            set .itemid = GetItemTypeId(whichitem)
            set .charges = GetItemCharges(whichitem)
            set .last = this
            call RemoveItem(whichitem)
            if .current.page == .page   then
                call UnitAddItemToSlotById(.current.u,.itemid,.id-(6*(.page-1)))
            else
                call UnitAddItemToSlotById(.current.u,.itemid,-13)
            endif
            call SetItemCharges(.thisitem,.charges)
        endif
        set .free = .item == null
    endmethod
    method operator item takes nothing returns item
        return .thisitem
    endmethod
    
    method update takes nothing returns nothing
        set .thisitem = UnitItemInSlot(.current.u,.id-(6*(.page-1)))
        set .itemid = GetItemTypeId(.thisitem)
        set .free = .thisitem == null
    endmethod
endstruct

//#######################################################################################
//#Inventory type.
//######################################################################################
private struct modules
    method itemstack takes item whichitem returns integer
        return 0
    endmethod
    static method setstack takes integer id, integer max returns nothing
    endmethod
    static method getstack takes integer id returns integer
        return 0
    endmethod
    
    method icontag takes item whichitem, integer id returns nothing
    endmethod
endstruct

private struct inventory 
    private static integer index
    private static integer array value
    private trigger trig
    integer pages
    slot first
    slot last
    unit u
    player p
    integer page
    boolean automove 
    boolean disabled
    integer size
    delegate modules addons

    implement optional ItemStack
    implement optional IconTag
        
    static method operator []= takes unit u, inventory value returns nothing
        set .index = H2I(u)-DEDUCT
        set .value[.index-(.index/HASH)*HASH] = value
    endmethod
    static method operator [] takes unit u returns inventory
        set .index = H2I(u)-DEDUCT
        return .value[.index-(.index/HASH)*HASH]
    endmethod
    
    static method Delegator takes nothing returns boolean 
        local inventory this = GetTriggerUnit():inventory
        
        if .disabled then
        elseif GetTriggerEventId() == EVENT_UNIT_PICKUP_ITEM then 
            return ExecuteFunc(inventory.onAquire.name)
        elseif GetTriggerEventId() == EVENT_UNIT_DROP_ITEM then 
            return ExecuteFunc(inventory.onDrop.name)
        endif
        return false
    endmethod
    
    private method updatepage takes integer page returns nothing
        local slot s = .first
        
        loop
            exitwhen s == 0
            if s.id &gt;= 6*(page-1) and s.id &lt; 6*page then
                call s.update()
            endif
            set s = s.next
        endloop
    endmethod
    
    method additem takes item whichitem, integer page returns item
        local slot s
        local integer pages = .pages
        local integer id
        
        if whichitem == null or .disabled then
            if .disabled then
                debug call BJDebugMsg(&quot;Extended Inventory Error: Disabled.&quot;)
            else
                debug call BJDebugMsg(&quot;Extended Inventory Error: Passing null as argument.&quot;)
            endif
            return null
        endif
        call .updatepage(.page)
        set s = .itemstack(whichitem)
        if s &gt; 0 then
            return s.item
        else
            set s = .first
        endif
        loop
            if (s.id &gt;= 6*(page-1) and s.id &lt; 6*page) then
                if s.free or s.item == whichitem then
                    exitwhen true
                endif
            endif
            if s.id+1 &gt;= 6*page then
                set page = page+1
                set pages = pages-1
            endif
            if page &gt; .pages  then
                set page = pages
                set s = .first
            else
                set s = s.next
            endif
            if s == 0 or pages == 0 then
                return null
            endif
        endloop
        if s.page != .page then
            call .icontag(whichitem,1)
        endif
        set s.item = whichitem
        return s.item
    endmethod
    
    method getitem takes integer id returns item
        local slot s = .first
        
        if id &lt; .size then
            loop
                exitwhen s.id == id or s == 0
                set s = s.next
            endloop
        elseif id &gt;= &#039;0000&#039; then
            loop
                exitwhen s.itemid == id
                set s = s.next
            endloop
        else
            return null
        endif
        return s.item
    endmethod
    
    method turnpage takes integer page returns nothing
        local integer oldpage = .page
        local slot a = .first
        local slot b = .first
    
        if page == oldpage then
            return
        elseif page &gt; .pages or page == 0 then
            set page = 1
        endif
        set .page = page
        loop
            exitwhen a.page == oldpage or a == 0
            set a = a.next
        endloop
        loop
            exitwhen b.page == page or b == 0
            set b = b.next
        endloop
        call .updatepage(oldpage)
        call .icontag(null,0)
        loop
            exitwhen a.id == oldpage*6 or b.id == page*6
            if a.item != null then
                set a.item = a.item
            endif
            if b.item != null then
                set b.item = b.item
            endif
            set a = a.next
            set b = b.next
        endloop
    endmethod
    
    method disable takes boolean flag returns nothing
        local slot s
        local real x
        local real y
        
        if flag then
            set s = .first
            set x = GetUnitX(.u)
            set y = GetUnitY(.u)
            loop
                exitwhen s == 0
                if s.page &gt; 1 then
                    call CreateItem(s.itemid,x,y)
                    call RemoveItem(s.item)
                endif
                set s = s.next
            endloop
            call DisableTrigger(.trig)
        else
            call EnableTrigger(.trig)
            set .page = 1
            call .updatepage(1)
        endif
        set .disabled = flag
    endmethod
    
    static method extend takes unit u, integer size returns nothing
        local inventory this = inventory.allocate()
        local integer i = 0
        local slot s
        
        set .u = u
        set .u:inventory = this
        set .p = GetOwningPlayer(.u)
        set .size = size+6
        set .pages = .size/6
        set .page = 1
        loop
            exitwhen i == .size
            set s = slot.create()
            set s.current = this
            if .last == 0 then
                set .first = s
            else
                set .last.next = s
            endif
            set s.page = 1+(i/6)
            set s.id = i
            set s.free = s.item == null
            set .last = s
            set i = i+1
        endloop
        set .trig = CreateTrigger()
        call TriggerRegisterUnitEvent(.trig,.u,EVENT_UNIT_PICKUP_ITEM)
        call TriggerRegisterUnitEvent(.trig,.u,EVENT_UNIT_DROP_ITEM)
        call TriggerAddCondition(.trig,Condition(function inventory.Delegator))
        set .disabled = false
        set .automove = false
        set .addons = modules.create()
        call .updatepage(1)
    endmethod
    
    static method onAquire takes nothing returns nothing
        local inventory this = GetTriggerUnit():inventory
        local item whichitem = GetManipulatedItem()
        
        if slot.last &gt; 0 then   
            set slot.last.item = whichitem
        else
            if .automove then
                call .additem(whichitem,.page+1)
            else
                call .additem(whichitem,.page)
            endif
        endif
        set whichitem = null
    endmethod
        
    static method onDrop takes nothing returns nothing
        local inventory this = GetTriggerUnit():inventory
        local item whichitem = GetManipulatedItem()
        local slot s = .first

        loop
            exitwhen s.item == whichitem or s == 0
            set s = s.next
        endloop
        set s.item = null
        set whichitem = null
    endmethod
endstruct
endlibrary


Extended Inventory Stack Item module:
JASS:
library ExtendInventoryItemStack 
//#######################################################################################
//#Extended Inventory Item Stack module v1.1 - By Tom Jones.
//#######################################################################################
//#Requirements:
//#1) NewGen Editor with JassHelper v0.9.G.1
//#2) Extended Inventory System v1.5a
//#
//#Implementation:
//#1) Copy/paste this trigger from this map to your map.
//#2) Modify the options section below. 
//#
//#Changelog:
//#   v1.00a - Initial draft.
//#   v1.1   - Release.
//#   v1.2   - Changed SetItemIdMaxCharges(...) to SetMaxStackById(...)
//#            Changed GetItemIdMaxCharges(...) to GetMaxStackById(...)
//#            Implemented wrappers in the main system.
//#
//#######################################################################################

//#######################################################################################
//#Options.
//#######################################################################################
globals
    private constant integer MAX_STACK       = 10        //If max charges for an item id hasn&#039;t been specified, this will be used.
endglobals

//#######################################################################################
//#Hashing.
//#######################################################################################
globals
    private constant integer DEDUCT = &#039;0000&#039;
    private constant integer HASH = 8192
endglobals

private struct stack
    private static integer index
    private static integer array value
    static method operator []= takes integer id, integer value returns nothing
        set .index = id-DEDUCT
        set .value[.index-(.index/HASH)*HASH] = value
    endmethod
    static method operator [] takes integer id returns integer
        set .index = id-DEDUCT
        return .value[.index-(.index/HASH)*HASH]
    endmethod
endstruct
    
//#######################################################################################
//#Stackitem Module.
//#######################################################################################
module ItemStack 
    method itemstack takes item whichitem returns integer
        local ExtendedInventorySystem_slot s = 0
        local integer id  

        if GetItemType(whichitem) == ITEM_TYPE_CHARGED then
            set id = GetItemTypeId(whichitem)
            set s = .first
            loop
                exitwhen (s.item != whichitem and s.itemid == id and ((s.charges &lt; MAX_STACK and s.itemid:stack == 0) or s.charges &lt; s.itemid:stack)) or s == 0
                if s.item == whichitem and s.charges == 0 then  
                    set s.charges = GetItemCharges(s.item)
                endif
                set s = s.next
            endloop
            if s &gt; 0 then
                set s.charges = s.charges+GetItemCharges(whichitem)
                call RemoveItem(whichitem)
                call SetItemCharges(s.item,s.charges)
            endif
        endif
        return s
    endmethod
    
    static method setstack takes integer id, integer max returns nothing
        set id:stack = max
    endmethod
    static method getstack takes integer id returns integer
        return id:stack
    endmethod
endmodule
endlibrary



Extended Inventory IconTag module:
JASS:
library ExtendedInventoryIconTag initializer Ini
//#######################################################################################
//#Extended Inventory IconTag module v1.1 - By Tom Jones.
//#######################################################################################
//#Requirements:
//#1) NewGen Editor with JassHelper v0.9.G.1
//#2) Extended Inventory System v1.5a
//#3) These object data:
//#       a) Extended Inventory (Turn Page Dummy)
//#       b) Extended Inventory (Move Item Dummy)
//#
//#Implementation:
//#1) Copy/paste this trigger from this map to your map.
//#2) Copy/paste the above required object data from this map to your map. Alternatively
//#   you could create new ones or use existing ones.
//#3) Modify the options section below. Values that expect rawdata must match the rawdata
//#   from your map. To see your map&#039;s raw data, go to the object editor and press ctrl+d.
//#
//#Changelog:
//#   v1.00a - Initial draft.
//#   v1.1   - Release.
//#
//#######################################################################################

//#######################################################################################
//#Options.
//#######################################################################################
globals
    private constant integer    SIZE            = 12         //Text size.
    private constant real       ASCENT_RATE     = 40.        //Acent rate
    private constant real       FADE_TIME       = 1.25       
    private constant integer    TURN_PAGE       = 0
    private constant integer    MOVE_ITEM       = 1
    private constant boolean    DISPLAY_TO_ALL  = false       
    private keyword ICON_TAG
endglobals

private function Init takes nothing returns nothing
    set ICON_TAG[TURN_PAGE].DUMMY               = &#039;u001&#039;  
    set ICON_TAG[TURN_PAGE].TEXT                = &quot;Page&quot;   
    set ICON_TAG[TURN_PAGE].COLOR               = &quot;ff7a96df&quot; //Raw data for the Turn Page Dummy.
    set ICON_TAG[TURN_PAGE].V_ALIGNMENT         = -30.       //Depending on the model you use, you may need align the model with the text.
    set ICON_TAG[TURN_PAGE].H_ALIGNMENT         = -20.

    set ICON_TAG[MOVE_ITEM].DUMMY               = &#039;u000&#039;
    set ICON_TAG[MOVE_ITEM].TEXT                = &quot; moved.&quot;
    set ICON_TAG[MOVE_ITEM].COLOR               = &quot;ff7a96df&quot;
    set ICON_TAG[MOVE_ITEM].V_ALIGNMENT         = -10.
    set ICON_TAG[MOVE_ITEM].H_ALIGNMENT         = -20.
endfunction

//#######################################################################################
//#Icontag module
//#######################################################################################
globals
    private constant real INTERVAL = 0.05
endglobals

private struct ICON_TAG extends array
    integer DUMMY
    real V_ALIGNMENT
    real H_ALIGNMENT
    string TEXT
    string COLOR
endstruct

private struct dummy
    static timer t = CreateTimer()
    static integer array attachment
    static integer index = 0
    texttag tt
    integer id 
    unit u
    real z
    real x
    real y
    integer alpha
    
    static method onTick takes nothing returns nothing
        local integer index = .index
        local player p
        local dummy this
        local real x
        local real y
        local real r
        
        loop
            set this = .attachment[index]
            exitwhen this == 0
            set p = GetOwningPlayer(.u)
            if GetLocalPlayer() == p then
                set x = GetCameraTargetPositionX()
            endif
            set .z = .z+ASCENT_RATE*INTERVAL
            set .alpha = .alpha-R2I(1.25*(255/FADE_TIME)*INTERVAL)
            call SetUnitPosition(.u,.x,.y)
            call SetTextTagPosUnit(.tt,.u,-50+ICON_TAG[.id].V_ALIGNMENT)
            call SetUnitFlyHeight(.u,.z,0)
            call SetUnitVertexColor(.u,255,255,255,.alpha)
            set r = (.x-x)/.x
            if r &lt; 0 then
                set r = -r
            endif
            call SetUnitPosition(.u,.x+ICON_TAG[.id].H_ALIGNMENT+r*Cos(0),.y)
            if .alpha &lt; 0 then  
                call RemoveUnit(.u)
                call .destroy()
                set .attachment[index] = .attachment[.index]
                set .index = .index-1
            endif
            set index = index-1
        endloop
        if .index == 0 then 
            call PauseTimer(.t)
        endif
    endmethod
endstruct

module IconTag
    method icontag takes item whichitem, integer id returns nothing
        local dummy d = dummy.create()
        local string s 
        
        set d.tt = CreateTextTag()
        set d.x = GetUnitX(.u)
        set d.y = GetUnitY(.u)
        set d.u = CreateUnit(.p,ICON_TAG[id].DUMMY,d.x+ICON_TAG[id].H_ALIGNMENT*Cos(0),d.y,-90)
        set s = ICON_TAG[id].TEXT
        if id == MOVE_ITEM then
            set s = &quot;|c&quot;+ICON_TAG[id].COLOR+GetItemName(whichitem)+s+&quot;|r&quot;
        elseif id == TURN_PAGE then
            set s = &quot;|c&quot;+ICON_TAG[id].COLOR+s+&quot; &quot;+I2S(.page)+&quot;|r&quot;
        endif
        call SetTextTagText(d.tt,s,SIZE*0.023/10)
        set d.alpha = 255
        set d.z = 50
        call SetUnitFlyHeight(d.u,d.z,0)
        call SetTextTagPosUnit(d.tt,d.u,-50+ICON_TAG[id].V_ALIGNMENT)
        call SetTextTagPermanent(d.tt,false)
        call SetTextTagLifespan(d.tt,FADE_TIME)
        call SetTextTagFadepoint(d.tt,FADE_TIME/4)
        if DISPLAY_TO_ALL == false then
            if GetLocalPlayer() != .p then
                call SetTextTagVisibility(d.tt,false)
                call ShowUnit(d.u,false)
            endif
        endif
        set d.id = id
        set d.index = d.index+1
        set d.attachment[d.index] = d
        if d.index == 1 then
            call TimerStart(d.t,INTERVAL,true,function dummy.onTick)
        endif
    endmethod
endmodule
endlibrary


Notes:
  • This system does not depend on users predefining items.
  • It does however depend on a bug I discovered, and as such could be dangerous. However I haven't run into any problems so far. For those of you who are interested in the bug, try adding an item to a unit thusly:
    JASS:
    function ...
         call UnitAddItemToSlotById(unit,itemid,-13)
    endfunction

Changelog:
  • v1.00a - Initial draft.
  • v1.2b - Release
  • v1.5a
    • Changes to the source code.
    • Added Extended Inventory Stack v1.1
    • Added Extended Inventory IconTag v1.1
    • Changed Example B.
  • v1.5c
    • Changed InventoryAddItem(unit,item,boolean) to InventoryAddItem(unit,item,integer)
    • Changes to the source code to accomodate the above change.
    • Added Extended Inventory Item Stack v.1.2
      • Changed SetItemIdMaxCharges(...) to SetMaxStackById(...)
      • Changed GetItemIdMaxCharges(...) to GetMaxStackById(...)
      • Implemented wrappers in the main system.

Comments and criticism is welcome :thup:
 

Attachments

  • Extended Inventory System v1.5c.w3x
    42.5 KB · Views: 685

wraithseeker

Tired.
Reaction score
122
It seems good but why don't you detect double clicks so it would be easier for users to move it into the backpack?
 

TERRYperfect

New Member
Reaction score
0
Excellent! THIS IS THE SYSTEM I've been searching for a long time ~~

But I found some bugs:

1. the item [bag] can't be dropped....
2. the item [Next page] can be sold ,but then the effect of the items in the bag will remain...
 

TERRYperfect

New Member
Reaction score
0
And a questions:

this system occupied a auto-casting spell...
In the demo map, this spell is innerfire..
so this system cannot be applied on the unit who has the spell innerfire, can it?

so , can I customize the order string?
 

Switch33

New Member
Reaction score
12
Hmm, someone should write this code into bonus mod as this gets rid of the need for custom abilities that add to attributes, damage, health, etc!
Only using items with certain amounts rather than a single ability with 30 lvls or 30 small lvl abilities should save a lot of coding time and space. Although bonus mod is still good for certain abilities you want to "cap(put a limit on)" like for instance evasion, crit strike, hardened skin, vampiric aura,even health regeneration(maybe?),and auras in general(since they don't stack with the same buff) etc.

Such a freaking sweet bug... xD

Only suggestion about the inventory system atm might be that you might want to add a check for item classification to show that this bug and system can be used for equipable items.
 

simonake

New Member
Reaction score
72
Have you tried to change the inventory slot numbers to 7 then wait 0.5 seconds and if it's not combined remove it?
I can't tell you if it would work. Never tried.
 

Tom Jones

N/A
Reaction score
437
It seems good but why don't you detect double clicks so it would be easier for users to move it into the backpack?
That'll be up for the user to code.

Excellent! THIS IS THE SYSTEM I've been searching for a long time ~~

But I found some bugs:

1. the item [bag] can't be dropped....
2. the item [Next page] can be sold ,but then the effect of the items in the bag will remain...

this system occupied a auto-casting spell...
In the demo map, this spell is innerfire..
so this system cannot be applied on the unit who has the spell innerfire, can it?

so , can I customize the order string?
The bag sholdn't be dropped. The effects should remain if the unit loses the Next Page item, however it shouldn't be dropped. And lastly, what you think is the system is actually an example on how to use the system.

Hmm, someone should write this code into bonus mod as this gets rid of the need for custom abilities that add to attributes, damage, health, etc!
Only using items with certain amounts rather than a single ability with 30 lvls or 30 small lvl abilities should save a lot of coding time and space. Although bonus mod is still good for certain abilities you want to "cap(put a limit on)" like for instance evasion, crit strike, hardened skin, vampiric aura,even health regeneration(maybe?),and auras in general(since they don't stack with the same buff) etc.

Such a freaking sweet bug... xD

Only suggestion about the inventory system atm might be that you might want to add a check for item classification to show that this bug and system can be used for equipable items.
Could you clarify this, because I really don't understand what you mean.

Have you tried to change the inventory slot numbers to 7 then wait 0.5 seconds and if it's not combined remove it?
I can't tell you if it would work. Never tried.
If your referring to how the bug works, then yes I tried that and it doesn't work.
 

Switch33

New Member
Reaction score
12
See if this clarifies it better?

If you add a check for (the first item matching an item classification) rather than just an item in the inventory.
Then you can recieve an already equiped item matching with it's classification for a simple equip example.
Like weapons are ITEM_TYPE_ARTIFACT, armor is ITEM_TYPE_CAMPAIGN etc etc. . .
(This would mean the first ITEM_TYPE_ARTIFACT you recieve is the weapon equiped in your weapon slot and you can easily prevent further equips till he drops it by doing some simple checks.)

Just a thought, i mean it would be great for a new simple Example C (equipable item types)
 

Tom Jones

N/A
Reaction score
437
Version 1.5a is out.
  • v1.5a
    • Changes to the source code.
    • Added Extended Inventory Stack v1.1
    • Added Extended Inventory IconTag v1.1
    • Changed Example B.

Important to note:
  • Important! This system now requires the newest JassHelper which is not included in the newest NewGen. To update your NewGen's JassHelper, donwload the latest JassHelper here. Then follow these instructions:
    • Extract to a desired location.
    • Browse the extracted folder.
    • Find and browse executable folder
    • Copy jasshelper.exe.
    • Browse your NewGen folder.
    • Find and browse the jasshelper folder.
    • Paste the jasshelper.exe here, say yes to overwrite existing files.
 

Tom Jones

N/A
Reaction score
437
I wasn't satisfied with the API, so:

  • v1.5c
    • Changed InventoryAddItem(unit,item,boolean) to InventoryAddItem(unit,item,integer)
    • Changes to the source code to accomodate the above change.
    • Added Extended Inventory Item Stack v.1.2
      • Changed SetItemIdMaxCharges(...) to SetMaxStackById(...)
      • Changed GetItemIdMaxCharges(...) to GetMaxStackById(...)
      • Implemented wrappers in the main system.
This is intended to be the final version, I can't come up with anything else to add to the system and I'm quite satisfied with the API and source as it is now.
 

Romek

Super Moderator
Reaction score
963
I tested it. It's certainly very useful. It's also well coded, as always.

Approved. :)
 

XxShadyxX

I abused the rep system.
Reaction score
81
Help!!! How DO I add this to my map? Keeps saying there is a error? HElp Please!
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top