HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

CBS - Complex Bag System

08-08-2008, 07:56 PM#1
Flame_Phoenix
Hi guys, this is CBS. This is a Bag system with user interface designed to be easy to use and import.
CBS stands for Complex Bag System and it's function is to allow players to have a backPack easy to use and change. This bag holds up to 60 items and can be increased you you want or decreased very easily.

CBS has many advantages in comparison with other systems so it is easy for you to use it and manage it:
- It is fully JESP
- It uses no vJASS nor cache and so you can be sure that it will work in your campaign
- It uses only 2 unit models, so you have more memory for other stuff
- It follows (or at least tries to) Object Oriented Programing, everything is divided into functions so you always know which part you want to change
- The code is heavily commented
- Has a capacity to hold 1000 different item types and it can be easily increased (I just think few campaigns will have more than that xD )

For those of you who are curious, here is the code, CBS uses (for now) two main triggers. One that creates the interface, and the other that is responsible for knowing the player's actions such as moving items and quiting the bag.
To work CBS needs a 3rd trigger, called a setup trigger, that the user must change and a map's header with some basic functions I created.
This is my best work so far, I am now searching for a better interface, however I hope you all like what you see and have fun.

However before you guys seeing this, there are some people I need to thank, credits:
- Toadcop -> his system inspired me, and mainly he was of great help. By explaining sections of his code to me and giving me tips, he deserves credit
- Troll-Brain -> his persistance was sure to help me solve bug

Collapse maps header:
constant function maxItemStorage takes nothing returns integer
    return 1000
endfunction

function getItemIcon takes integer iconType returns integer
    local integer i = 0//a counter for our loops
    local integer itemType = iconType   //the array of the icon
    local integer result = 0
    
    loop
        exitwhen(i == maxItemStorage())
        if(udg_ItemArray[i] == itemType)then    
            set result = udg_ItemIconArray[i]
        endif
        set i = i + 1
    endloop
    
    return result
endfunction

function getItemText takes integer iconType returns string
    local integer i = 0//a counter for our loops
    local integer itemType = iconType
    local string result = ""
    
    loop
        exitwhen(i == maxItemStorage())
        if(udg_ItemArray[i] == itemType)then
            set result = udg_ItemTextArray[i]
        endif
        set i = i + 1
    endloop
    
    return result
endfunction

function getItemTextBoolean takes integer itemType returns integer
    local integer i = 0 //counter for loops
    
    loop
        exitwhen(i == maxItemStorage())
        if(udg_ItemArray[i] == itemType) then
            return i
        endif
        set i = i + 1
    endloop
    
    return -1
endfunction

