YaBackpackComponent¶
YaBackpackComponent manages the backpack and items to be put in or moved out of the backpack.
Note: YaBackpackComponent is attached to a player entity by default, rather than a character entity.Functions¶
Array<YaBackpackStacks> GetAll()¶
Returnsitems Info
Gets the information of all the items in the backpack.
number GetCapacity()¶
Returnsthe capacity
Gets the capacity of the backpack.
number GetCount(number itemID)¶
Returnsthe count
Returns the total number of the items in the backpack by itemId.
- itemIDthe item id
number Addable(number itemID, number count)¶
Returnscould be added to the backpack's count
Whether the item could be add to the backpack.
- itemIDitemId
- countadd count
void Sort()¶
Sort the backpack.
void Clear()¶
Clear the backpack.
boolean Replace(number fromIndex, number toIndex)¶
SERVER ONLY 
Returnstrue if success
Exchange the position of the two item in backpack.
- fromIndexfrom
- toIndexto
void Add(number itemID, number count)¶
SERVER ONLY 
Add item to backpack.
- itemIDitemId
- countcount
void Add(number itemID, number entityId, number count)¶
SERVER ONLY DEPRECATED 
Obsoleted,use Add(int itemID, int count) instead.
- itemIDitemId
- entityIditem's entityId
- countitem count
void Remove(number index, number count)¶
SERVER ONLY 
Remove an item from backpack.
- indexthe index in backpack
- countcount
void RemoveByItemId(number itemID, number count, number fromIndex)¶
SERVER ONLY 
Remove item from backpack by itemId.
- itemIDitemId
- countcount
- fromIndexstart position in backpack
void Enable()¶
SERVER ONLY 
Enable backpack.
void Disable()¶
SERVER ONLY 
Disable backpack.
Events¶
ChangedEvent<void>¶
Fired when the backpack's data changed.
ItemAddedEvent<BackpackItemChange>¶
Fired when an item is added.
- ChangeInfoThe added item info.
| 1 2 3 4 5 6 7 8 9 10 11 12 |  | 
ItemRemovedEvent<BackpackItemChange>¶
Fired when an item is removed.
- ChangeInfoThe removed item info.
| 1 2 3 4 5 6 7 8 9 10 11 12 |  | 
Code sample¶
Code sample
| 1 2 3 4 5 6 7 8 9 10 11 12 |  |