SimpleInventory Plugin

1 favourites
  • 1 posts
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • Introduction

    Download it free: https://lusobytes.itch.io/simpleinventory

    Construct is very flexible but I found it tedious to create and dificult to maintain a working inventory using just dictionaries and arrays - so I created this plugin just for that.

    The plugin handles all inventory management, like sorting, item equipping, getting the sum of all DEF for a specific hero, etc.

    You just need to worry about the UI!

    See a working demo that you can download here: https://www.construct.net/en/free-online-games/lusobytes-simple-inventory-23282/play

    How it works

    Define your items in a JSON file. Then you initiate the plugin with said file.

    Add items via plugin call - use the id defined on the json file.

    Core concepts

    Stacked Inventory - Holds a quantity of a specific item defined on the json file. You can stack them.

    Global inventory - Holds unique items (equipments). They don't stack. Can have multiples and they can be equipped.

    Why a global and a stacked inventory? I wanted to add the possiblity of creating rarities or forging without defining all of it on the json - having an equip be a unique instance allows this separation (see games like NiNuKuni, knights of ages, etc.)

    I might support stacking equipments in the future if there is a demand.

    Main Actions

    AddItem(id) - id is defined on the json file. Adds a unique unique item with starting properties defined on the json.

    AddStackedItem(id, quantity) - Id is defined on json. Adds a specific quantity to the stacked inventory. You also decrease quantity with this method - use a negative quantity.

    How to list inventory and sort

    Load Global or Stacked inventories into a C3 array or a PRO UI list, via expressions.

    All Lists functions need to be wrapped by the conversion functions, either:

    ToC2jsonarray > converts the list into a C3 compatible JSON ( that grows on Y axis, so iterate XY)

    ToProUI > converts the list into a ProUI compatible JSON.

    SimpleInventory.ListStackedItems(category, orderproperty) - Gets the stacked inventory Id and quantities as a JSON.

    SimpleInventory.Listinventorybycategory(category, orderproperty) - Gets the global inventory IDs in a list.

    "category" only returns items of a given category. Leave empty to return all.

    "orderproperty" order the list by a specific item property (ex: "hp" or "price"). Empty defaults to "id" property.

    Display specific Item information

    The inventory lists return the item IDs, so when you are processing the array created by the lists, the value the item ID on the inventory - that you see on the debugger. With that ID, you can access the item properties via the expressions:

    getstackeditemproperty(stackedID,prop)

    getitemproperty(globalinventoryID,prop)

    Equipping Items

    *Documentation TODO - see demo for now*

    Modifying specific items

    You can change whatever unique item property you want via the action "setitemproperty(itemref, prop, value)".

    Breaking down the example above:

    Itemref - SimpleInventory.Getlastaddeditem ( returns the id of the last unique item added to the inventory)

    "prop" - atk the property to be changed

    value - int(SimpleInventory.Getitemproperty(SimpleInventory.Getlastaddeditem, "atk")) + 5

    SimpleInventory.Getitemproperty(id, prop) returns the item property, in this case atk.

    Then we add + 5 to that value.

    That way we increase the base item atk to + 5.

    JSON File

    The json file needs to have an array named "items" in the root. All items must be defined under it.

    All items defined need to have atleast these keys:

    "id", "name", "category", "equipped"

    "equipped" must be -1 or it wont work

    Ex:

    { "id": 101, "name":"Worn Buckler", "description": "Worn Buckler", "icon":6, "category": "shield", "equipped" : -1 }/ic] --

    Extra Credits

    - piranha305 for the amazing C3IDE.

    - Dop2000 for allowing me to use his scrolling list demo as a base for this plugin demo (https://www.construct.net/out?u=https%3a%2f%2fhowtoconstructdemos.com%2fscrolling-a-list-of-players-scores-images-etc-example-a-capx%2f )

    -----

    Hope this can be of use!

    Any bugs, doubts or sugestions let me know in the comments.

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)