This implements the following mechanic:
First create a text file to write down your item properties. File Name, extension and path can be anything as long as the file structure is a proper table.
For this example, we will use this path: scripts/maps/item_info.kv
To load a table into your game mode, you need to use the `LoadKeyValues( "path/to/file" ) lua function. This can be called at GameMode:InitGameMode() inside your main lua addon. GameMode = self
If your table is badly formed (e.g. you missed a quotation mark or a bracket), this will fail and you'll get a lua console error when starting the game.
Note how I didn't add a "classRequired" to the 2nd item. When trying to access the
GameMode.ItemInfoKV[itemNane].classRequired value will be nil, meaning there is no restriction on class (but still checks the level)
There are many ways to set a class, the most basic one is indexing
.class in the hero handle the first time the hero is in game (using the barebones.lua default calls)
Add this datadriven event on every item that needs to do a check for restrictions. It calls a lua script to do the logic check against the table.
This is needed because the listener for inventory changed is broken, and the Lua
OnItemPickedUp event hook doesn't account for someone dragging an item into another players inventory.
In this example, I'll look for Level and Class requirements
Make use of the CustomError Flash UI by zedor to display a red error message when the item doesn't met any criteria found in the table.
There are some
Leave your questions or suggestions below.