• 🏆 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!

[JASS] InvSystem v0.95

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
An inventory system I made for my map and it's also my first thing JASS, so I hope it's ok.

Features:
- Supports 12 players with one hero per player.
- Supports 5 bags with maximum of 6 item slots for each.
- Saves the Itemtype, Charges and Customvalue of an item.
- The position of item in the inventory is retained though saving/loading.
- Each bag can be disabled and enabled for any player with 1 function call.
- Menu is automatically closed if the Hero is attacked.
- All items from a specific bag can be dropped with a push of a button.
- ( Can be tested with 1 or 2 player(s). )

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
## Not working on this atm. Possible updates in the future. This is done for now ##
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
(Coming soon:)
- Replaceable bags with diffirent amount of item slots.
- Equipment Menu
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
The DropBag ability can be simply removed from the dummy unit in object editor.
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

How to use:
Press Open Item Management.
* A multiboard pops up showing the contents of each bag *
Select the what you want to do from the menu.
* Cannot drop items while Item Management is open *
Exit the Item Management by Pressing Cancel or selecting any other unit.

Help:
You can enable and disable bag by typing 'EnableBagX' or 'DisableBagX'
X means the BagId, which range from 1 to 4. 'All' applies to all bags.

Thanks to:
NFWar - BagOut and DropBag icons.
||Goro|| - Bag item model.
Blizzard Entertaiment - Other bag icons.

Please, give credit if you use or modify this, thank you!
Also report any ideas and most importantly bugs.


Bug reported by Etzer = Fixed!
Updated Screenshot (slightly out of date)
Updated Description
Added Drop All Items button
The system 'remembers' the inventory slots where the items are
Removed BJ's (Also those that krisserz reported)
Supports 12 players



Globals
JASS:
function Globals takes nothing returns nothing
    local integer loop1 = 0
//    local location nLoc = //Location( X, Y ) //GetUnitLoc( Unit )

    // Multiboard Hashtable
    set udg_MultiboardData = InitHashtable()

    // Bag Hashtable
    set udg_BagData = InitHashtable()

    // Item Management Dummies
    loop
        exitwhen ( loop1 > 11 )
        set udg_ItemManagementDummy[ loop1 ] = CreateUnit( Player( loop1 ), 'h000', 0, 0, 270 )    
        set loop1 = loop1 + 1
    endloop

    // Heroes
    set udg_Hero[0] = gg_unit_Ofar_0000

    // Bag Names OLD
    set udg_BagName[0] = "Backpack"
    set udg_BagName[1] = "Sack"
    set udg_BagName[2] = "Pack"
    set udg_BagName[3] = "Satchel"
    set udg_BagName[4] = "Belt Pouch"

    // Bag Names NEW
//    set udg_BagName[0] = "Backpack"
//    set udg_BagName[1] = "Large Bag"
//    set udg_BagName[2] = "Small Backpack"
//    set udg_BagName[3] = "Sack"
//    set udg_BagName[4] = "Tool Box"
//    set udg_BagName[5] = "Satchel"
//    set udg_BagName[6] = "Belt Pouch"

    // Bag Icons OLD
    set udg_BagIcon[0] = "ReplaceableTextures\\CommandButtons\\BTNBackpack.blp"       //Slots 6
    set udg_BagIcon[1] = "ReplaceableTextures\\CommandButtons\\BTNSack.blp"           //Slots 6
    set udg_BagIcon[2] = "ReplaceableTextures\\CommandButtons\\BTNSmallBackpack.blp"  //Slots 6
    set udg_BagIcon[3] = "ReplaceableTextures\\CommandButtons\\BTNSatchel.blp"        //Slots 6
    set udg_BagIcon[4] = "ReplaceableTextures\\CommandButtons\\BTNBeltPouch.blp"      //Slots 6


    // Bag Icons NEW