Collapse the Setup Trigger:
function InitTrig_Item_Set_Up takes nothing returns nothing
    local trigger SetUpTrigger = CreateTrigger()
    
    //Here we set the items setup
    
    //The bag Item
    set udg_ItemArray[0] = 'I000'   //rawcode of the item
    set udg_ItemIconArray[0] = 'B00D'   //rawcode of the destructilbe with the Item's icon
    set udg_ItemTextArray[0] = "This is a text message, for you to see the versability of the system:|nFast moving flying machine. Excellent at scouting, and effective against air units. Can learn the Flying Machine Bombs and Flak Cannons upgrades. |nCan see invisible units. |n|n|cffffcc00Attacks air units.|r" //description of the item
    //if "forAll()" is false, than this will decide if your item has an user description or not. 
    //Note that in this case, because "forAll()" is TRUE, than the values on "udg_ItemTextArray[0]" and the values in 
    //"udg_ItemHasText[0]" don't matter and are useless. You can just simply remove them, although if one day later 
    //you decide you want to use the, you will have to set up their values by indexes, just like in the following examples
    //and in that case, you will have a lot of work to do =P
    set udg_ItemHasText[0] = true   
    
    //Alleria's Flute of Accuracy
    set udg_ItemArray[1] = 'afac'   //rawcode of the item
    set udg_ItemIconArray[1] = 'B004'   //rawcode of the destructilbe with the Item's icon
    set udg_ItemTextArray[1] = "Increases nearby ranged units' damage by <AIar,DataA1,%>%. |nDoes not stack with Trueshot Aura." //description of the item
    set udg_ItemHasText[1] = false
    
    //Amulet of Spell Shield
    set udg_ItemArray[2] = 'spsh'   //rawcode of the item
    set udg_ItemIconArray[2] = 'B005'   //rawcode of the destructilbe with the Item's icon
    set udg_ItemTextArray[2] = "Blocks a negative spell that an enemy casts on the Hero once every <ANss,Cool1> seconds." //description of the item
    set udg_ItemHasText[2] = false
    
    //Ancient Janggo of Endurance
    set udg_ItemArray[3] = 'ajen'   
    set udg_ItemIconArray[3] = 'B006'   
    set udg_ItemTextArray[3] = "Grants the Hero and friendly nearby units increased attack rate and movement speed. |nDoes not stack with Endurance Aura." 
    set udg_ItemHasText[3] = false
    
    //Belt of Giant Strength +6
    set udg_ItemArray[4] = 'bgst'   
    set udg_ItemIconArray[4] = 'B007'   
    set udg_ItemTextArray[4] = "Increases the Strength of the Hero by 6 when worn." 
    set udg_ItemHasText[4] = false
    
    //Boots of Quel'Thalas +6
    set udg_ItemArray[5] = 'belv'   
    set udg_ItemIconArray[5] = 'B008'   
    set udg_ItemTextArray[5] = "Increases the Agility of the Hero by 6 when worn." 
    set udg_ItemHasText[5] = false
    
    //Boots of Speed
    set udg_ItemArray[6] = 'bspd'   
    set udg_ItemIconArray[6] = 'B009'   
    set udg_ItemTextArray[6] = "Increases the movement speed of the Hero when worn." 
    set udg_ItemHasText[6] = false
    
    //Circlet of Nobility
    set udg_ItemArray[7] = 'cnob'   
    set udg_ItemIconArray[7] = 'B00A'  
    set udg_ItemTextArray[7] = "Increases the Strength, Agility and Intelligence of the Hero by 2 when worn." 
    set udg_ItemHasText[7] = false
    
    //Claws of Attack +12
    set udg_ItemArray[8] = 'ratc'   
    set udg_ItemIconArray[8] = 'B00B'   
    set udg_ItemTextArray[8] = "Increases the attack damage of the Hero by 12 when worn." 
    set udg_ItemHasText[8] = false
    
    //Claws of Attack +6
    set udg_ItemArray[9] = 'rat6'   
    set udg_ItemIconArray[9] = 'B00C'   
    set udg_ItemTextArray[9] = "Increases the attack damage of the Hero by 6 when worn." 
    set udg_ItemHasText[9] = false
    
    set SetUpTrigger = null
endfunction

//Note in this demo map I only use this items =P

Collapse The create trigger:
//===========================================================================
//=============================SETUP START===================================
//===========================================================================

//=============================RAWCODES===================================
constant function bagID takes nothing returns integer
    return 'I000'   //The rw of the bag item
endfunction

constant function blueBag takes nothing returns integer
    return 'B000'   //the rw of the blue bag desctructble icon
endfunction

constant function grayBag takes nothing returns integer
    return 'B001'   //the rw of the gray bag desctructble icon
endfunction

constant function clickUnit takes nothing returns integer
    return 'h000'   //the rw of the click unit
endfunction

constant function selectorId takes nothing returns integer
    return 'h001'   //the rw of the selector model that appears when you click a unit
endfunction

constant function dummyItemId takes nothing returns integer
    return 'I001'   //the rw of the a dummy item that will be needed by the system
endfunction

//=============================SIZES AND POSITIONS===================================
constant function bagSize takes nothing returns integer
    //The Size of the bag
    //note that the real capacity will be 24 +1 because the arrays start on 0
    //note that to ouccpy 60 slots, here will be 59!
    return 24   
endfunction

constant function boardCapacity takes nothing returns integer
    //Note that it will be 60 slots for the bag items + 6 for hero inventory
    return 66
endfunction

constant function boardBagSlots takes nothing returns integer
    return 60   //These are the slots on the board that we will use for items of the bag
endfunction

constant function bottomLeftX takes nothing returns real
    //the down left corner X value of the board when it is created
    return 0.//-1260.
endfunction

