Skip to content

How to store item info?

I'm working on setting up my character for equipping weapons and armor, as well as his inventory slots. My question is, what is the best way to store all that info regarding each item?

For example: a sword would have Name, Attack, Attack%, Magic, Buy Cost, Sell Amount as its basic data.

So if you consider the large amount of all weapons and armor and items in a game, I can't imagine it would be wise to create large arrays of each item type and try referencing them whenever I need to?

Would it be better to store this info in an xml file, and create objects from the data only when needed? And if so, how do I protect that data in the xml file so players can't access it and make a weapon do a million damage or be worth 10 million gold. Is there a way to encrypt it?

1 points6 comments
Open on Reddit
About this post
Posted
Archived
Score
1 · 67% up
Kind
Text
ID
ph5v91

Author

41
posts
37
comments
7
media
View profile

6 comments

If you're making a multi-player game, then your server would handle the creation of those items. There are many ways to create items and info you're talking about, most of it is personal preference and depends on your engine.

You can store that in a database that only the server has access to. To prevent clients from trying to cheat you would just use the server values of the weapon. The server would be the absolute authority.

1 points

Not multiplayer.

1 points

Then you can't stop that. If people want to cheat, they'll find a way. You can never trust a client's data.

2 points

As /u/dj-riff said there is no way to stop player from cheating. But you can just make it harder so not every player with Notepad will be able to do that. And the only option is to avoid saving plain text.

There are some options for that:

  1. AES encryption. There are a lot of libraries with implementation of this algorithm. You're just storing a key in some another place (global variable, another file, etc.) and use it to decrypt/encrypt your text data. So after encryption you will get just binary data that you can save to file. So in this case the hardest part for a cheater will be searching for the key to decrypt it.
  2. Just compress it! Of course if you will use ZIP, players will able to just open this zip file and change whatever they want. But you can use less popular compression algorithms which are not supported by default Windows File Explorer. Snappy for example. (or just compress with ZIP and put at the beginning of the file some garbage (like a couple of bytes) so it will not be valid for some ZIP explorer).
  3. Use binary format. Instead of XML or JSON (which are text based) you can choose other format to store your data. In my company we're using protobuf. Which is designed for server-to-server communication but can be used to storing data too. There is also BSON which is just a binary version of JSON (used by MongoDB). You can easily google other binary formats.
  4. Pack this data with something else. You can insert this data in your executable for example. If I'm not mistaken you can use .data segment for that. Maybe... Or to any other existing file.

And of course you can combine those options. Like encrypting data and inserting it into your executable. Or compressing your data and encrypting it. And so on... But remember that these are just ways to make it harder.

1 points

Data segment

In computing, a data segment (often denoted . data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this segment is determined by the size of the values in the program's source code, and does not change at run time. The data segment is read/write, since the values of variables can be altered at run time.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.