//    set udg_BagIcon[0] = "ReplaceableTextures\\CommandButtons\\BTNBackpack.blp"     //Slots 6
//    set udg_BagIcon[1] = "ReplaceableTextures\\CommandButtons\\BTNLargeBag.blp"     //Slots 6
//    set udg_BagIcon[2] = "ReplaceableTextures\\CommandButtons\\BTNSmallBackpack.blp"//Slots 5
//    set udg_BagIcon[3] = "ReplaceableTextures\\CommandButtons\\BTNSack.blp"         //Slots 4
//    set udg_BagIcon[4] = "ReplaceableTextures\\CommandButtons\\BTNToolBox.blp"      //Slots 4
//    set udg_BagIcon[5] = "ReplaceableTextures\\CommandButtons\\BTNSatchel.blp"      //Slots 2
//    set udg_BagIcon[6] = "ReplaceableTextures\\CommandButtons\\BTNBeltPouch.blp"    //Slots 2

    // Equipment Names NEW
//    set udg_BagName[0] = "Main Hand"
//    set udg_BagName[1] = "Off Hand"
//    set udg_BagName[2] = "Ranged"
//    set udg_BagName[3] = "Ammo"

//    set udg_EquipmentName[4] = "Head"
//    set udg_EquipmentName[5] = "Shoulder"
//    set udg_EquipmentName[6] = "Chest"
//    set udg_EquipmentName[7] = "Wrists"
//    set udg_EquipmentName[8] = "Hand"
//    set udg_EquipmentName[9] = "Waist"
//    set udg_EquipmentName[10] = "Leg"
//    set udg_EquipmentName[11] = "Feet"

//    set udg_EquipmentName[12] = "Neck"
//    set udg_EquipmentName[13] = "Finger"
//    set udg_EquipmentName[14] = "Trinket"

//    set udg_EquipmentName[15] = "Belt"

    // Equipment Icons NEW
//    set udg_EquipmentIcon[0] = "ReplaceableTextures\\CommandButtons\\BTNBackpack.blp"
//    set udg_EquipmentIcon[1] = "ReplaceableTextures\\CommandButtons\\BTNLargeBag.blp"
//    set udg_EquipmentIcon[2] = "ReplaceableTextures\\CommandButtons\\BTNSmallBackpack.blp"
//    set udg_EquipmentIcon[3] = "ReplaceableTextures\\CommandButtons\\BTNSack.blp"

//    set udg_EquipmentIcon[4] = "ReplaceableTextures\\CommandButtons\\BTNToolBox.blp"
//    set udg_EquipmentIcon[5] = "ReplaceableTextures\\CommandButtons\\BTNSatchel.blp"
//    set udg_EquipmentIcon[6] = "ReplaceableTextures\\CommandButtons\\BTNBeltPouch.blp"
//    set udg_EquipmentIcon[7] = "ReplaceableTextures\\CommandButtons\\BTNBackpack.blp"
//    set udg_EquipmentIcon[8] = "ReplaceableTextures\\CommandButtons\\BTNLargeBag.blp"
//    set udg_EquipmentIcon[9] = "ReplaceableTextures\\CommandButtons\\BTNSmallBackpack.blp"
//    set udg_EquipmentIcon[10] = "ReplaceableTextures\\CommandButtons\\BTNSack.blp"

//    set udg_EquipmentIcon[11] = "ReplaceableTextures\\CommandButtons\\BTNToolBox.blp"
//    set udg_EquipmentIcon[12] = "ReplaceableTextures\\CommandButtons\\BTNSatchel.blp"
//    set udg_EquipmentIcon[13] = "ReplaceableTextures\\CommandButtons\\BTNBeltPouch.blp"

//    set udg_EquipmentIcon[14] = "ReplaceableTextures\\CommandButtons\\BTNBeltPouch.blp"

//    call RemoveLocation( nLoc )
endfunction

//===========================================================================
function InitTrig_Globals takes nothing returns nothing
    local trigger trg_Globals = CreateTrigger(  )
    call TriggerRegisterTimerEvent( trg_Globals, 0.00, false )
    call TriggerAddAction( trg_Globals, function Globals )
endfunction

Inventory Functions
JASS:
function DropBag takes integer PlayerId returns nothing
    //Coming Soon
endfunction