constant function bottomLeftY takes nothing returns real
    //the down left corner Y value of the board when it is created
    return 0.//-1500.
endfunction

constant function textSize takes nothing returns real
    //formula is:
    //Size * 0.023 /10
    //In the case we have Size = 9
    // 9 * 0.023 / 10 = 0.0207
    return 0.0207
endfunction

constant function returnButtonsPos takes nothing returns real
    //this determinates where the first return button will be created
    //this is important because all other 6 buttons will follow this one
    //PS. The "Return to game" button is made of a total of 7 units aligned in a row
    //Here when I say button, I refer to a unit.
    return 215. 
endfunction

constant function textDescriptionX takes nothing returns real
    return 400. //The X poition where the Items description will be created.
endfunction

constant function textDescriptionY takes nothing returns real
    return 250. //The Y poition where the Items description will be created.
endfunction
//=============================PATHS AND TEXTS===================================
constant function backGroundPath takes nothing returns string
    return "war3mapImported\\BMP.blp"  //The path of the screen Image Fade Filter
endfunction

function itemCustomtext takes item anItem returns string
    //This is the custom text displayed if an item doesn't have a custom description 
    //made by the user. In this case we just display it's name
    return "|cff8000FFName: |r" + "|cff0000FF" + GetItemName(anItem) + "|r" 
endfunction

//=============================BOOLEAN FLAGS===================================
constant function forAll takes nothing returns boolean
    //If true it will affect all item's descriptions meaning that all items do NOT have a
    //description made by the user. In this case the "itemCustomtext()" text will be displayed
    //for all items with no exception.
    //If false than it means there can be particular cases.This special cases are decided by 
    //the global variable "udg_ItemHasText" array. In this case if "udg_ItemHasText" is true, 
    //than the item has a custom description by the user; if false, than it means it doesn't, 
    //and the "itemCustomtext()" will be displayed.
    return true
endfunction

//===========================================================================
//==============================SETUP END====================================
//===========================================================================
function setCamera takes nothing returns nothing
    local real minX = bottomLeftX()
    local real maxX = minX 
    local real minY = bottomLeftY()
    local real maxY = minY 
    local real centerX = (minX + maxX) / 2
    local real centerY = (minY + maxY) / 2
    local real duration=0.00
    local camerasetup windowLoc = CreateCameraSetup()
 
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_TARGET_DISTANCE, 600.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_FARZ, 1000.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_ZOFFSET, 0.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_ANGLE_OF_ATTACK, 270.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_FIELD_OF_VIEW, 70.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_ROLL, 0.00, duration)
    call CameraSetupSetField(windowLoc, CAMERA_FIELD_ROTATION, 90.00, duration)
    call CameraSetupSetDestPosition(windowLoc, centerX + 300, centerY + 125, duration)

    call SetCameraBounds(centerX+300, centerY + 125, centerX + 300, centerY + 125, centerX + 300, centerY + 125, centerX + 300, centerY + 125)
    call CameraSetupApplyForceDuration(windowLoc, true, 0.)

    //Create our new filter
    call EnableUserUI(false)
    call SetCineFilterTexture(backGroundPath())
    call SetCineFilterBlendMode(BLEND_MODE_BLEND)
    call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
    call SetCineFilterStartUV(0, 0, 1, 1)
    call SetCineFilterEndUV(0, 0, 1, 1)
    call SetCineFilterStartColor(255, 255, 255, 255)
    call SetCineFilterEndColor(255, 255, 255, 255)
    call DisplayCineFilter(true)
endfunction
//===========================================================================
//although this name is "pauseUnits" this function represents in general what should
//happen to the game whena unit uses the bag. In this case we just hide the caster.
function pauseUnits takes nothing returns nothing
    call IssueImmediateOrder(udg_User, "stop")
    call PauseUnit(udg_User, true)
