I have a test version of a item system i have been working on. Its based in the hero's default inventory. Has 2 items at the bottom on the inventory to change pages to add more then the default 6 items.
The system is changeable in how many pages and how many items the hero can hold. I'm still working on the system to add more things to it. I'm posting this to get feed back from others to see what they think and new ideas for it.
The system supports stacking(only on same page as of now plan on changing that). Will support recipes(not yet added). Its easy to add new units to the system each time a unit is made you call the start function like this
any unit can be added to the system as long as that unit has an inventory.
heres the systems code:
I have also uploaded the map to this thread. Please leave feedback thanks
im not sure where to put this i had it in the map development area but i removed it
The system is changeable in how many pages and how many items the hero can hold. I'm still working on the system to add more things to it. I'm posting this to get feed back from others to see what they think and new ideas for it.
The system supports stacking(only on same page as of now plan on changing that). Will support recipes(not yet added). Its easy to add new units to the system each time a unit is made you call the start function like this
JASS:
local unit u = CreateUnit(Player(0), 'Hpal', 0, 0, 0)
call start(u)
heres the systems code:
JASS:
scope itemsystem initializer Init
globals
constant integer MAXPAGE = 5
constant integer MAXITEMS = 20
constant boolean STACKING = true // set this to false if you dont want stacking
pages array Page
endglobals
struct pages
unit Unit
player play
integer pagen = 1//keeps tract of the page number the player is on
integer array items[MAXITEMS]
integer array charge[MAXITEMS] //Keeps track of the items charges based on what item number the item is
private method itemnumber takes nothing returns integer
local integer it = 0
local integer i = 0
loop
exitwhen i == .pagen
set i = i + 1
if .pagen == 0 then
set it = 0
elseif i == .pagen then
set it = i * 4 - 3
endif
endloop
return it
endmethod
private method show takes nothing returns nothing
// This function will show the items for the give page
local integer i = .itemnumber()
local item i1
local integer it
loop
exitwhen i > .itemnumber() + 3
set it = .items[i]
set i1 = UnitAddItemById(.Unit, it)
if GetItemCharges(i1) > 0 then
call SetItemCharges(i1, .charge[i])
endif
set i = i + 1
endloop
call UnitAddItemToSlotById(.Unit, 'I000', 5)
call UnitAddItemToSlotById(.Unit, 'I001', 4)
endmethod
private method hide takes nothing returns nothing
// This function will hide all the items in the hero's inventory
local integer i = 0
local item it
loop
exitwhen i > 5
set it = UnitItemInSlot(.Unit, i)
call RemoveItem(it)
set i = i + 1
endloop
call .show()
set it = null
endmethod
method clickedpage takes boolean next returns nothing
// This function will change the page number when the player changes pages
if next == true then
if .pagen == MAXPAGE then
set .pagen = 1
call .hide()
else
set .pagen = .pagen + 1
call .hide()
endif
else
if .pagen == 1 then
set .pagen = MAXPAGE
call .hide()
else
set .pagen = .pagen - 1
call .hide()
endif
endif
endmethod
private method charges takes item it returns integer
local integer i = GetItemCharges(it)
set it = null
return i
endmethod
method stacking takes nothing returns nothing
local item it = GetManipulatedItem()
local integer charge = .charges(it)
local integer icharge
local integer i = 0
local boolean b = false
call SetItemUserData(it, 1)
loop
exitwhen i > 3
if GetItemTypeId(UnitItemInSlot(.Unit, i)) == GetItemTypeId(it) then
if GetItemUserData(UnitItemInSlot(.Unit, i)) != 1 then
set icharge = .charges(UnitItemInSlot(.Unit, i))
call SetItemCharges(UnitItemInSlot(.Unit, i), charge + icharge)
call RemoveItem(it)
set b = true
endif
endif
set i = i + 1
endloop
call SetItemUserData(it, 0)
set it = null
endmethod
method store takes nothing returns nothing
// This function saves the items in the heros inventory
local integer int = .itemnumber()
local integer i = 0
local item it
loop
exitwhen int > .itemnumber() + 3
set .items[int] = GetItemTypeId(UnitItemInSlot(.Unit, i))
if GetItemCharges(UnitItemInSlot(.Unit, i)) > 0 then
set .charge[int] = GetItemCharges(UnitItemInSlot(.Unit, i))
endif
set i = i + 1
set int = int + 1
endloop
set it = null
endmethod
static method new takes unit u returns pages
local pages page = pages.create()
set page.Unit = u
set page.play = GetOwningPlayer(u)
call UnitAddItemToSlotById(page.Unit, 'I000', 5)
call UnitAddItemToSlotById(page.Unit, 'I001', 4)
return page
endmethod
endstruct
private function check takes nothing returns boolean
return GetItemTypeId(GetManipulatedItem()) == 'I000' or GetItemTypeId(GetManipulatedItem()) == 'I001'
endfunction
private function Actions takes nothing returns nothing
local item it = GetManipulatedItem()
local integer i = 0
loop
exitwhen i > 10
if GetTriggerPlayer() == Player(i) then
call Page[i].store()
if GetItemTypeId(it) == 'I000' then
call Page[i].clickedpage(true)
elseif GetItemTypeId(it) == 'I001' then
call Page[i].clickedpage(false)
endif
endif
set i = i + 1
endloop
endfunction
private function Action takes nothing returns nothing
local item it = GetManipulatedItem()
local integer i = 0
loop
exitwhen i > 10
if GetTriggerPlayer() == Player(i) then
if GetItemCharges(it) > 0 then
if STACKING == true then
if check() == false then
call Page[i].stacking()
endif
endif
endif
endif
set i = i + 1
endloop
endfunction
function start takes unit u returns nothing
local pages page = pages.new(u)
local integer i = 0
loop
exitwhen i > 10
if GetOwningPlayer(u) == Player(i) then
set Page[i] = page
endif
set i = i + 1
endloop
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local integer i = 0
loop
exitwhen i > 10
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_USE_ITEM, null)
call TriggerRegisterPlayerUnitEvent(t1, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
set i = i + 1
endloop
call TriggerAddAction(t, function Actions)
call TriggerAddAction(t1, function Action)
endfunction
endscope
I have also uploaded the map to this thread. Please leave feedback thanks
im not sure where to put this i had it in the map development area but i removed it