function EnableBag takes integer PlayerId, integer BagId, boolean DisableBag returns nothing
    local unit nUnit

    if ( BagId >= 1 and BagId <= 4 ) then
        call RemoveUnit( LoadUnitHandle( udg_BagData, BagId*18, PlayerId ) )
        if ( not DisableBag ) then
            if ( LoadUnitHandle( udg_BagData, BagId*18, PlayerId ) == null ) then
                if ( BagId == 1 ) then
                    set nUnit = CreateUnit( Player( PlayerId ), 'h001', 0, 0, 270 )
                elseif ( BagId == 2 ) then
                    set nUnit = CreateUnit( Player( PlayerId ), 'h002', 0, 0, 270 )
                elseif ( BagId == 3 ) then
                    set nUnit = CreateUnit( Player( PlayerId ), 'h003', 0, 0, 270 )
                elseif ( BagId == 4 ) then
                    set nUnit = CreateUnit( Player( PlayerId ), 'h004', 0, 0, 270 )
                endif
                call SaveUnitHandle( udg_BagData, BagId*18, PlayerId, nUnit )
            endif
        else
            call SaveUnitHandle( udg_BagData, BagId*18, PlayerId, null )
        endif
    endif
    set nUnit = null
    call RemoveUnit( nUnit )    
endfunction

function UpdateBagBoard takes integer PlayerId returns nothing
    local multiboard nBoard = LoadMultiboardHandle( udg_MultiboardData, 1, PlayerId )
    local multiboarditem nBoardItem
    local string Value
    local string Value2
    local integer Row
    local integer Column = 1
    local integer Bag = 0
    
    loop
        exitwhen ( Bag > 4 )
        set Row = 2
        loop
            exitwhen ( Row > 7 )              //Bag*18+InvSlot*3+ValueType+(Bag+1)
                set Value = I2S( LoadInteger( udg_BagData, Bag*18+(Row-2)*3+1+(Bag+1), PlayerId ) )
                set Value2 = " x "
                if ( S2I( Value ) == 0 ) then
                    set Value = " |cff444444" + Value + "|r"
                    set Value2 = "|cff444444" + Value2 + "|r"
                else//if ( StringLength(Value) == 1 ) then
                    set Value = " |cffCCCCCC" + Value + "|r"
                    set Value2 = "|cffCCCCCC" + Value2 + "|r"
                endif
                set nBoardItem = MultiboardGetItem( nBoard, Row-1, Column-1 )
                call MultiboardSetItemValue( nBoardItem, Value )
                call MultiboardReleaseItem( nBoardItem )
                set nBoardItem = MultiboardGetItem( nBoard, Row-1, Column )
                call MultiboardSetItemValue( nBoardItem, Value2 )
                call MultiboardReleaseItem( nBoardItem )
            set Row = Row + 1
        endloop
        set Column = Column + 2

        set nBoardItem = MultiboardGetItem( nBoard, 0, Column-1 )
        if ( udg_ActiveBag[PlayerId] == Bag ) then
            call MultiboardSetItemValue( nBoardItem, " |cffFFCC00" + udg_BagName[Bag] + "|r" )
        elseif ( LoadUnitHandle( udg_BagData, Bag*18, PlayerId ) == null and Bag != 0) then
            call MultiboardSetItemValue( nBoardItem, " |cff444444" + udg_BagName[Bag] + "|r" )
        else
            call MultiboardSetItemValue( nBoardItem, " |cffCCCCCC" + udg_BagName[Bag] + "|r" )
        endif
        call MultiboardReleaseItem( nBoardItem )

        set Row = 2
        loop
            exitwhen ( Row > 7 )                            //Bag*18+InvSlot*3+ValueType
                set Value = ItemType2ItemName( LoadInteger( udg_BagData, Bag*18+(Row-2)*3+0+Bag+1, PlayerId ) )
                set nBoardItem = MultiboardGetItem( nBoard, Row-1, Column-1 )
                call MultiboardSetItemValue( nBoardItem, Value )
                call MultiboardReleaseItem( nBoardItem )
            set Row = Row + 1
        endloop
        set Column = Column + 1
        set Bag = Bag + 1
    endloop
    set nBoard = null
    call DestroyMultiboard( nBoard )
endfunction

