TriggerHappy
...
- Reaction score
- 341
Bag System
This is a little system I made that stores items, inside an item, also known as a bag.
I made this bag system because I have only really seen extended inventorys to heroes.
This system stores all the items into a bag, so if you drop that bag, and someone else picks it up, the items will still remain in the bag.
Features
Code!
It's pretty simple, i'm sure theres a flaw in it, so comments and suggestions welcome!
For all you gui'ers, don't be afraid, try the demo map and you will see how easy it is to use.
This is a little system I made that stores items, inside an item, also known as a bag.
I made this bag system because I have only really seen extended inventorys to heroes.
This system stores all the items into a bag, so if you drop that bag, and someone else picks it up, the items will still remain in the bag.
Features
- MUI (or MII, Multi Item instancability )
- Stores items depending on the bag, not the hero.
- Stores the items UserData (Custom Value).
- Simple Usage, by only calling one function.
- You can store bags, inside bags!
- Saves the items position in the inventory.
- Stores item charges!
Code!
It's pretty simple, i'm sure theres a flaw in it, so comments and suggestions welcome!
JASS:
//***************************************************************************
//*
//* Bag System - By TriggerHappy187
//*
//***************************************************************************
//*
//* Installation
//* Simply copy the BagSys trigger into your map.
//* You can optionally copy the demo triggers, if they suite you.
//* This system also requires JassHelper (included with JNGP)
//* Also, copy the CloseBag and Bag items into your map, and edit the BagSys globals to fit the raw ID
//***************************************************************************
//*
//* Documentation
//* This is a little system I made that stores items, inside an item, also known as a bag.
//*
//* made this bag system because I have only really seen extended inventorys to heroes.
//*
//* This system stores all the items into a bag, so if you drop that bag, and someone else picks it up,
//* the items will still remain in the bag.
//*
//***************************************************************************
//*
//* The Functions
//* They are self explanitory in my opinion.
//*
//* OpenBag opens the bag for the current person holding it.
//*
//* CloseBag closes the currently open bag for the owner
//*
//***************************************************************************
library BagSys
globals
private constant integer BAG = 039;I000039;
private constant integer CLOSE_BAG = 039;I001039;
endglobals
private struct bag
integer array items[7]
integer array UserData[7]
integer array bagitems[7]
integer array Charges[7]
boolean isOpen = false
static method create takes item whichBag returns bag
local bag b = bag.allocate()
call SetItemUserData(whichBag, b)
return b
endmethod
endstruct
function CloseBag takes unit owner, item whichBag returns boolean
local bag b = GetItemUserData(whichBag)
local integer i = 0
local item itm
if b.isOpen == false then
debug call BJDebugMsg(GetItemName(whichBag) + " is not open!")
return false
endif
set b.isOpen = false
call RemoveItem(UnitItemInSlot(owner, 5))
loop
exitwhen i == 7
set b.bagitems<i> = GetItemTypeId(UnitItemInSlot(owner, i))
set itm = CreateItem(b.items<i>, 0, 0)
call SetItemUserData(itm, b.UserData<i>)
call SetItemCharges(itm, b.Charges<i>)
set b.UserData<i> = GetItemUserData(UnitItemInSlot(owner, i))
set b.Charges<i> = GetItemCharges(UnitItemInSlot(owner, i))
call RemoveItem(UnitItemInSlot(owner, i))
call UnitAddItem(owner, itm)
call UnitDropItemSlot(owner, itm, i)
set i = i + 1
endloop
set itm = null
return true
endfunction
function OpenBag takes unit owner, item whichBag returns boolean
local bag b = GetItemUserData(whichBag)
local integer i = 0
local item itm
if b.isOpen == true then
debug call BJDebugMsg(GetItemName(whichBag) + " is already open!")
return false
elseif GetItemTypeId(UnitItemInSlot(owner, 5)) == CLOSE_BAG then
debug call BJDebugMsg("You cannot open two bags at once")
return false
endif
loop
exitwhen i == 6
set b.items<i> = GetItemTypeId(UnitItemInSlot(owner, i))
set itm = CreateItem(b.bagitems<i>, 0, 0)
call SetItemUserData(itm, b.UserData<i>)
call SetItemCharges(itm, b.Charges<i>)
set b.UserData<i> = GetItemUserData(UnitItemInSlot(owner, i))
set b.Charges<i> = GetItemCharges(UnitItemInSlot(owner, i))
call RemoveItem(UnitItemInSlot(owner, i))
call UnitAddItem(owner, itm)
call UnitDropItemSlot(owner, itm, i)
set i = i + 1
endloop
set b.isOpen = true
set itm = CreateItem(CLOSE_BAG, 0, 0)
call SetItemUserData(itm, b)
call UnitAddItem(owner, itm)
call UnitDropItemSlot(owner, itm, 5)
set itm = null
return true
endfunction
function ToggleBag takes unit owner, item whichBag returns nothing
if bag(GetItemUserData(whichBag)).isOpen == true then
call CloseBag(owner, whichBag)
else
call OpenBag(owner, whichBag)
endif
endfunction
function CreateBag takes item whichBag returns nothing
call bag.create(whichBag)
endfunction
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i>
For all you gui'ers, don't be afraid, try the demo map and you will see how easy it is to use.