If I was going to make a simple item system, this is how I would structure it:
- I would have one database table to store item information (call it ITEMS_INFO) with columns such as:
UID, NAME, TYPE, DESCRIPTION, GANI, REAL_NAME, ...
This table would have one row for every item on your server.
- I would have another table to store player possessions (call it PLAYER_ITEMS) with the columns:
ACCOUNT, ITEMSINFO_UID, QUANTITY
- I would also maintain a cache of each player's item info in clientr.vars. I would update the entire cache on login, and also individual items as they are bought/sold/dropped/whatever.
A simple way to load all of a player's items in a single query (such as when they login) would look something like:
NPC Code:
select PLAYER_ITEMS.QUANTITY, ITEMS_INFO.* from PLAYER_ITEMS
left join ITEMS_INFO on PLAYER_ITEMS.ITEMSINFO_UID = ITEMS_INFO.UID
where PLAYER_ITEMS.ACCOUNT = 'salesman'
You could then loop through the result of this query to update the player's
clientr.var cache. If a player has 600 items, you'd only have a single SQLite query and a loop that iterates 600 times when they log on.
There's also really no need to cache the SQLite databases in DBNPCs. From my personal experience, it is much faster to just stick with SQLite.
You shouldn't have an issue with too many clientr.vars (Era does something similar). Just remember to only store information that you will actually use...such as the information that will be displayed in an inventory or on the player's HUD.