function RemoveSlotSkips takes unit nUnit returns nothing
    local integer loop1 = 0
    local item nItem
    
    loop
        exitwhen (loop1 > 5)
        set nItem = UnitItemInSlot( nUnit, loop1 )
        if ( GetItemTypeId( nItem ) == 'I000' ) then
            call RemoveItem( nItem )
        endif
        set loop1 = loop1 + 1
    endloop
endfunction

function ItemRemoveAll takes unit nUnit returns boolean
    local integer loop1 = 0
    local item nItem
    local boolean empty = true
    
    loop
        exitwhen (loop1 > 5)
        set nItem = UnitItemInSlot( nUnit, loop1 )
        if ( nItem != null ) then
            set empty = false
            call RemoveItem( nItem )
        endif
        set loop1 = loop1 + 1
    endloop
    return empty
endfunction

function ItemDropAll takes unit nUnit returns boolean
    local integer loop1 = 0
    local item nItem
    local boolean empty = true
    
    loop
        exitwhen (loop1 > 5)
        set nItem = UnitItemInSlot( nUnit, loop1 )
        if ( nItem != null ) then
            set empty = false
            call UnitRemoveItem( nUnit, nItem )
            set nItem = null
        endif
        call RemoveItem( nItem )
        set loop1 = loop1 + 1
    endloop
    return empty
endfunction

function SaveBag takes integer PlayerId, integer BagId returns nothing
    local integer loop1 = 0
    local item nItem

    loop
        exitwhen ( loop1 > 5 )
        set nItem = UnitItemInSlot( udg_Hero[PlayerId], loop1 )
        call SaveInteger( udg_BagData, BagId*18+loop1*3+0+BagId+1, PlayerId, GetItemTypeId( nItem ) )
        call SaveInteger( udg_BagData, BagId*18+loop1*3+1+BagId+1, PlayerId, GetItemCharges( nItem ) )
        call SaveInteger( udg_BagData, BagId*18+loop1*3+2+BagId+1, PlayerId, GetItemUserData( nItem ) )
        set nItem = null
        call RemoveItem( nItem )
        set loop1 = loop1 + 1
    endloop
endfunction

function LoadBag takes unit nUnit, integer BagId returns nothing
    local integer PlayerId = GetPlayerId( GetOwningPlayer( nUnit ) )
    local integer loop1 = 0
    local integer nItemType
    local item nItem

    call ItemRemoveAll( nUnit )
    loop
        exitwhen (loop1 > 5)
        set nItemType = LoadInteger( udg_BagData, BagId*18+loop1*3+0+BagId+1, PlayerId )
        if ( nItemType == 0 ) then
            set nItem = CreateItem( 'I000', 0, 0 )
        else
            set nItem = CreateItem( nItemType, 0, 0 )
        endif
        call SetItemCharges( nItem, LoadInteger( udg_BagData, BagId*18+loop1*3+1+BagId+1, PlayerId ) )
        call SetItemUserData( nItem, LoadInteger( udg_BagData, BagId*18+loop1*3+2+BagId+1, PlayerId ) )
        call UnitAddItem( nUnit, nItem )
        set nItem = null
        call RemoveItem( nItem )
        set loop1 = loop1 + 1
    endloop
    call RemoveSlotSkips( nUnit )
endfunction

function ConvertBagId takes integer BagId returns integer
    if ( BagId == 'A000' ) then //Backpack
        return 0
    elseif ( BagId == 'A002' ) then //Sack
        return 1
    elseif ( BagId == 'A003' ) then //Pack
        return 2
    elseif ( BagId == 'A005' ) then //Satchel
        return 3
    elseif ( BagId == 'A004' ) then //Belt Pouch
        return 4
    endif
    return -1
endfunction

function OpenItemManagement takes integer PlayerId returns nothing
    set udg_SelectionChanged[PlayerId] = true
    //call UnitRemoveAbility( udg_ItemManagementDummy[PlayerId], 'Aloc' )
    call SaveBag( PlayerId, udg_ActiveBag[PlayerId] )
    call LoadBag( udg_ItemManagementDummy[PlayerId], udg_ActiveBag[PlayerId] )
    call UpdateBagBoard( PlayerId )
    if (GetLocalPlayer() == Player(PlayerId) ) then
        call ClearSelection()
        call SelectUnit( udg_ItemManagementDummy[PlayerId], true )
    endif
    call PauseUnit( udg_Hero[PlayerId], true )
    call SetUnitPosition( udg_ItemManagementDummy[PlayerId], GetUnitX( udg_Hero[PlayerId] ), GetUnitY( udg_Hero[PlayerId] ) )
