This is an advanced Inventory System, fully written in vjass.
It allows the user to add heroes and advanced inventory system, which features:
Equipment Menu with 8 Slots
8 Slot Backpack
Auto Stack Detection System
Advanced Item Handling
....
Requires:
vJass
Table, TimerUtils & SimError (by Vexorian)
StringRead (short System by D1000)
BonusMod & SetUnitMaxState (by Earth-Fury)
Icons by:
BruZzl3R_17C
Fore more details, look in the librarys.
If you wan't to use this system correct, you have to disable 2 thinks in the Gameplay-Interface:
Text - Message - 'Inventory is full':
Delate this message " ", else the normal wc3 Message will be shown, that you hero#s inventory is full
Sound - Inventory Full:
Just "Shift-Klick", press space and then enter again. That disables the sound, which will be played, wenn the inventory is full.
Changelogs
Version 2.01b:
Demo Map:
- added a computer bot to demo map, so it can be runned direct through warcraft
//////////////////////////////////////////
// OLD CHANGELOGS: //
//////////////////////////////////////////
Version 2.01:
Inventory System:
- added two new globals for movement speed
Item List:
- added movement speed bonus
- fixed bug in addNormelItem method
Version 2.00:
Inventory System:
- added a 8 slot backpack
- added a auto stack detection system
- added fully triggered item pickup
- ALOT code changes and improvements
- Added some more constants
- now uses TimerUtils
- Item now can be equipped when the equipment menu is opened (through auto equip for example)
Item List:
- added more configurations
- removed / delated methods which are not required
- added some new methods / operators for handling with "Items"
- made some struct member private
- added possibility to add potions to the system (uses the new configurations)
- added the possibility to add "special efffects" to items (only for Equipment)
Demo Map:
- added 6 new Items
Version 1.02:
Inventory System:
-added auto equip to the system
-added normal functions to add heroes to the system, get its Inventory and specific items in slots
-some small code changes
Item List:
-added functions to add items directly to their Slot
Demo Map:
-added 3 example items
Version 1.01:
Inventory System:
-added custom Icons for "Emtpy Slots".
-you now can setup the position of the 'Inventory-Item'.
-After closing the inventory, the items now will be added to the place they where before closing.
-When equiping an item and its slot is full, the item will be switched to the same slot, the new equipped item was
globals //The Rawcodes of the Items for opening the backpack and equipment privateconstantinteger EQUIPMENT_OPEN_ID = 'I000' privateconstantinteger BACKPACK_OPEN_ID = 'I00R'
//The rawcodes of the Items for closing the backpack and equipment privateconstantinteger EQUIPMENT_CLOSE_ID = 'I001' privateconstantinteger BACKPACK_CLOSE_ID = 'I00S'
//The rawcodes of the Items changing the pages of the backpack and equipment menu privateconstantinteger EQUIPMENT_PAGE_1 = 'I003' privateconstantinteger BACKPACK_PAGE_1 = 'I00T'
//The slots, where the items for opening backpack and equipment menu should be created privateconstantinteger EQUIPMENT_SLOT = 4 privateconstantinteger BACKPACK_SLOT = 5
//The place, where required items should be stored privateconstantreal STORE_ITEM_X = 0. privateconstantreal STORE_ITEM_Y = 0.
//The Maximum Movespeed a unit can have privateconstantreal MAX_MOVEMENT_SPEED = 400. //The Minimum Movespeed a unit can have privateconstantreal MIN_MOVEMENT_SPEED = 150.
//The Max Number of Charges, an item can has maximum constantinteger MAX_ITEM_CHARGES = 8
//If true, the equipment menu will change to first page when opened privateconstantboolean CHANGE_TO_FIRST = true //If trie, an item being picked up will be auto equipped, if its slot is emtpy and the hero can wear it privateconstantboolean AUTO_EQUIP = true //The distance, an item can be picked up by a hero privateconstantreal ITEM_PICKUP_DIST = 225.00
privatefunction SETUP_DUMMY_ITEMS takesnothingreturnsnothing set DUMMY_ITEMS[0] = 'I004'//Head set DUMMY_ITEMS[1] = 'I005'//Chest set DUMMY_ITEMS[2] = 'I006'//Main Hand set DUMMY_ITEMS[3] = 'I007'//Secondary Hand set DUMMY_ITEMS[4] = 'I008'//Gloves set DUMMY_ITEMS[5] = 'I009'//Feet set DUMMY_ITEMS[6] = 'I00A'//First Acessory set DUMMY_ITEMS[7] = 'I00B'//Second Acessory endfunction
//EVERYTHING BELOW HERE IS SYSTEM CODE!!! privatekeyword addItem
//This is the triggered item pickup and stack detection System. privatestruct StackData privatedelegate Inventory inv = 0 itemitem = null real x = 0 real y = 0 integer order = 0
//creates a new instance of the stackdata staticmethod create takesunit hero, item which returns StackData local StackData this = StackData.allocate() set .inv = Inventory.table[hero] set .item = which set .x = GetItemX(.item) set .y = GetItemY(.item) call IssuePointOrder(.Owner, "move", .x, .y) set .order = GetUnitCurrentOrder(.Owner) set .datas[.count] = this set .count = .count + 1 returnthis endmethod
//checks if the issued target was an item and the order is correct staticmethod check takesnothingreturnsboolean if GetOrderTargetItem() != nulland(GetIssuedOrderId() == 851971)then call StackData.create(GetTriggerUnit(), GetOrderTargetItem()) returntrue endif returnfalse endmethod
//just sorts and checks each stackdata... staticmethod periodic takesnothingreturnsnothing localinteger i = .count - 1 loop exitwhen i < 0 ifnot .datas[i].control()then set .count = .count - 1 if .count < 0then set .count = 0 else set .datas[i] = .datas[.count] endif endif set i = i - 1 endloop endmethod
//checks the hero and the item every interval method control takesnothingreturnsboolean localreal dx = GetUnitX(.Owner) - .x localreal dy = GetUnitY(.Owner) - .y local Item it = Item.getItemById(GetItemTypeId(.item)) if GetUnitCurrentOrder(.Owner) != .order or GetItemX(.item) != .x or GetItemY(.item) != .y or GetWidgetLife(.Owner) <= 0.405then returnfalse elseif SquareRoot(dx * dx + dy * dy) <= ITEM_PICKUP_DIST and GetItemX(.item) == .x or GetItemY(.item) == .y and GetWidgetLife(.Owner) > 0.405then call IssueImmediateOrder(.Owner, "stop") if(AUTO_EQUIP and it.equippable and .isSlotEmpty(it.slot)and .checkHero(it, false)and .allowauto)then return Inventory.equipItem(.Owner, .item, it) endif ifnot .checkItemForStack(.item)then ifnot .getSlotForItem(.item)then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse endif endif returnfalse elseif SquareRoot(dx * dx + dy * dy) > ITEM_PICKUP_DIST then returntrue endif returnfalse endmethod
//private struct required to "recreate" items in their slots when their are dragged or dropped incrorrect privatestruct addItem delegate Inventory inv integer id integer charges integer slot privatetimer t
//creates a new instance for an item to a move it to a slot staticmethod create takesitem it, integer slot, Inventory inv returnsthistype localthistypethis = thistype.allocate() set .inv = inv set .id = GetItemTypeId(it) set .charges = GetItemCharges(it) set .slot = slot set .dropped = false call RemoveItem(it) set .dropped = true set .t = NewTimer() call SetTimerData(.t, this) call TimerStart(.t, 0.0, false, functionthistype.expire) returnthis endmethod
//creates a new Inventory for the unit staticmethod create takesunit whichUnit, string heroClass, string availableItemClasses returnsthistype localthistypethis = 0 localinteger i = 0 ifnot .table.exists(whichUnit)then setthis = thistype.allocate() set .Owner = whichUnit set .HeroClass = heroClass set .ItemClasses = availableItemClasses loop exitwhen i > 8 set .equip[i] = CreateItem(DUMMY_ITEMS[i], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[i], false) set i = i + 1 endloop
call UnitAddItemToSlotById(.Owner, EQUIPMENT_OPEN_ID, EQUIPMENT_SLOT) call UnitAddItemToSlotById(.Owner, BACKPACK_OPEN_ID, BACKPACK_SLOT) call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) set .table[.Owner] = this returnthis endif return0 endmethod
//opens the backpack for the unit publicstaticmethod openBackpack takesunit whichUnit returnsboolean localinteger i = 0 localinteger i2 = 0 localthistypethis = .table[whichUnit] localitem temp = null localinteger add = 0 ifnot .table.exists(whichUnit)then returnfalse elseifnot .bopen andnot .open then set .bopen = true set .allowauto = false loop exitwhen i > 5 set temp = UnitItemInSlot(.Owner, i) set .charges[i] = GetItemCharges(temp) set .items[i] = GetItemTypeId(temp) call RemoveItem(temp) set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, BACKPACK_CLOSE_ID, 5) if .bpage <= 1then set i = 0 loop exitwhen i > 3 if .backp[i] != 0then call UnitAddItemToSlotById(.Owner, .backp[i], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .bcharges[i]) endif set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_2, 4) elseif .bpage >= 2then set i = 0 loop exitwhen i > 3 if .backp[i+4] != 0then call UnitAddItemToSlotById(.Owner, .backp[i+4], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .bcharges[i+4]) endif set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_1, 4) endif set temp = null set .allowauto = true returntrue endif returntrue endmethod
//opens the equipment menu publicstaticmethod openEquipment takesunit whichUnit returnsboolean localinteger i = 0 localthistypethis = .table[whichUnit] localitem temp = null ifnot .table.exists(whichUnit)then returnfalse elseifnot .open andnot .bopen then set .open = true set .allowauto = false if .page <= 1 or CHANGE_TO_FIRST then loop exitwhen i > 5 set temp = UnitItemInSlot(.Owner, i) set .charges[i] = GetItemCharges(temp) set .items[i] = GetItemTypeId(temp) call RemoveItem(temp) if i < 4then call SetItemVisible(.equip[i], true) call UnitAddItem(.Owner, .equip[i]) endif set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, EQUIPMENT_PAGE_2, 4) elseif .page >= 2andnot CHANGE_TO_FIRST then loop exitwhen i > 5 set temp = UnitItemInSlot(.Owner, i) set .charges[i] = GetItemCharges(temp) set .items[i] = GetItemTypeId(temp) call RemoveItem(temp) if i < 4then call SetItemVisible(.equip[i+4], true) call UnitAddItem(.Owner, .equip[i+4]) endif set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, EQUIPMENT_PAGE_1, 4) endif call UnitAddItemToSlotById(.Owner, EQUIPMENT_CLOSE_ID, 5) set .allowauto = true returntrue endif returntrue endmethod
//closes the hero's backpack publicstaticmethod closeBackpack takesunit whichUnit returnsboolean localinteger i = 0 localitem t = null localthistypethis = .table[whichUnit] localitem temp = null ifnot .table.exists(whichUnit)then returnfalse elseif .bopen then set .bopen = false set .allowauto = false call RemoveItem(UnitItemInSlot(.Owner, 5)) call RemoveItem(UnitItemInSlot(.Owner, 4)) if .bpage <= 1then loop exitwhen i > 3 set temp = UnitRemoveItemFromSlot(.Owner, i) set .backp[i] = GetItemTypeId(temp) set .bcharges[i] = GetItemCharges(temp) call RemoveItem(temp) set i = i + 1 endloop elseif .bpage >= 2then loop exitwhen i > 3 set temp = UnitRemoveItemFromSlot(.Owner, i) set .backp[i+4] = GetItemTypeId(temp) set .bcharges[i+4] = GetItemCharges(temp) call RemoveItem(temp) set i = i + 1 endloop endif
set i = 0 loop exitwhen i > 5 if .items[i] != 0then call UnitAddItemToSlotById(.Owner, .items[i], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .charges[i]) endif set i = i + 1 endloop set .bfree = .getBackpackPlace() call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) set .allowauto = true set temp = null returntrue endif returnfalse endmethod
//closes the hero's equipment menu publicstaticmethod closeEquipment takesunit whichUnit returnsboolean localinteger i = 0 localitem t = null localthistypethis = .table[whichUnit] localinteger add = 0 ifnot .table.exists(whichUnit)then returnfalse elseif .open then set .open = false set .allowauto = false if .page >= 2then set add = 4 endif loop exitwhen i > 3 set .equip[i+add] = UnitRemoveItemFromSlot(.Owner, i) call SetItemPosition(.equip[i+add], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[i+add], false) set i = i + 1 endloop call RemoveItem(UnitItemInSlot(.Owner, 5)) call RemoveItem(UnitItemInSlot(.Owner, 4))
set i = 0 loop exitwhen i > 5 if .items[i] != 0then call UnitAddItemToSlotById(.Owner, .items[i], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .charges[i]) endif set i = i + 1 endloop
call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) if CHANGE_TO_FIRST then set .page = 1 endif set .allowauto = true returntrue endif returnfalse endmethod
//changes the backpack pages of the unit publicstaticmethod changePageBackpack takesunit whichUnit returnsboolean localinteger i = 0 localthistypethis = .table[whichUnit] localitem temp = null if .bopen andthis != 0then set .dropped = false call RemoveItem(UnitItemInSlot(.Owner, 4)) set .dropped = true set .allowauto = false if .bpage <= 1then loop exitwhen i > 3 set temp = UnitRemoveItemFromSlot(.Owner, i) set .backp[i] = GetItemTypeId(temp) set .bcharges[i] = GetItemCharges(temp) call UnitAddItemToSlotById(.Owner, .backp[i+4], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .bcharges[i+4]) call RemoveItem(temp) set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_1, 4) set .bpage = 2 elseif .bpage >= 2then loop exitwhen i > 3 set temp = UnitRemoveItemFromSlot(.Owner, i) set .backp[i+4] = GetItemTypeId(temp) set .bcharges[i+4] = GetItemCharges(temp) call UnitAddItemToSlotById(.Owner, .backp[i], i) call SetItemCharges(UnitItemInSlot(.Owner, i), .bcharges[i]) call RemoveItem(temp) set i = i + 1 endloop call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_2, 4) set .bpage = 1 endif set .allowauto = true set temp = null returntrue endif returnfalse endmethod
//changes the equipment menu pages for the unit publicstaticmethod changePageEquipment takesunit whichUnit returnsboolean localinteger i = 0 localthistypethis = .table[whichUnit] localinteger add = 0 if .open andthis != 0then if .page >= 2then set add = 4 endif set .allowauto = false loop exitwhen i > 3 set .equip[i+add] = UnitRemoveItemFromSlot(.Owner, i) call SetItemPosition(.equip[i+add], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[i+add], false) call UnitAddItem(.Owner, .equip[i+4-add]) set i = i + 1 endloop set .dropped = false call RemoveItem(UnitItemInSlot(.Owner, 4)) set .dropped = true if .page >= 2then call UnitAddItemToSlotById(.Owner, EQUIPMENT_PAGE_2, 4) set .page = 1 elseif .page <= 1then call UnitAddItemToSlotById(.Owner, EQUIPMENT_PAGE_1, 4) set .page = 2 endif set .allowauto = true returntrue endif returnfalse endmethod
//Only call this method, if you can be shure, that the Item's slot is empty or it will bug! publicstaticmethod quickEquip takesunit u, Item it returnsboolean localthistypethis = .table[u] if .checkHero(it, true)then set .equip[it.slot] = CreateItem(it.itemId, STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[it.slot], false) call SetItemDroppable(.equip[it.slot], false) call .applyItemStats(it) returntrue endif returnfalse endmethod
//equips an item for a hero publicstaticmethod equipItem takesunit u, item t, Item it returnsboolean localthistypethis = .table[u] localinteger itd1 = 0 localinteger itd2 = 0 localinteger slot = 0 localinteger i = 0 if .checkHero(it, true)then ifnot .isItemEquipped(t)and .isSlotEmpty(it.slot)then ifnot .open then call RemoveItem(.equip[it.slot]) set .equip[it.slot] = t call SetItemPosition(.equip[it.slot], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[it.slot], false) call SetItemDroppable(.equip[it.slot], false) call .applyItemStats(it) returntrue elseif .open then set .dropped = false if .page <= 1then if it.slot <= 3then ifnot(GetItemTypeId(UnitItemInSlot(.Owner, it.slot)) == DUMMY_ITEMS[it.slot])then ifnot .getSlotForItem(UnitItemInSlot(.Owner, it.slot))then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse endif else call RemoveItem(UnitItemInSlot(.Owner, it.slot)) endif call UnitAddItemToSlotById(.Owner, it.itemId, it.slot) call .applyItemStats(it) returntrue elseif it.slot > 3then ifnot(GetItemTypeId(.equip[it.slot]) == DUMMY_ITEMS[it.slot])then ifnot .getSlotForItem(.equip[it.slot])then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse endif else call RemoveItem(.equip[it.slot]) endif set .equip[it.slot] = t call SetItemPosition(.equip[it.slot], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[it.slot], false) call SetItemDroppable(.equip[it.slot], false) call .applyItemStats(it) returntrue endif elseif .page >= 2then if it.slot > 3then ifnot(GetItemTypeId(UnitItemInSlot(.Owner, it.slot - 4)) == DUMMY_ITEMS[it.slot])then ifnot .getSlotForItem(UnitItemInSlot(.Owner, it.slot - 4))then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse endif else call RemoveItem(UnitItemInSlot(.Owner, it.slot - 4)) endif call UnitAddItemToSlotById(.Owner, it.itemId, it.slot - 4) call .applyItemStats(it) returntrue elseif it.slot <= 3then ifnot(GetItemTypeId(.equip[it.slot]) == DUMMY_ITEMS[it.slot])then ifnot .getSlotForItem(UnitItemInSlot(.Owner, it.slot))then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse endif else call RemoveItem(.equip[it.slot]) endif set .equip[it.slot] = t call SetItemPosition(.equip[it.slot], STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[it.slot], false) call SetItemDroppable(.equip[it.slot], false) call .applyItemStats(it) returntrue endif endif endif elseifnot .isSlotEmpty(it.slot)then set itd1 = GetItemTypeId(t) set slot = .getItemSlot(t) call RemoveItem(t) set itd2 = GetItemTypeId(.equip[it.slot]) call RemoveItem(.equip[it.slot]) call .removeItemStats(Item.getItemById(itd2)) call .applyItemStats(it) set .equip[it.slot] = CreateItem(itd1, STORE_ITEM_X, STORE_ITEM_Y) call SetItemVisible(.equip[it.slot], false) call UnitAddItemToSlotById(.Owner, itd2, slot) call SetItemDroppable(.equip[it.slot], false) returntrue endif endif returnfalse endmethod
//un-equips an item for the hero publicstaticmethod unequipItem takesunit u, item t, Item it returnsboolean localthistypethis = .table[u] ifnot .getSlotForItem(t)then call SimError(GetOwningPlayer(.Owner), "Inventory and Backpack are full.") returnfalse else call .removeItemStats(it) set .equip[it.slot] = UnitAddItemById(.Owner, DUMMY_ITEMS[it.slot]) returntrue endif endmethod
//Returns true, if the given item is equipped (or an item with the same ItemTypeId) publicmethod isItemEquipped takesitem whichItem returnsboolean//INLINE FRIENDLY return GetItemTypeId(.equip[Item.getItemById(GetItemTypeId(whichItem)).slot]) == GetItemTypeId(whichItem) endmethod
//Returns true, if the given slot is empty publicmethod isSlotEmpty takesinteger Slot returnsboolean//INLINE FRIENDLY return GetItemTypeId(.equip[Slot]) == DUMMY_ITEMS[Slot] endmethod
//checks, if the hero has the possibility to stack the given item with another publicmethod checkItemForStack takesitem for returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(for) localinteger bonus = 0 local Item it = Item.getItemById(GetItemTypeId(for)) ifnot .open andnot .bopen andnot it.equippable then loop exitwhen i > 5 if GetItemTypeId(UnitItemInSlot(.Owner, i)) == id and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= MAX_ITEM_CHARGES and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(UnitItemInSlot(.Owner, i)) + bonus) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 7 if .backp[i] == id and .bcharges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) set .bcharges[i] = .bcharges[i] + bonus call RemoveItem(for) returntrue endif set i = i + 1 endloop
elseif .open then loop exitwhen i > 5 if .items[i] == id and .charges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .charges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) set .charges[i] = .charges[i] + bonus returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 7 if .backp[i] == id and .bcharges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) set .bcharges[i] = .bcharges[i] + bonus returntrue endif set i = i + 1 endloop
elseif .bopen then loop exitwhen i > 5 if .items[i] == id and .charges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .charges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) set .charges[i] = .charges[i] + bonus returntrue endif set i = i + 1 endloop
if .bpage <= 1then set i = 0 loop exitwhen i > 3 if GetItemTypeId(UnitItemInSlot(.Owner, i)) == id and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= MAX_ITEM_CHARGES and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(UnitItemInSlot(.Owner, i)) + bonus) returntrue endif set i = i + 1 endloop
set i = 4 loop exitwhen i > 7 if .backp[i] == id and .bcharges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) set .bcharges[i] = .bcharges[i] + bonus returntrue endif set i = i + 1 endloop
elseif .bpage >= 2then
set i = 0 loop exitwhen i > 3 if GetItemTypeId(UnitItemInSlot(.Owner, i)) == id and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= MAX_ITEM_CHARGES and GetItemCharges(UnitItemInSlot(.Owner, i)) + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) call RemoveItem(for) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(UnitItemInSlot(.Owner, i)) + bonus) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 3 if .backp[i] == id and .bcharges[i] + GetItemCharges(for) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(for) <= it.maxCharges then set bonus = GetItemCharges(for) set .bcharges[i] = .bcharges[i] + bonus call RemoveItem(for) returntrue endif set i = i + 1 endloop endif
endif returnfalse endmethod
//checks if the hero has a empty item slot publicmethod getSlotForItem takesitem for returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(for) ifnot .open andnot .bopen then loop exitwhen i > 5 if UnitItemInSlot(.Owner, i) == nullthen call UnitAddItemToSlotById(.Owner, id, i) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(for)) call RemoveItem(for) returntrue endif set i = i + 1 endloop set i = 0 loop exitwhen i > 7 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(for) call RemoveItem(for) set .bfree = .bfree - 1 ifnot .open or .bopen then call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) endif returntrue endif set i = i + 1 endloop
elseif .open then loop exitwhen i > 5 if .items[i] == 0then set .items[i] = id set .charges[i] = GetItemCharges(for) call RemoveItem(for) returntrue endif set i = i + 1 endloop set i = 0
loop exitwhen i > 7 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(for) call RemoveItem(for) set .bfree = .bfree - 1 ifnot .open or .bopen then call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) endif returntrue endif set i = i + 1 endloop
elseif .bopen then
if .bpage <= 1then set i = 0 loop exitwhen i > 3 if UnitItemInSlot(.Owner, i) == nullthen call UnitAddItemToSlotById(.Owner, id, i) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(for)) call RemoveItem(for) returntrue endif set i = i + 1 endloop
set i = 4 loop exitwhen i > 7 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(for) call RemoveItem(for) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 5 if .items[i] == 0then set .items[i] = id set .charges[i] = GetItemCharges(for) call RemoveItem(for) returntrue endif set i = i + 1 endloop
elseif .bpage >= 2then
set i = 0 loop exitwhen i > 3 if UnitItemInSlot(.Owner, i) == nullthen call UnitAddItemToSlotById(.Owner, id, i) call SetItemCharges(UnitItemInSlot(.Owner, i), GetItemCharges(for)) call RemoveItem(for) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 3 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(for) call RemoveItem(for) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 5 if .items[i] == 0then set .items[i] = id set .charges[i] = GetItemCharges(for) call RemoveItem(for) returntrue endif set i = i + 1 endloop endif
endif returnfalse endmethod
//Applies the item's stats to the hero privatemethod applyItemStats takes Item it returnsnothing if it.Ms + GetUnitMoveSpeed(.Owner) > MAX_MOVEMENT_SPEED then set .MsBoni[it.slot] = MAX_MOVEMENT_SPEED - GetUnitMoveSpeed(.Owner) else set .MsBoni[it.slot] = it.Ms endif call SetUnitMoveSpeed(.Owner, GetUnitMoveSpeed(.Owner) + .MsBoni[it.slot]) call UnitAddBonus(.Owner, 0, it.Armor) call UnitAddBonus(.Owner, 1, it.Dmg) call UnitAddBonus(.Owner, 2, it.As) call UnitAddBonus(.Owner, 3, it.MpReg) call UnitAddBonus(.Owner, 4, it.HpReg) call UnitAddBonus(.Owner, 5, it.Str) call UnitAddBonus(.Owner, 6, it.Agi) call UnitAddBonus(.Owner, 7, it.Int) call AddUnitMaxState(.Owner, UNIT_STATE_MAX_LIFE, it.Life) call AddUnitMaxState(.Owner, UNIT_STATE_MAX_MANA, it.Mana) if it.Effect != ""and it.EffectAttach != ""then set .fx[it.slot] = AddSpecialEffectTarget(it.Effect, .Owner, it.EffectAttach) endif if it.Abil != 0then call UnitAddAbility(.Owner, it.Abil) endif endmethod
//returns the slot of an item privatemethod getItemSlot takesitem it returnsinteger localitem temp = null localinteger i = 0 loop set temp = UnitItemInSlot(.Owner, i) exitwhen i > 5 or temp == it set i = i + 1 endloop set temp = null return i endmethod
//Returns the first free Inventory slot of the hero privatemethod getFreeSlot takesnothingreturnsinteger localinteger i = 0 localinteger free loop exitwhen i > 4 if .items[i] == 0then set free = i endif exitwhen .items[i] == 0 set i = i + 1 endloop return free endmethod
//Returns the first free backpack slot of the hero privatemethod getFreeBackpackSlot takesnothingreturnsinteger localinteger i = 0 localinteger free loop exitwhen i > 7 if .backp[i] == 0then set free = i endif exitwhen .backp[i] == 0 set i = i + 1 endloop return free endmethod
//Returns the free place of the hero's backpack privatemethod getBackpackPlace takesnothingreturnsinteger localinteger i = 0 localinteger i2 = 8 loop exitwhen i > 7 if .backp[i] != 0then set i2 = i2 - 1 endif set i = i + 1 endloop return i2 endmethod
//Returns the free place of the hero's Inventory privatemethod getInventoryPlace takesnothingreturnsinteger localinteger i = 0 localinteger i2 = 4 loop exitwhen i > 3 if .items[i] != 0then set i2 = i2 - 1 endif set i = i + 1 endloop return i2 endmethod
//moves an item to the hero's backpack privatemethod moveToBackpack takesitem Moved, item Bag returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(Moved) localinteger Slot if .getBackpackPlace() > 0then loop exitwhen i > 7 if .backp[i] == id and .bcharges[i] + GetItemCharges(Moved) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(Moved) <= Item.getItemById(GetItemTypeId(Moved)).maxCharges then set .bcharges[i] = .bcharges[i] + GetItemCharges(Moved) call RemoveItem(Bag) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_OPEN_ID, BACKPACK_SLOT) call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) returntrue endif set i = i + 1 endloop set i = 0 loop exitwhen i > 7 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(Moved) set .bfree = .bfree - 1 call RemoveItem(Bag) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_OPEN_ID, BACKPACK_SLOT) call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) returntrue endif set i = i + 1 endloop elseif .getBackpackPlace() <= 0then set Slot = .getItemSlot(Moved) set i = GetItemCharges(Moved) call RemoveItem(Bag) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_OPEN_ID, BACKPACK_SLOT) call SetItemCharges(UnitItemInSlot(.Owner, BACKPACK_SLOT), .bfree) call UnitAddItemToSlotById(.Owner, id, Slot) call SetItemCharges(UnitItemInSlot(.Owner, Slot), i) call SimError(GetOwningPlayer(.Owner), "Backpack is full!") returnfalse endif returnfalse endmethod
//moves an item from the first page to the second page privatemethod moveToSecondPage takesitem Moved, item Second returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(Moved) localinteger Slot loop exitwhen i > 3 if .backp[i+4] == id and .bcharges[i+4] + GetItemCharges(Moved) <= MAX_ITEM_CHARGES and .bcharges[i+4] + GetItemCharges(Moved) <= Item.getItemById(GetItemTypeId(Moved)).maxCharges then set .bcharges[i+4] = .bcharges[i+4] + GetItemCharges(Moved) call RemoveItem(Second) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_2, 4) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 3 if .backp[i+4] == 0then set .backp[i+4] = id set .bcharges[i+4] = GetItemCharges(Moved) call RemoveItem(Second) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_2, 4) returntrue endif set i = i + 1 endloop
set Slot = .getItemSlot(Moved) set i = GetItemCharges(Moved) call RemoveItem(Second) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_2, 4) call UnitAddItemToSlotById(.Owner, id, Slot) call SetItemCharges(UnitItemInSlot(.Owner, Slot), i) call SimError(GetOwningPlayer(.Owner), "Cannot move item to a full page!") returnfalse endmethod
//moves an item from the second page to the first page privatemethod moveToFirstPage takesitem Moved, item First returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(Moved) localinteger Slot loop exitwhen i > 3 if .backp[i] == id and .bcharges[i] + GetItemCharges(Moved) <= MAX_ITEM_CHARGES and .bcharges[i] + GetItemCharges(Moved) <= Item.getItemById(GetItemTypeId(Moved)).maxCharges then set .bcharges[i] = .bcharges[i] + GetItemCharges(Moved) call RemoveItem(First) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_1, 4) returntrue endif set i = i + 1 endloop
set i = 0 loop exitwhen i > 3 if .backp[i] == 0then set .backp[i] = id set .bcharges[i] = GetItemCharges(Moved) call RemoveItem(First) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_1, 4) returntrue endif set i = i + 1 endloop
set Slot = .getItemSlot(Moved) set i = GetItemCharges(Moved) call RemoveItem(First) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_PAGE_1, 4) call UnitAddItemToSlotById(.Owner, id, Slot) call SetItemCharges(UnitItemInSlot(.Owner, Slot), i) call SimError(GetOwningPlayer(.Owner), "Cannot move item to a full page!") returnfalse endmethod
//moves an item to the heroes inventory privatemethod moveToInventory takesitem Moved, item Close returnsboolean localinteger i = 0 localinteger id = GetItemTypeId(Moved) localinteger Slot if .getInventoryPlace() > 0then loop exitwhen i > 3 if .items[i] == id and .charges[i] + GetItemCharges(Moved) <= MAX_ITEM_CHARGES and .charges[i] + GetItemCharges(Moved) <= Item.getItemById(GetItemTypeId(Moved)).maxCharges then set .charges[i] = .charges + GetItemCharges(Moved) set .bfree = .bfree + 1 call RemoveItem(Close) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_CLOSE_ID, 5) returntrue endif set i = i + 1 endloop
set i = .getFreeSlot() set .items[i] = id set .charges[i] = GetItemCharges(Moved) set .bfree = .bfree + 1 call RemoveItem(Close) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_CLOSE_ID, 5) returntrue
elseif .getInventoryPlace() <= 0then set Slot = .getItemSlot(Moved) set i = GetItemCharges(Moved) call RemoveItem(Close) call RemoveItem(Moved) call UnitAddItemToSlotById(.Owner, BACKPACK_CLOSE_ID, 5) call UnitAddItemToSlotById(.Owner, id, Slot) call SetItemCharges(UnitItemInSlot(.Owner, Slot), i) call SimError(GetOwningPlayer(.Owner), "Inventory is full!") returnfalse endif returnfalse endmethod
//checks, if a hero can equip an item publicmethod checkHero takes Item it, boolean UseError returnsboolean if it.HeroClasses != ""then ifnot SearchString(it.HeroClasses, .HeroClass)then if UseError then call SimError(GetOwningPlayer(.Owner), "Only " + it.HeroClasses + " can equip this item.") endif returnfalse endif endif if it.ItemClass != ""then ifnot SearchString(.ItemClasses, it.ItemClass)then if UseError then call SimError(GetOwningPlayer(.Owner), "This unit can't equip " + it.ItemClass + ".") endif returnfalse endif endif if GetHeroLevel(.Owner) >= it.Level then returntrue else if UseError then call SimError(GetOwningPlayer(.Owner), "This item requires a hero level of " + I2S(it.Level) + " or greater.") endif endif returnfalse endmethod
//will be runned, whenever an item is used privatestaticmethod useItem takesnothingreturnsboolean localthistypethis = .table[GetTriggerUnit()] local Item it = Item.getItemById(GetItemTypeId(GetManipulatedItem())) if GetItemTypeId(GetManipulatedItem()) == EQUIPMENT_OPEN_ID then return .openEquipment(GetTriggerUnit())
elseif GetItemTypeId(GetManipulatedItem()) == BACKPACK_OPEN_ID then return .openBackpack(GetTriggerUnit())
elseif GetItemTypeId(GetManipulatedItem()) == EQUIPMENT_CLOSE_ID or GetItemTypeId(GetManipulatedItem()) == BACKPACK_CLOSE_ID then if .open then return .closeEquipment(GetTriggerUnit()) elseif .bopen then return .closeBackpack(GetTriggerUnit()) endif
elseif GetItemTypeId(GetManipulatedItem()) == EQUIPMENT_PAGE_1 or GetItemTypeId(GetManipulatedItem()) == EQUIPMENT_PAGE_2 or GetItemTypeId(GetManipulatedItem()) == BACKPACK_PAGE_1 or GetItemTypeId(GetManipulatedItem()) == BACKPACK_PAGE_2 then if .open then return .changePageEquipment(GetTriggerUnit()) elseif .bopen then return .changePageBackpack(GetTriggerUnit()) endif
//Will be runned, whenever an item is dragged on another item or on an empty slot privatestaticmethod dragItem takesnothingreturnsboolean localitem manipul = GetOrderTargetItem() localinteger slot = GetIssuedOrderId() - 852002 localthistypethis = .table[GetTriggerUnit()] localitem dropped = UnitItemInSlot(.Owner, slot) localinteger id = GetItemTypeId(manipul) localinteger idd = GetItemTypeId(dropped)
if manipul != dropped and id != BACKPACK_PAGE_1 and id != BACKPACK_PAGE_2 and id != BACKPACK_CLOSE_ID and id != BACKPACK_OPEN_ID then
if idd == BACKPACK_OPEN_ID then set .dropped = false call .moveToBackpack(manipul, dropped) set .dropped = true set manipul = null set dropped = null returnfalse
elseif idd == BACKPACK_CLOSE_ID then set .dropped = false call .moveToInventory(manipul, dropped) set .dropped = true set manipul = null set dropped = null returnfalse
elseif idd == BACKPACK_PAGE_2 then set .dropped = false call .moveToSecondPage(manipul, dropped) set .dropped = true set manipul = null set dropped = null returnfalse
elseif idd == BACKPACK_PAGE_1 then set .dropped = false call .moveToFirstPage(manipul, dropped) set .dropped = true set manipul = null set dropped = null returnfalse endif endif endif
if id == BACKPACK_OPEN_ID or id == BACKPACK_CLOSE_ID or id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2 and dropped == nullthen
if id == BACKPACK_OPEN_ID andnot .bopen andnot .open then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(manipul, BACKPACK_SLOT, this) set manipul = null set dropped = null returnfalse
elseif id == BACKPACK_CLOSE_ID or id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2 and .bopen then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") if id == BACKPACK_CLOSE_ID then call addItem.create(manipul, 5, this) elseif id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2 then call addItem.create(manipul, 4, this) endif set manipul = null set dropped = null returnfalse endif endif
if(id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2)and idd == BACKPACK_CLOSE_ID and .bopen then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(manipul, 4, this) call addItem.create(dropped, 5, this) set manipul = null set dropped = null returnfalse
elseif id == BACKPACK_CLOSE_ID and(idd == BACKPACK_PAGE_1 or idd == BACKPACK_PAGE_2)and .bopen then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(manipul, 5, this) call addItem.create(dropped, 4, this) set manipul = null set dropped = null returnfalse
endif set manipul = null set dropped = null returntrue endmethod
//will be runned whenever an item is picked up privatestaticmethod pickupItem takesnothingreturnsboolean localthistypethis = .table[GetTriggerUnit()] localitem i = GetManipulatedItem() local Item it = Item.getItemById(GetItemTypeId(i))
if AUTO_EQUIP and it.equippable and .isSlotEmpty(it.slot)and .checkHero(it, false)and .allowauto then callthistype.equipItem(GetTriggerUnit(), GetManipulatedItem(), it) set i = null returntrue endif
returnfalse endmethod
//Will be runned whenever an item is dropped privatestaticmethod dropItem takesnothingreturnsboolean localthistypethis = .table[GetTriggerUnit()] localitem ite = GetManipulatedItem() localinteger id = GetItemTypeId(ite) ifthis == 0 or ite == null or not .dropped then returnfalse
elseifthis != 0and ite != nulland .dropped then
if id == BACKPACK_OPEN_ID andnot .bopen andnot .open then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(ite, BACKPACK_SLOT, this) set ite = null returntrue
elseif id == BACKPACK_CLOSE_ID or id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2 and(.bopen or .open)then
if id == BACKPACK_CLOSE_ID then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(ite, 5, this) set ite = null returntrue
elseif id == BACKPACK_PAGE_1 or id == BACKPACK_PAGE_2 then call SimError(GetOwningPlayer(.Owner), "Cannot drop this item.") call addItem.create(ite, 4, this) set ite = null returntrue endif endif endif returnfalse endmethod
//initialization of the Inventory struct privatestaticmethodonInittakesnothingreturnsnothing call TriggerAddCondition(.Use, Condition(functionthistype.useItem)) call TriggerAddCondition(.Pickup, Condition(functionthistype.pickupItem)) call TriggerAddCondition(.Drag, Condition(functionthistype.dragItem)) call TriggerAddCondition(.Drop, Condition(functionthistype.dropItem))
set .table = HandleTable.create() call SETUP_DUMMY_ITEMS() endmethod
endstruct
endlibrary
Item List Code
library ItemList
globals //If true, item abilitys will be preloaded on map init, when adding one to the systen (longer laod time, but no laggs if first time used/equipped) privateconstantboolean PRELOAD_ABILITYS = false //The unit for preloading item abilitys privateconstantinteger PRELOAD_DUMMY_ID = 'hpea' endglobals
//The struct for each item, you have registred struct Item integer Life = 0 integer Mana = 0 integer Str = 0 integer Agi = 0 integer Int = 0 integer Dmg = 0 integer Armor = 0 integer Level = 1 integer HpReg = 0 integer MpReg = 0 integer As = 0 integer Abil = 0 real Ms = 0. string Effect = "" string EffectAttach = ""
//Use this method to register an Item, which IS equippable to the system //Example: call Item.addEquipment('I000', 2, "Bloogmages", "Cloth Armors") //This would register the item as a weapon (see above), which ItemTypeId is 'I000' to the system //has the ItemClass "Cloth Armors" and is only equippable by "Bloodmages" staticmethod addEquipment takesinteger ItemId, integer Slot, string availableHeroClasses, string itemClass returnsthistype localthistypethis = 0 if .allowAdd then setthis = .allocate() set .ItemId = ItemId set .Slot = Slot set .HeroClasses = availableHeroClasses set .ItemClass = itemClass set .id = .id + 1 set .table[.ItemId] = this returnthis debugelse call BJDebugMsg("Can only register Items in Map Initialization") endif return0 endmethod
//Use this method to register an Item, which IS NOT equippable to the system //Example: call Item.addNormalItem('I001', true, 6) //This would register the item, which ItemTypeId is 'I001' to the system, enables Stacks for it and sets its MaxStacks to 6 staticmethod addNormalItem takesinteger ItemId, boolean AllowStacks, integer MaxStacks returnsthistype localthistypethis = 0 if .allowAdd then setthis = .allocate() set .ItemId = ItemId set .Equipment = false set .MaxStacks = MaxStacks set .id = .id + 1 set .table[.ItemId] = this returnthis debugelse call BJDebugMsg("Can only register Items in Map Initialization") endif return0 endmethod
//call this method after adding an ability to an item. If you set the boolean "inSpellbook" to true, //the system disables the spellbook for every player (not the ability in it!) method HasAbility takesboolean inSpellbook returnsnothing localinteger i = 0 if PRELOAD_ABILITYS then call UnitAddAbility(.dummy, .Abil) call UnitRemoveAbility(.dummy, .Abil) endif if inSpellbook then loop call SetPlayerAbilityAvailable(Player(i), .Abil, false) set i = i + 1 exitwhen i >= bj_MAX_PLAYER_SLOTS endloop endif endmethod
//use this to get the slot of the item. Returns -1 if the item isn't equipable methodoperator slot takesnothingreturnsinteger if .Equipment then return .Slot else return -1 endif return -1 endmethod
//returns true, if item is equippable methodoperator equippable takesnothingreturnsboolean//INLINE FRIENDLY return .Equipment endmethod
//Returns the item Id of the used Item //Can be used for Save & Load Systems methodoperator itemId takesnothingreturnsinteger//INLINE FRIENDLY return .ItemId endmethod
//Returns the MaxCharges of an item methodoperator maxCharges takesnothingreturnsinteger//INLINE FRIENDLY return .MaxStacks endmethod
//Returns the Item struct by using its index staticmethod getItemByIndex takesinteger Id returns Item //INLINE FRIENDLY return Item(Id) endmethod
//Returns the Item Struct by the item Type Id staticmethod getItemById takesinteger ItemId returns Item //INLINE FRIENDLY return Item(.table[ItemId]) endmethod
//Disables the registring after map Initialization privatestaticmethod disableAdd takesnothingreturnsboolean set .allowAdd = false call DestroyTrigger(.Disabler) if PRELOAD_ABILITYS then call KillUnit(.dummy) endif return .allowAdd endmethod
//self-explanatory privatestaticmethodonInittakesnothingreturnsnothing if PRELOAD_ABILITYS then set .dummy = CreateUnit(Player(15), PRELOAD_DUMMY_ID, 0., 0., 0.) endif call TriggerRegisterTimerEvent(.Disabler, 0., false) call TriggerAddCondition(.Disabler, Condition(function Item.disableAdd)) set .table = Table.create() endmethod
endstruct
endlibrary
Please give credits to the above named mapper, if you use this system and to me :D
Rating - 5.00 (2 votes)
(Hover and click)
Moderator Comments
Recommended
14:46, 8th Oct 2009
The_Reborn_Devil:
The code looks very nice and I couldn't find a leak.
This is definitely useful for someone. Approved.
I give this system the rating Recommended.
well its works good, but u cant give items active abilitys :/
i dont know how u could implement that, but if you would find some way, that would be nice
@Godslayer:
I really don't know, how i could add active abilitys to items...
@xxdingo93xx:
Yeah, i made this for my RPG and liked the AAA Inventory, but this is very old and not 1.24 compatible, so I made it by my own ;)
@Deuterium:
Will post the Code of the required System Librarys (Inventory System and Item List) soon.
Edit:
Will upload the code, after I added a small feature, which allows the user to setup, if an picked item will be auto eqipped, if the slot for the item is empty-
Hell, I checked the code, and I liked it.
Although, I was making nearly the same system.
But mine works as following:
I used hashtables.
And also mine is able to use the bonus systems,
but unlike yours, its not an requirement.
Mine also allows automaticly pickup and drop events
which refresh the inventory. And you can have items
in your inventory which are not shown. Unlike yours.
And, mine is limited to the 6 slot inventory yet, but its no problem
you can do a workaround...
So in all:
Yours is more advanced getting to the UnitMaxMod and such,
because mine does not require them. But with mine you can
also stack items, combine them and make many more thing.
I would look forward seeing a system without the pages but with
the bonus mod.
Of course you could add stackable items an so on, but i think for an equippment system, that isn't needed^^
At the beginning, I also wanted to use a hashtable for the items but structs are quite faster ;)
But what do you mean with "Mine also allows automaticly pickup and drop events
which refresh the inventory"
In Version 1.02, the inventory can auto-equip items, if their slot is empty. Maybe I'll add the feature, that you can drop the items directly from your inventory on the ground, will look, how i could do that...
But why do you want invisible equipped items? Don't see any feature of it.
And i wanted to have the system as simple as possible to create new Items and ingame, I think thats, what it is or?^^
Of course you could add stackable items and so on, but i think for an equippment system, that isn't needed^^
Ok, I have an collection, you only a single system.
Quote:
At the beginning, I also wanted to use a hashtable for the items but structs are quite faster ;)
Sure, but hashtables are easier to use.
Quote:
But what do you mean with "Mine also allows automaticly pickup and drop events which refresh the inventory"
Normally, when you drop items with my system, it applies effects of the itemtype to the hero and while being dropped, they get removed. The item will also instantly be added to the inventory object of the unit. (Which is also automaticly created if you want)
Quote:
In Version 1.02, the inventory can auto-equip items, if their slot is empty. Maybe I'll add the feature, that you can drop the items directly from your inventory on the ground, will look, how i could do that...
Yeah, something like that.
Quote:
But why do you want invisible equipped items? Don't see any feature of it.
You could add a window to manage your inventory items and don't have to use the damn 6 slot inventory for gods sake.
Quote:
And i wanted to have the system as simple as possible to create new Items and ingame, I think thats, what it is or?^^
My system would be even easier, since you don't even need to call anything ingame if you don't want to, and it would handle the items nonetheless.
Hmmm
I like using structs more like hashtables, because in my opinion, they are very simple to use ;)
And I wanna add a small bagpack system to the Inventory, giving the hero 8 more slots (also with pages^^). That would use Drag and Drop, will look how I'll do that best...
In my tests, it is a little bit faster.
And I'll explain the Stack System a little bit more exactly:
When you give your unit an order to pickup an item, the system will detect that, and just orders the unit to move to the item. When the distance between caster and item is smaller then a constant value, the item will be added on this way:
1. Check, if the item is equippable, autopick if enabled, its equipment slot is empty and the unit can wear the item: Equip it.
2. If 1 isn't true, the sytem will checks, if the unit has any type of this item in its inventory and backpack. The start of the serach depends on the current opened "inventory". If an item of this type was found, it will be stacked with it, if its stack + the item's stack is smaller than MAX_STACK_SIZE and the item's stack size.
3. If 2 isn't true, the system will search for the first free slot, where this item can be stored, also depending on the current opened inventory. So if I have opened page 2, it will first serach for the backpack page 2, then the normal inventory and at last, the first backpack page.
4. If 4 also not true, you become an error, that you inventory and backpack is full :)
And maybe, I'll change the way of equipping an item to drag and drop... maybe...^^
Very nice inventory system i tested it over and over all items equip correctly, you can only have 1 item of each type, and items in your normal inventory do not increase your stats
Edit:
Can't update today, because of a big bug..
Will udate it tomorrow i think...
Edit2:
The bug is fixed, the code is nearly done. Just want to add the possibility to equip items with opened equipment menu :D
Btw, the code has atm exactly 1337 Lines of code^^
Edit3:
It's nearly done. Iv'e just added a small feature to allow to equip items with opened equipment menu page.