//    call ShowUnit(udg_User, false)
endfunction
//===========================================================================
function CBS_Condition takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == bagID()
endfunction
//===========================================================================
function Create takes nothing returns nothing
    local real x 
    local real y  
    local integer i
    local integer j
    local real positionX
    local real positionY
    local boolean array isSpotValid[boardCapacity()]
    local player owner
    
    set udg_User = GetTriggerUnit()        
    set owner = GetOwningPlayer(udg_User)
    set x = bottomLeftX()
    set y = bottomLeftY()
     
    call pauseUnits()
     
    //here we set in an array which spots can be used by the player to store items
    //move items and manage them. Valid spots will be the bagSize and the end of the
    //board (60) plus 6 extra spots for the hero's inventory
    //"i" is a counter which will navigate though all spots of the board and will
    //set the spots of the user's inventory to valid
    set i = 0
    loop
        exitwhen(i == boardCapacity())
        if ((i <= bagSize()) or (i >= 60 and i <= 66)) then
            set isSpotValid[i] = true
        else 
            set isSpotValid[i] = false
        endif
        set i = i + 1
    endloop
        
    //this is a debugg loop, to see if the boolean array isSpotValid is correct
//        set i = 0
//        loop
//            exitwhen(i == boardCapacity())
//            if isSpotValid[i] then
//                call BJDebugMsg(I2S(i) + " true")
//            else 
//                call BJDebugMsg(I2S(i) + " false")
//            endif
//            set i = i + 1
//        endloop
        
    //here we create the 3 rows of icons for the bag.
    //"i" represents each slot of a row individualy
    //Create Row 1
    set positionX = x
    set positionY = y + 100
    set i = 0
    loop
        exitwhen(i == 20)  
        if (udg_BagPack[i] == null) then
            if isSpotValid[i] then
                set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            else
                set udg_InterfaceIcons[i] = CreateDestructable(grayBag(), positionX, positionY, 180, 0.3, 1)
            endif
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            //we get the destructible refereing to the icon and create it
            //we create the dummy clickUnit
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
        
    //Create Row 2
    set positionX = x
    set positionY = y + 75
    set i = 20
    loop
        exitwhen(i == 40)
        if (udg_BagPack[i] == null) then
            if isSpotValid[i] then
                set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                    
                set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            else
                set udg_InterfaceIcons[i] = CreateDestructable(grayBag(), positionX, positionY, 180, 0.3, 1)
                    
            endif
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            //we get the destructible refereing to the icon and create it
            //we create the dummy clickUnit
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
        
    //Create Row 3
    set positionX = x
    set positionY = y + 50
    set i = 40
    loop
        exitwhen(i == 60)
        if (udg_BagPack[i] == null) then
            if isSpotValid[i] then
                set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                    
                set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            else
                set udg_InterfaceIcons[i] = CreateDestructable(grayBag(), positionX, positionY, 180, 0.3, 1)
                    
            endif
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                 
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
            //we get the destructible refereing to the icon and create it
            //we create the dummy clickUnit
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
        
    //here we fill our array with the items our caster has
    //here "i" is the itemSlot of the caster being evaluated
    set i = 60  //The spot on the BagPack Item Array. The first 60 spots are for the bag, the last 6 for the user's inventory
    set j = 0   //a counter which will loop trhough all spots of the caster's inventory
    loop
        exitwhen(i == 66) 
        set udg_BagPack[i] = UnitItemInSlot(udg_User, j )
        set i = i + 1
        set j = j + 1
    endloop
        
    //here we create the hero inventory
    //line 1
    //"i" is the spots of the InterfaceIcons global
    //"j" is the slot of the user's Inventory being evaluated currently
    set positionX = x + 550
    set positionY = y + 100
    set i = 60
    loop
        exitwhen(i == 62)
        if (udg_BagPack[i] == null) then
            set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
    
    //here we create the hero inventory
    //line 2
    //"i" is the spots of the InterfaceIcons global
    //"j" is the slot of the user's Inventory being evaluated currently. "j" starts with
    //2 because we already saw the first 2 slots in the loop before this one.
    set positionX = x + 550
    set positionY = y + 75
    set i = 62
    loop
        exitwhen(i == 64)
        if (udg_BagPack[i] == null) then
            set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
        
    //here we create the hero inventory
    //line 3
    //"i" is the spots of the InterfaceIcons global
    //"j" is the slot of the user's Inventory being evaluated currently. Guess why "j"
    //is 4 =P
    set positionX = x + 550
    set positionY = y + 50
    set i = 64
    loop
        exitwhen(i == 66)
        if (udg_BagPack[i] == null) then
            set udg_InterfaceIcons[i] = CreateDestructable(blueBag(), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        else
            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[i])), positionX, positionY, 180, 0.3, 1)
                
            set udg_ClickUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        endif
        set positionX = positionX + 25
        set i = i + 1
    endloop
        
    //now here we create the units that will allow the player to exit the bag Interface
    set positionX = x + returnButtonsPos()
    set positionY = y
    set i = 0
    loop
        exitwhen(i == 7)  
        set udg_ReturnUnits[i] = CreateUnit(owner, clickUnit(), positionX, positionY, 0.)
        set positionX = positionX + 25
        set i = i + 1
    endloop
     
     //here start a timer that will set every second the camera. This is to prevent 
     //mouse scroll from meesing things up
    call TimerStart(udg_CameraTimer, 0.3, true, function setCamera)
    
    set owner = null