endfunction

function CloseItemManagement takes integer PlayerId, boolean CloseUsingCancelButton returns nothing
    set udg_SelectionChanged[PlayerId] = false
    call PauseUnit( udg_Hero[PlayerId], false )
    call IssueImmediateOrder( udg_Hero[PlayerId], "stop" )
    if ( CloseUsingCancelButton ) then
        if (GetLocalPlayer() == Player(PlayerId) ) then
            call ClearSelection()
            call SelectUnit( udg_Hero[PlayerId], true )
        endif
    else
        if (GetLocalPlayer() == Player( PlayerId ) ) then
            call SelectUnit( udg_ItemManagementDummy[PlayerId], false )
        endif
    endif
    //call UnitAddAbility( udg_ItemManagementDummy[PlayerId], 'Aloc' )
endfunction

//===========================================================================
function InitTrig_InventoryFunctions takes nothing returns nothing
endfunction

MenuEvents
JASS:
function MenuEvents takes nothing returns nothing
    local integer CastId = GetSpellAbilityId()
    local integer PlayerId = GetPlayerId( GetOwningPlayer( GetTriggerUnit() ) )
    local player nPlayer = Player( PlayerId )

    if ( CastId == 'A006' ) then //Open Item Management
        call OpenItemManagement( PlayerId )
        call ShowMultiBoard( 1, PlayerId )
    elseif ( CastId == 'A007' ) then //Cancel
        call CloseItemManagement( PlayerId, true )
        call ShowMultiBoard( 0, PlayerId )
    elseif ( CastId == 'A00A' ) then //Drop All Items
        if ( ItemDropAll( udg_Hero[ PlayerId ] ) ) then
            call DisplayTimedTextToPlayer( nPlayer, 0, 0, 1.00, "|cffFFCC00" + "Selected bag is already empty." + "|r" )
            call PlaySoundEffect( PlayerId, gg_snd_Error )
        else
            call DisplayTimedTextToPlayer( nPlayer, 0, 0, 1.00, "Dropped all items from " + "|cffFFCC00" + udg_BagName[ udg_ActiveBag[PlayerId] ] + "|r" )
            call PlaySoundEffect( PlayerId, gg_snd_ChangeBag )
            call SaveBag( PlayerId, udg_ActiveBag[PlayerId] )
            call LoadBag( udg_ItemManagementDummy[PlayerId], udg_ActiveBag[PlayerId] )
            call UpdateBagBoard( PlayerId )
        endif
    else
        set CastId = ConvertBagId( CastId )
        if ( CastId == -1 ) then
            return
        elseif ( udg_ActiveBag[ PlayerId ] != CastId ) then
            set udg_ActiveBag[ PlayerId ] = CastId
            call DisplayTimedTextToPlayer( nPlayer, 0, 0, 1.00, "Opened " + "|cffFFCC00" + udg_BagName[ CastId ] + "|r" )
            call PlaySoundEffect( PlayerId, gg_snd_ChangeBag )
            call LoadBag( udg_Hero[ PlayerId ], CastId )
            call SaveBag( PlayerId, udg_ActiveBag[ PlayerId ] )
            call LoadBag( udg_ItemManagementDummy[ PlayerId ], udg_ActiveBag[ PlayerId ] )
            call UpdateBagBoard( PlayerId )
        else
            call DisplayTimedTextToPlayer( nPlayer, 0, 0, 1.00, "|cffFFCC00" + "Selected bag is already open." + "|r" )
            call PlaySoundEffect( PlayerId, gg_snd_Error )
        endif
    endif
    set nPlayer = null
    call RemovePlayer( nPlayer, PLAYER_GAME_RESULT_NEUTRAL )
endfunction

