Skip to main content
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

You can see kind of an example of what the entity files look like herehere.

You can see kind of an example of what the entity files look like here.

You can see kind of an example of what the entity files look like here.

Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

Yes, storing the items in external files is a good idea. I created something very close to what you're talking about. It's an item/entity lexicon. Items, materials and entities are all stored in this "database". The script files get read on load and store every item available in game.

You can see kind of an example of what the entity files look like here.

The format of the script is up to you. You may want to use XML or some other common script, or you can make your own like I did or what it looks like you've started to do.

When the items are read in, they go into an item blueprint class. This class has all the required information for generating a new item. It also allows each item some variation. As you can see in my other answer, I define ranges of acceptable values. When the item is created it will choose a random value from within the range defined, giving each item a slightly different quality/value/whatever.

All those blueprints are stored in a HashMap, a Dictionary for C#. The ID is the key and the value is the blueprint. I also have the keys in a HashMap that's referenced by the item name. This makes it easier for me if I want to create a specific item, and I don't remember the name. For example I have an apple defined:

MATERIAL:"Apple" {
        description="An apple, a tasty fruit"
        commonName="Apple"
        pluralCommonName="Apples"
        tags=Fruit,Edible
        basetype=CulinaryFruit
        qualityrange=0.2:1.0
        itemtextureindex=10
        value=15
        density=20.0
        entityBaseAttributes="Small Physics Item","Slow Decay"
        
        HarvestItems{
                HarvestItem{
                        material="Apple seed"
                        TimeToCollect=200:500
                        WeightedChance=1
                        MinConditionToProduce=0.3
                        OverrideQuality=1.0:1.0
                }
                HarvestItem{
                        material="Apple core"
                        TimeToCollect=200:500
                        WeightedChance=1
                        MinConditionToProduce=0.3
                }
        }
}

Where Apple seed and Apple core are also items defined in the script. So if I want to create an apple somewhere, I have a method that takes the information above and generates the properties of an entity. Including some predefined standards like "Small Physics Item" and "Slow Decay" which add attributes to the entity being generated.

It's a pretty flexible system that allows me to quickly generate new items. And it's easy to use, because I don't actually even need to know the IDs of anything, I can reference them by name. I also have an entity named "Apple Tree" that has a ProduceItems attribute that generates Apple.

All in all, yes, it's a good idea to put your items in scripts. And with a little work, you can create some very complex behaviors and items with your item scripts.