endfunction
//===========================================================================
function InitTrig_Create takes nothing returns nothing
    local trigger CreateCBSTrigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(CreateCBSTrigger, EVENT_PLAYER_UNIT_USE_ITEM)
    call TriggerAddCondition(CreateCBSTrigger, Condition(function CBS_Condition))
    call TriggerAddAction(CreateCBSTrigger, function Create)
    set CreateCBSTrigger = null
endfunction

Collapse Item Managing trigger:
function ResetCamera takes nothing returns nothing
    //Now we stop the timer because we no longer need it
    call PauseTimer(udg_CameraTimer)
    
    //set camera to normal
    call ResetToGameCamera(0.0)
   
    //kill the filter
    call DisplayCineFilter(false)
    call EnableUserUI(true)
    
    //reseting camera bounds as in the beggining of the map
    call SetCameraBounds(GetRectMinX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds), GetRectMinX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds))
    
    //now we Pan the camera to the position of the user
    call PanCameraToTimed(GetUnitX(udg_User), GetUnitY(udg_User), 0.0)
endfunction
//===========================================================================
function ClearSelections takes nothing returns nothing
    set udg_ClickedNumber = -1
    set udg_ClickedUnit[0] = null
    call KillUnit(udg_ClickedUnit[1])
    set udg_ClickedUnit[1] = null
endfunction
//===========================================================================
function ClearItemDescriptionArea takes nothing returns nothing
    //we get rid of the texttag!
    call DestroyTextTag(udg_ItemInterfaceText)
    set udg_ItemInterfaceText = null
    
    //Here we kill the amplified description image icon
    call KillDestructable(udg_ImageDescription)
    set udg_ImageDescription = null
endfunction
//===========================================================================
//This function is responsable by the items description
function ItemDescriptionArea takes integer itemPosition returns nothing
    //here we destroy any previous occurences of the amplified Icon Image
    //and Create a new one.
    call KillDestructable(udg_ImageDescription)
    set udg_ImageDescription = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[itemPosition])), bottomLeftX() + 350, bottomLeftY() + 200, 180, 0.5, 1)
    
    //here we destroy any previous occurences of the text tag
    //and Create a new one.
    call DestroyTextTag(udg_ItemInterfaceText)
    set udg_ItemInterfaceText = CreateTextTag()
    
    if (forAll()) then 
        call SetTextTagText(udg_ItemInterfaceText, itemCustomtext(udg_BagPack[itemPosition]), textSize() ) 
    else
        if(udg_ItemHasText[getItemTextBoolean(GetItemTypeId(udg_BagPack[itemPosition]))]) then
            call SetTextTagText(udg_ItemInterfaceText, getItemText(GetItemTypeId(udg_BagPack[itemPosition])), textSize())
        else
            call SetTextTagText(udg_ItemInterfaceText, itemCustomtext(udg_BagPack[itemPosition]), textSize() ) 
        endif
    endif

    call SetTextTagPos(udg_ItemInterfaceText, bottomLeftX() + textDescriptionX(), bottomLeftY() + textDescriptionY(), 0 ) 
    call SetTextTagPermanent(udg_ItemInterfaceText, false)
endfunction
//===========================================================================
//although this name is "unPauseUnits" this function represents in general what should
//happen to the game whena unit finishes using the bag. In this case we just show
//the caster again.
function unPauseUnits takes nothing returns nothing
    call PauseUnit(udg_User, false)