//===========================================================================
function InitTrig_MenuEvents takes nothing returns nothing
    local trigger trg_MenuEvents = CreateTrigger(  )
    local integer loop1 = 0
    
    loop
        exitwhen ( loop1 > 11 )
        call TriggerRegisterPlayerUnitEvent( trg_MenuEvents, Player(loop1), EVENT_PLAYER_UNIT_SPELL_CAST, null )
        set loop1 = loop1 + 1
    endloop
    call TriggerAddAction( trg_MenuEvents, function MenuEvents )
endfunction

LimitSelection
JASS:
function LimitSelection takes nothing returns nothing
    local integer PlayerId = GetPlayerId( GetTriggerPlayer() )

    if ( udg_SelectionChanged[ PlayerId ] == true ) then
        if ( GetTriggerUnit() != udg_ItemManagementDummy[ PlayerId ] ) then
            call CloseItemManagement( PlayerId, false )
            call ShowMultiBoard( 0, PlayerId )
        endif
    endif
endfunction

//===========================================================================
function InitTrig_LimitSelection takes nothing returns nothing
    local trigger trg_LimitSelection = CreateTrigger(  )
    local integer loop1 = 0
    
    loop
        exitwhen ( loop1 > 11 )
        call TriggerRegisterPlayerUnitEvent( trg_LimitSelection, Player(loop1), EVENT_PLAYER_UNIT_SELECTED, null )
        set loop1 = loop1 + 1
    endloop
    call TriggerAddAction( trg_LimitSelection, function LimitSelection )
endfunction

DeselectOnAttack
JASS:
function DeselectOnAttack takes nothing returns nothing
    local integer PlayerId = GetPlayerId( GetOwningPlayer( GetTriggerUnit() ) )

    if ( IsUnitType( GetTriggerUnit(), UNIT_TYPE_HERO ) == true ) then
        if ( udg_SelectionChanged[ PlayerId ] == true ) then
            call CloseItemManagement( PlayerId, true )
            call ShowMultiBoard( 0, PlayerId )
        endif
    endif
endfunction

//===========================================================================
function InitTrig_DeselectOnAttack takes nothing returns nothing
    local trigger trg_DeselectOnAttack = CreateTrigger(  )
    local integer loop1 = 0

    loop
        exitwhen ( loop1 > 11 )
        call TriggerRegisterPlayerUnitEvent( trg_DeselectOnAttack, Player(loop1), EVENT_PLAYER_UNIT_ATTACKED, null )
        set loop1 = loop1 + 1
    endloop
    call TriggerAddAction( trg_DeselectOnAttack, function DeselectOnAttack )
endfunction

InitBagBoard (BJs only used in this initialization)
JASS:
function InitBagBoard takes nothing returns nothing
    local integer Loop1 = 0
    local integer Loop2
    local multiboard nBoard

    loop
        exitwhen ( Loop1 > 11 )

        set nBoard = CreateMultiboard()
        call MultiboardSetColumnCount( nBoard, 15)
        call MultiboardSetRowCount( nBoard, 7)
        call MultiboardSetTitleText( nBoard, "Inventory")
        call MultiboardSetItemStyleBJ( nBoard, 0, 0, true, false )

        set Loop2 = 1
        loop
            exitwhen Loop2 > 15

            if ( ModuloInteger( Loop2, 3) == 0 ) then
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 10.00 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + "Empty" + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 12.00 )
                call MultiboardSetItemStyleBJ( nBoard, Loop2, 1, true, true )
                call MultiboardSetItemIconBJ( nBoard, Loop2, 1, udg_BagIcon[Loop2/3-1] )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, ( udg_BagName[Loop2/3-1] ) )
            elseif ( ModuloInteger( Loop2 + 1, 3) == 0 ) then
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 1.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + " x " + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 0.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, "" )
            else
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 1.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + "00" + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 0.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, "" )
            endif

            set Loop2 = Loop2 + 1
        endloop

        call SaveMultiboardHandle( udg_MultiboardData, 1, Loop1, nBoard )
        call SetPlayerTechResearched( Player(Loop1), 'R004', 1 )
        call TriggerSleepAction(0.00)
        set Loop1 = Loop1 + 1
    endloop
endfunction

//===========================================================================
function InitTrig_InitBagBoard takes nothing returns nothing
    local trigger trg_InitBagBoard = CreateTrigger(  )
    call TriggerRegisterTimerEvent( trg_InitBagBoard, 0.00, false )
    call TriggerAddAction( trg_InitBagBoard, function InitBagBoard )
