| 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
 maps header:
constant function maxItemStorage takes nothing returns integer
return 1000
endfunction
function getItemIcon takes integer iconType returns integer
local integer i = 0
local integer itemType = iconType
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
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
loop
exitwhen(i == maxItemStorage())
if(udg_ItemArray[i] == itemType) then
return i
endif
set i = i + 1
endloop
return -1
endfunction
 the Setup Trigger:
function InitTrig_Item_Set_Up takes nothing returns nothing
local trigger SetUpTrigger = CreateTrigger()
set udg_ItemArray[0] = 'I000'
set udg_ItemIconArray[0] = 'B00D'
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"
set udg_ItemHasText[0] = true
set udg_ItemArray[1] = 'afac'
set udg_ItemIconArray[1] = 'B004'
set udg_ItemTextArray[1] = "Increases nearby ranged units' damage by <AIar,DataA1,%>%. |nDoes not stack with Trueshot Aura."
set udg_ItemHasText[1] = false
set udg_ItemArray[2] = 'spsh'
set udg_ItemIconArray[2] = 'B005'
set udg_ItemTextArray[2] = "Blocks a negative spell that an enemy casts on the Hero once every <ANss,Cool1> seconds."
set udg_ItemHasText[2] = false
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
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
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
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
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
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
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
 The create trigger:
constant function bagID takes nothing returns integer
return 'I000'
endfunction
constant function blueBag takes nothing returns integer
return 'B000'
endfunction
constant function grayBag takes nothing returns integer
return 'B001'
endfunction
constant function clickUnit takes nothing returns integer
return 'h000'
endfunction
constant function selectorId takes nothing returns integer
return 'h001'
endfunction
constant function dummyItemId takes nothing returns integer
return 'I001'
endfunction
constant function bagSize takes nothing returns integer
return 24
endfunction
constant function boardCapacity takes nothing returns integer
return 66
endfunction
constant function boardBagSlots takes nothing returns integer
return 60
endfunction
constant function bottomLeftX takes nothing returns real
return 0.
endfunction
constant function bottomLeftY takes nothing returns real
return 0.
endfunction
constant function textSize takes nothing returns real
return 0.0207
endfunction
constant function returnButtonsPos takes nothing returns real
return 215.
endfunction
constant function textDescriptionX takes nothing returns real
return 400.
endfunction
constant function textDescriptionY takes nothing returns real
return 250.
endfunction
constant function backGroundPath takes nothing returns string
return "war3mapImported\\BMP.blp"
endfunction
function itemCustomtext takes item anItem returns string
return "|cff8000FFName: |r" + "|cff0000FF" + GetItemName(anItem) + "|r"
endfunction
constant function forAll takes nothing returns boolean
return true
endfunction
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.)
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
function pauseUnits takes nothing returns nothing
call IssueImmediateOrder(udg_User, "stop")
call PauseUnit(udg_User, true)
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()
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
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.)
endif
set positionX = positionX + 25
set i = i + 1
endloop
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.)
endif
set positionX = positionX + 25
set i = i + 1
endloop
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.)
endif
set positionX = positionX + 25
set i = i + 1
endloop
set i = 60
set j = 0
loop
exitwhen(i == 66)
set udg_BagPack[i] = UnitItemInSlot(udg_User, j )
set i = i + 1
set j = j + 1
endloop
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
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
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
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
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
 Item Managing trigger:
function ResetCamera takes nothing returns nothing
call PauseTimer(udg_CameraTimer)
call ResetToGameCamera(0.0)
call DisplayCineFilter(false)
call EnableUserUI(true)
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))
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
call DestroyTextTag(udg_ItemInterfaceText)
set udg_ItemInterfaceText = null
call KillDestructable(udg_ImageDescription)
set udg_ImageDescription = null
endfunction
function ItemDescriptionArea takes integer itemPosition returns nothing
call KillDestructable(udg_ImageDescription)
set udg_ImageDescription = CreateDestructable(getItemIcon(GetItemTypeId(udg_BagPack[itemPosition])), bottomLeftX() + 350, bottomLeftY() + 200, 180, 0.5, 1)
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
function unPauseUnits takes nothing returns nothing
call PauseUnit(udg_User, false)
endfunction
function Clear takes nothing returns nothing
local integer j
local item anItem = null
set j = 0
loop
exitwhen(j == 66)
call KillUnit(udg_ClickUnits[j])
set udg_ClickUnits[j] = null
call KillDestructable(udg_InterfaceIcons[j])
set udg_InterfaceIcons[j] = null
set j = j + 1
endloop
set j = 0
loop
exitwhen(j > 6)
call KillUnit(udg_ReturnUnits[j])
set udg_ReturnUnits[j] = null
set j = j + 1
endloop
call ClearSelections()
call ClearItemDescriptionArea()
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
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
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()
set udg_User = null
endfunction
function onSelection takes nothing returns nothing
local unit selected = GetTriggerUnit()
local integer selectedId = GetUnitTypeId(selected)
local integer i
local integer j
local integer k
local item anItem = null
set i = 0
loop
exitwhen(i == boardCapacity())
if (selected == udg_ClickUnits[i]) then
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
call ItemDescriptionArea(i)
endif
else
if ((udg_ClickedUnit[0] == selected)) then
call ClearSelections()
else
if (udg_BagPack[i] == null) then
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]
set udg_BagPack[udg_ClickedNumber] = null
call ClearSelections()
endif
else
if not(GetItemTypeId(udg_BagPack[udg_ClickedNumber]) == bagID() and (i < boardBagSlots())) then
call KillDestructable(udg_InterfaceIcons[i])
call KillDestructable(udg_InterfaceIcons[udg_ClickedNumber])
set anItem = udg_BagPack[i]
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(getItemIcon(GetItemTypeId(anItem)), GetUnitX(udg_ClickUnits[udg_ClickedNumber]), GetUnitY(udg_ClickUnits[udg_ClickedNumber]),180, 0.3, 1)
set udg_BagPack[i] = udg_BagPack[udg_ClickedNumber]
set udg_BagPack[udg_ClickedNumber] = anItem
call ClearSelections()
endif
endif
endif
endif
endif
set i = i + 1
endloop
set i = 0
loop
exitwhen(i == 7)
if (selected == udg_ReturnUnits[i]) then
call Clear()
endif
set i = i + 1
endloop
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:
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 =) |