//    call ShowUnit(udg_User, true)
endfunction
//===========================================================================
//This Clears and nulls everything
function Clear takes nothing returns nothing
    local integer j //a counter for our loops
    local item anItem = null
    
    set j = 0
    loop
        exitwhen(j == 66)
        
        //here we kill the units behind the destructibles (the Icons)
        call KillUnit(udg_ClickUnits[j])
        set udg_ClickUnits[j] = null
        
        //here will kill the Icons, we no longer need them
        call KillDestructable(udg_InterfaceIcons[j])
        set udg_InterfaceIcons[j] = null
        
        set j = j + 1
    endloop

    //here we also remove the Return Units, that allow the player to exit
    set j = 0
    loop
        exitwhen(j > 6)
            call KillUnit(udg_ReturnUnits[j])
            set udg_ReturnUnits[j] = null
        set j = j + 1
    endloop
    
    //we reset the clcking variables in order to prevent further bugs when 
    //we use it for the second time
    call ClearSelections()
    
    //here we clear the item description area by nullifying both icon and text
    call ClearItemDescriptionArea()
    
    //here we take away the items from the caster and hide them
    set j = 0
    loop
        exitwhen(j == 6)
        set anItem = UnitItemInSlot(udg_User, j)
        call UnitRemoveItem(udg_User, anItem)
        call SetItemVisible(anItem, false)
        set j = j + 1
    endloop
            
    //now we add the new Items to the caster
    //in every null spot we add a dummy item to take up some space, so the real
    //Items can be in the spot the user choosed for them when in the Interface
    set j = 60
    loop
        exitwhen(j == 66)
        if (udg_BagPack[j] == null) then
            set anItem = CreateItem(dummyItemId(), GetUnitX(udg_User), GetUnitY(udg_User))
            call UnitAddItem(udg_User, anItem)
        endif
        call UnitAddItem(udg_User, udg_BagPack[j])
        set j = j + 1
    endloop
            
    //now we remove the dummyItems because they are no longer required
    set j = 0
    loop
        exitwhen(j == 6)
        if (GetItemTypeId(UnitItemInSlot(udg_User, j)) == dummyItemId()) then
            call RemoveItem(UnitItemInSlot(udg_User, j))
        endif
        set j = j + 1
    endloop
    
    call unPauseUnits()
    call ResetCamera()
    
    //cleaning more mess
    set udg_User = null