endfunction


Keywords:
Inventory, Inv, System, Bag, Bags, Backpack, Item.
Contents

InvSystem v0.95 (Map)

Reviews
12th Dec 2015 IcemanBo: Too long time as NeedsFix. Rejected. 13:02, 17th Jun 2010 The_Reborn_Devil: You're removing a null player here in function "MenuEvents": set nPlayer = null call RemovePlayer( nPlayer...

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long time as NeedsFix. Rejected.

13:02, 17th Jun 2010
The_Reborn_Devil:

You're removing a null player here in function "MenuEvents":
JASS:
    set nPlayer = null
    call RemovePlayer( nPlayer, PLAYER_GAME_RESULT_NEUTRAL )
"set nPlayer = null" should come after it, not before.
You're also using a lot of BJ's in function "InitBagBoard".
I see a lot of red here:
JASS:
call MultiboardSetItemStyleBJ( nBoard, 0, 0, true, false )

        set Loop2 = 1
        loop
            exitwhen Loop2 > 15

            if ( ModuloInteger( Loop2, 3) == 0 ) then
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 10.00 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + "Empty" + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 12.00 )
                call MultiboardSetItemStyleBJ( nBoard, Loop2, 1, true, true )
                call MultiboardSetItemIconBJ( nBoard, Loop2, 1, udg_BagIcon[Loop2/3-1] )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, ( udg_BagName[Loop2/3-1] ) )
            elseif ( ModuloInteger( Loop2 + 1, 3) == 0 ) then
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 1.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + " x " + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 0.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, "" )
            else
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 0, 1.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 0, "|cff444444" + "00" + "|r" )
                call MultiboardSetItemWidthBJ( nBoard, Loop2, 1, 0.50 )
                call MultiboardSetItemValueBJ( nBoard, Loop2, 1, "" )
            endif


Status: Rejected until updated
Rating: N/A

PM me or another mod once you've updated this to get it reviewed again. Have a nice day!
 
Level 13
Joined
Feb 18, 2009
Messages
1,381
I will test this now.

As it seems, there is a few bugs :
When opening backpack the LAST ITEM in your backpack disapears.
You can't get the other sacks, packs and all that stuff.

Please fix that!

Else, it works fine

Screenshot shows last item bug
 

Attachments

  • lawl.JPG
    lawl.JPG
    120.4 KB · Views: 284
Level 9
Joined
Jun 7, 2007
Messages
195
I will test this now.

As it seems, there is a few bugs :
When opening backpack the LAST ITEM in your backpack disapears.
You can't get the other sacks, packs and all that stuff.

Please fix that!

Else, it works fine

Screenshot shows last item bug

Umm... I forgot to put it right away and you tested before my update. You can enable other bags by using the command EnableBag'number' (1-4)

I will try to fix the bug. If anyone can find the problem before I update please post a reply about it here or send PM.
 
Last edited:
Level 13
Joined
Feb 18, 2009
Messages
1,381
DUDE!
You forgot to write "Mon!" in your signature!

Anyways, i'll test it again

EDIT :
Tested.
You can only enable bag 1 (sack) anyways, when you open it THE FIRST TIME, you see the thing that disapeared from the last spot. Then it moves to the next bag (i guess)

A little more fixing and i will vote for 5/5 and approval. for now it is 4/5, and no approval or rejection.
+rep
 
Level 18
Joined
Feb 28, 2009
Messages
1,970
Just some of them:
JASS:
SetPlayerTechResearchedSwap
LoadMultiboardHandleBJ
SubStringBJ
Use instead of them:
JASS:
SetPlayerTechResearched (player whichPlayer, integer techid, integer setToLevel)
LoadMultiboardHandle (hashtable table, integer parentKey, integer childKey)
SubString (string source, integer start, integer end)

Ofc there are more of them.
Are you using JNGP?
 
