inventory system
#1

Hello, I want to make an inventory system but I dont know how should I save it. I am going to use y_ini and I think I can use strings to save it. Is it logical to do it like this?;

Код:
"{13,2},{24,5},{12,7}"
{} represents an item table. first thing in this table is item id, second thing is item quantity. I will define item ids one by one. when you try to add an item to player, it will check this string and if item id exists, it will add 1 to specified item table's second argument. if item id doesn't exists then it will add new item table with 1 quantity. it goes same way with removing items.

I made this logic but I dont know how to do it in pawn. should I use sscanf for strings or what?

Also, would it be efficient to get whole string every time to add new item?
Reply
#2

The ini file format is very, very bad at storing lists of thing, because it was simply not designed for that. If you must use files, try an XML or JSON parser instead.
Reply
#3

XML is also not that fast, JSON would be the greatest idea, however I've had some problems using SA-MP Json plugins. You can also think about SQLite, it's natively supported and not that bad.
Reply
#4

Quote:
Originally Posted by kubak01
Посмотреть сообщение
XML is also not that fast, JSON would be the greatest idea, however I've had some problems using SA-MP Json plugins. You can also think about SQLite, it's natively supported and not that bad.
why not use MySQL?
Reply
#5

The best choice would be SQL. Easy to work along with a lot of possibilities.
Reply
#6

You can save the inventory info as follows:
12,9,2,0,2,8 - item_id,quantity,item_id,quantity,item_id,quantity

then use SSCANF to store it accordingly in an array (with an enumerator tied to it or not).

It doesn't bother me when I see people using INI files, but with the existence of SQL everyone should be using it instead (it would be better in the long run, especially if you're going to use the script on a production server).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)