endfunction
//===========================================================================
function onSelection takes nothing returns nothing
    local unit selected = GetTriggerUnit() //the selected unit
    local integer selectedId = GetUnitTypeId(selected)
    local integer i //a counter for our loops
    local integer j //a counter for our loops
    local integer k //a counter for our loops
    local item anItem = null
    
    //here we loop trhough all our clcikingUnits, to see which one was selected
    set i = 0
    loop
        exitwhen(i == boardCapacity())
        if (selected == udg_ClickUnits[i]) then
            //here we check if a unit was already cliked
            //if it is the first time we are selecting a unit, then we save it and
            //create an effect on it, as long as the unit being clicked does NOT 
            //represent an empty blue bag. If it is a blue bag, we do nothing.
            if(udg_ClickedUnit[0] == null) then 
                if (udg_BagPack[i] != null) then
                    set udg_ClickedUnit[0] = selected
                    set udg_ClickedUnit[1] = CreateUnit(GetOwningPlayer(udg_User), selectorId(), GetUnitX(selected), GetUnitY(selected), 270)
                    set udg_ClickedNumber = i
                
                    //here we activate the description of the item
                    call ItemDescriptionArea(i)
                endif
            
            //if we already selected a unit
            else 
                //here we check if the Player selected the same unit 2 times
                //if so, we de-select everything
                if ((udg_ClickedUnit[0] == selected)) then
                    call ClearSelections()
                else
                    //if "udg_BagPack[i]" is null, then the player is choosing as second clicking unit
                    //a blue bag
                    if (udg_BagPack[i] == null) then
                        //If our first select unit is the bag, and if "i" < boardBagSize() this means we are placing the bag inside of itself
                        //and we can't allow it
                        if not(GetItemTypeId(udg_BagPack[udg_ClickedNumber]) == bagID() and (i < boardBagSlots())) then 
                            call KillDestructable(udg_InterfaceIcons[i])
                            call KillDestructable(udg_InterfaceIcons[udg_ClickedNumber])
                        
                            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[udg_ClickedNumber])), GetUnitX(udg_ClickUnits[i]), GetUnitY(udg_ClickUnits[i]),180,  0.3, 1) 
                            set udg_InterfaceIcons[udg_ClickedNumber] = CreateDestructable(blueBag(), GetUnitX(udg_ClickUnits[udg_ClickedNumber]), GetUnitY(udg_ClickUnits[udg_ClickedNumber]),180,  0.3, 1)  
                        
                            set udg_BagPack[i] = udg_BagPack[udg_ClickedNumber] //we move the item 
                            set udg_BagPack[udg_ClickedNumber] = null   //we null our first spot
                        
                            //we set everything up as to the beggining
                            call ClearSelections()
                    endif
                    
                    //if our second clicked icon is not null (not a blue bag) than it means
                    //we changing item slots
                    else
                        //If our first select unit is the bag, and if "i" < boardBagSize() this means we are placing the bag inside of itself
                        //and we can't allow it
                        if not(GetItemTypeId(udg_BagPack[udg_ClickedNumber]) == bagID() and (i < boardBagSlots())) then 
                            call KillDestructable(udg_InterfaceIcons[i])
                            call KillDestructable(udg_InterfaceIcons[udg_ClickedNumber])
                        
                            //we save the object of the second slot in a var
                            set anItem = udg_BagPack[i]
                        
                            //we set the icon of the second clciked to the icon of the first cilcked
                            set udg_InterfaceIcons[i] = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[udg_ClickedNumber])), GetUnitX(udg_ClickUnits[i]), GetUnitY(udg_ClickUnits[i]),180,  0.3, 1) 
                        
                            //we set the icon of the first click to the icon of the second
                            set udg_InterfaceIcons[udg_ClickedNumber] = CreateDestructable(getItemIcon(GetItemTypeId(anItem)), GetUnitX(udg_ClickUnits[udg_ClickedNumber]), GetUnitY(udg_ClickUnits[udg_ClickedNumber]),180,  0.3, 1)  
                        
                            //here we change the positions of the items on the BagPAck array
                            set udg_BagPack[i] = udg_BagPack[udg_ClickedNumber] 
                            set udg_BagPack[udg_ClickedNumber] = anItem   
                        
                            //we set everything up as to the beggining, by clearing the selections
                            call ClearSelections()
                        endif
                    endif
                endif
            endif
        endif
        set i = i + 1
    endloop
    
    //debug loop
//    set i = 0
//    loop
//        exitwhen(i == bagSize() + 1)
//        call BJDebugMsg(GetItemName(udg_BagPack[i]))
//        set i = i + 1
//    endloop
//    call BJDebugMsg("_______________")
//    set i = 60
//    loop
//        exitwhen(i == 66)
//        call BJDebugMsg(GetItemName(udg_BagPack[i]))
//        set i = i + 1
//    endloop
//    call BJDebugMsg("--------------")
    
    //here we check if he clicked unit was to one of the units that would allow the player
    //to exit the bag    
    //the udg_isItClear flag prevents the user from calling the Clear() function nultiple times 
    set i = 0
    loop
        exitwhen(i == 7)
        if (selected == udg_ReturnUnits[i]) then 
            call Clear()
        endif
        set i = i + 1
    endloop
    
    //cleaning up the mess
    set selected = null
    set anItem = null
    
endfunction
//===========================================================================
function InitTrig_Item_Management takes nothing returns nothing
    local trigger ItemManagementTrigger = CreateTrigger()
    call TriggerRegisterPlayerSelectionEventBJ( ItemManagementTrigger, Player(0), true )
    call TriggerAddAction( ItemManagementTrigger, function onSelection)
    set ItemManagementTrigger = null
endfunction

CBS is sure to have future versions. Hope you all like it.
Screen shots:
Click image for larger version

Name:	Image1.jpg
Views:	225
Size:	174.5 KB
ID:	36327
Click image for larger version