Level 18
Joined
Feb 28, 2009
Messages
1,970
Sorry but my post was to Furiontti. Let`s not go off-topic.

@Furiontti
As it was already mentioned there are already a lot of inv systems. This one is original in some way but not the best one. Also the code is crying for improvements.
 
Level 9
Joined
Jun 7, 2007
Messages
195
Just some of them:
JASS:
SetPlayerTechResearchedSwap
LoadMultiboardHandleBJ
SubStringBJ
Use instead of them:
JASS:
SetPlayerTechResearched (player whichPlayer, integer techid, integer setToLevel)
LoadMultiboardHandle (hashtable table, integer parentKey, integer childKey)
SubString (string source, integer start, integer end)

Ofc there are more of them.
Are you using JNGP?

No I'm using the standard World Editor and JassCraft.

I'll will try to replace the BJs with natives soon.

bj's o.o???
Thats not what i said.

BJ functions are the same functions that can be seen in the GUI.
Most BJs simply call the native so by using a BJ I might actually be doing this:
JASS:
call somefuncBJ( 0 )

function somefuncBJ takes integer PlayerId returns nothing
    call somefunc( PlayerId )
endfunction

function somefunc takes integer PlayerId returns nothing
    call DoSomethingCool( PlayerId )
endfunction

Instead I could skip the BJ and use the native function instead. Why should I? One function call less
saves all people using this system '1/10000000000000' second and if a lot of them are replaced it might contribute to reduced lag.

Sorry but my post was to Furiontti. Let`s not go off-topic.

@Furiontti
As it was already mentioned there are already a lot of inv systems. This one is original in some way but not the best one. Also the code is crying for improvements.

As I said in the description this IS my first thing in JASS so it might not be the most optimized but I'll try to improve it. I would appriciate it if you could give me some hints.

I might expand this system later on so that it also goes as an equipment and crafting system.
 
Basically, the spells/systems here should be most efficient here so removing the bj's is advised if you expect for it to be approved. =)

Change:
JASS:
function InitTrig_LimitSelection takes nothing returns nothing
    local integer loop1 = 0    
    set gg_trg_LimitSelection = CreateTrigger(  )
    loop
        exitwhen ( loop1 >= 9 )
        call TriggerRegisterPlayerSelectionEventBJ( gg_trg_LimitSelection, Player(0), true )
        set loop1 = loop1 + 1
    endloop

To:
JASS:
function InitTrig_LimitSelection takes nothing returns nothing
    local integer loop1 = 0    
    set gg_trg_LimitSelection = CreateTrigger(  )
    loop
        exitwhen ( loop1 >= 9 )
        call TriggerRegisterPlayerSelectionEventBJ( gg_trg_LimitSelection, Player(loop1), true )
        set loop1 = loop1 + 1
    endloop

Simple mistake, happens all the time. =D

Anyway, I'll try to review the code tomorrow and hopefully help in removing the BJ's.

This system is fine in normal JASS for the purposes it serves, especially since most people would use a system in vanilla JASS than in vJASS. (by vanilla I mean original JASS or JASS2 or whatever the term people use for non-vJASS)

Basically, I think you might want to extend this to all 12 players in the meantime for the best functionality.
 
Level 13
Joined
Feb 18, 2009
Messages
1,381
There are some bugs i can't make work.

First of all "EnableBag1" or 2, 3, 4 dosen't work (screeny)
The bags you can pick up dosen't work.
 

Attachments

  • lawl.JPG
    lawl.JPG
    123.4 KB · Views: 122
Level 9
Joined
Jun 7, 2007
Messages
195
There are some bugs i can't make work.

First of all "EnableBag1" or 2, 3, 4 dosen't work (screeny)
The bags you can pick up dosen't work.

The bags on the ground are not supposed to work yet. They're just there as testing items at the moment. If you read the description it says that such functionality is Coming Soon.

Enabling and disabling all bags at once aswell as disabling bags one at a time works so I wonder what went wrong.
However that thing is simply for testing purposes and you can get access to the bags with EnableBagAll, but I'll fix that anyways.
 
Level 7
Joined
May 21, 2009
Messages
289
I had a few questions. . .
-> Do I need an extensive knowelege of JASS to use your inventory system?
> Can this work for multiple heroes, everythough it says for one, if all the heroes are going to share an inventory but not the armor? It sounds confusing but I need a system that lets me use multiple heroes for one player.
 
Top