Name:	Image2.jpg
Views:	154
Size:	179.8 KB
ID:	36328

Here you have a demo-map to test, hope you all have fun.
Also note that CBS was based on simplicity. It is designed in a way that it allows the most basic Jasser to use it and mainly change it. So I bet most of you could make this system =)
Attached Files
File type: w3xCBS 1.0.w3x (1.1 MB)
08-08-2008, 08:19 PM#2
Pyrogasm
Quote:
Originally Posted by Flame_Phoenix
However, CBS is still under development and to finish it I require help from all of you.
Currently I am working on trying to fix a serious bug: Some how the system only works one time. I don't know why this happens. If you enter the bag one time, everything works fine however, if you enter the bag the second time, you will not be able to quit it.
I suspect the bug is some where inside the Clear function, but after debugging there is nothing I could find wrong, and there fore I am asking for all you people to please help me out.
Well then, post it in Triggers & Scripts and we'll just move it when you've got everything sorted out.

'till then, moved.

Edit: un-moved. I see you've got a thread there already; in that case I'll just leave this.
08-08-2008, 08:24 PM#3
Rising_Dusk
If he's got a thread in T&S for help on this and is submitting this, then this should be graveyarded and resubmitted when it is totally complete.
08-08-2008, 08:36 PM#4
Pyrogasm
That's what I thought to, but I didn't do it because I figured your input would be required.
08-08-2008, 08:48 PM#5
Flame_Phoenix
Mmm, I only need to fix this so I can submit it right after. I definitely don't feel like creating another submission after, so I decided to post it now and fix the bug =P

Still my thread in T&S is not being much helpful, that's also why I decided to post here, to see if things could change =S
08-08-2008, 11:08 PM#6
Fulla
Screenshots please :p
08-08-2008, 11:56 PM#7
Captain Griffen
Does this actually work? If not I'll graveyard this and you can PM me for it to be moved back when you update it.
08-09-2008, 12:45 AM#8
Tide-Arc Ephemera
Am I the only one who saw the filesize of the demo map?
08-09-2008, 10:10 AM#9
Flame_Phoenix
Bug was fixed, I will soon post the right version.
Also, the map size is big because it contains two filters with maximum quality.
I only use one, the filter with the campaigns mark, the other filter has no mark, so people have a filter to use if they want.
Screen shots and so will be posted soon as well as a fixed version.
08-09-2008, 05:36 PM#10
Rising_Dusk
Maybe you should actually explain in the first post what this is supposed to do. As far as I'm concerned, you shouldn't be screwing around with cameras in an inventory system. (Which is what a "Complex Bag System" sounds like to me)
08-09-2008, 06:58 PM#11
Flame_Phoenix
Quote:
Maybe you should actually explain in the first post what this is supposed to do. As far as I'm concerned, you shouldn't be screwing around with cameras in an inventory system. (Which is what a "Complex Bag System" sounds like to me)

Rising, your comment seems most ignorant. I will pretend you didn't say that.
Anyway new version is now here. It is most likely to suffer improvements do your judging minimals, but let's see what God has for me ...

Anyway, new version released, first post updated.
Also, if you guys think you can help with a better interface please visit:
http://www.wc3campaigns.net/showthre...41#post1028641
08-09-2008, 08:56 PM#12
TriggerHappy
Nice , i like it.

still not better than toadcops though :)

Im going to test it out and look at code
\


I just learned how 2 use trackables so maybe this can help me make my own inventory



EDIT : lol wierd u use units 2 detect clicks
08-09-2008, 09:08 PM#13
Flame_Phoenix
lol, my system was designed not to be like Toadcop. Toadcop is not a bag system, but an Item system. it is different, he changes and creates types of items in ways you can't imagine. My was designed to just a simple bag, so everyone could use it =)
However I admit Toadcop made a hell of a job.
08-09-2008, 09:15 PM#14
TriggerHappy
Why dont you use trackables?
08-09-2008, 10:44 PM#15
Flame_Phoenix
Quote:
Why dont you use trackables?
Mainly because of 1 reason: I don't know what they are. (lol)

Anyway, if you use vJASS or cache, forget it, I can't use such things.
Also, I believe my system of parallel arrays is pretty easy and simple so, why complicate things ?