adding_a_new_item_to_the_game

ADDING A NEW ITEM TO THE GAME

Items are one of the key concepts of the game. They are used for many things, including crafting. Via modding is possible to add new items to the game, put them for sale in a shop or put them in a spawner. In this guide we will create a new ClothingItem, we will call it the “Modder Shirt”. Then we will put it in a shop for sale. Creating a new ClothingItem will make it available also to npcs, sso people dressed in the new clothes will appear randomly in the game. If we wanted to make a special clothing, not available to npcs, we should create a SpecialClothings item instead. Item Categories are a very important concept in Hard Times modding. Each category represents a kind of items with special uses and functions. Here are the actual item categories implemented in the game:

  • BaseItem: This items are basic items without a definite use by themselves.. Are mostly base materials involved in crafting.
  • BookItem: Books are needed to unlock crafting recipes. Each book covers a definite realm so for examples there are books about cooking, about fishing and so on. Using a book reads it. Books already known will appear in the book panel (key C) and will appear with their name in green when in inventories.
  • BoxedFurnituresItem: This items represent boxed versions of placeable furnitures. Using them will place the furniture on the ground.
  • CleaningItem:This items are used to affect the hygiene stat. For example wet tissues used to wash yourself.
  • ClothingItem:This items represent clothing. Use them to wear it.
  • ContainerItem:This items are containers, in the sense that they own a inventory in which you can store other items.
  • CorpseItem: Represent dead pets.
  • DrugItem:Items which, when used, have a physical effect on the character. For example cigarettes and joints.
  • FishItem: Items representing fishes.
  • FoodItem: Items representing edible food.
  • HatItem: Hats, that are treated like clothing.
  • HintGiver: For example the fortune cookies. Are items that display a message when used.
  • MedicItem:Are items used to regain health, such as bandage and medikits.
  • RecordItem: Records are made of a collection of songs in ogg format. The have also a description and a link to the band’s website.
  • SeedItem: Seeds are used for cultivation, to grow crops. They must be used with water in a growing plot. Use fertilizers for improved effects.
  • SpecialClothing: Are like normal clothings, but in this category you will find special and non sellable clothings, like uniforms and so on.
  • SpecialItem: Like baseitem but containing unique and no sellable items.
  • WalletItem: A kind of items that converts to money when used.

To items in game we should add a proper folder for all our items categories and sprites. So the first step is to create a proper Items folder under our mod package:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items

This folder will contain all the items defined in this mod. Another thing to do is adding the items folder to the mod descriptor, to let it know there are items to be loaded in this mod.
We will have to create also a Lang folder, since our item will need lang files for names and descriptions.

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Lang

This folder will contain all the lang entries for everything we will define in this mod. So now let's go back to our mod descriptor file in:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Descriptor.json

and let's add the items folder and the lang folder properties to let the game know we are adding such entities.

{
  "modName": "MyMod_MODPKG",
  "author": "RadicalFiction",
  "gameVersion": "",
  "langFolder": "Lang",
  "itemsFolder": "Items"
}


Now that we have prepared everything we will proceed to create the folder structure for our new item, since it will be a ClothingItem type of item we will add the following folder:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items\ClothingItem

Inside it we will create a Sprites directory to hold all our category items sprites:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items\ClothingItem\Sprites

Now we will create the ClothingItem.json file:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items\ClothingItem\ClothingItem.json

It will contain the descriptions of all the items of this category we will define in this mod.

{
  "archetipusName": "baseItemArchetipus",
  "category": "ClothingItem",
  "items": [
    
  ]
}

Now we have an empty item category file referring to the ClothingItem category. We will put in it a new ClothingItem to use in the game.

Firt thing we will need a sprite for our new clothing piece. It must conform to the items sprite requirements for being used in Hard Times. It must be a transparent background png file of exactly 64x64px. In it the clothing must cover the center to be properly aligned to the in game sprites. I suggest you use an existing clothing item as a guide in a lower layer when you create a new clothing. You could even edit an existing one to be sure to get the perfect size and position. Practice makes perfect and a good template makes swift. For now I prepared this simple sprite for us to use in this guide: Just right click on it and choose “save image as” to save it in:

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items\ClothingItem\Sprites\modder_shirt.png

And you're done with the sprite of your new ClothingItem.

Now let's edit again our ClothingItem.json file in

C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Items\ClothingItem\ClothingItem.json

We will add a new entry in the items array, so edit the file like this:

{
  "archetipusName": "baseItemArchetipus",
  "category": "ClothingItem",
  "items": [
	{
	  "itemRootPath": "",
	  "itemId": "Modder Shirt",
	  "itemSpriteName": "modder_shirt.png",
	  "itemProxySprite": "",
	  "itemEffectOnUse": "clothing_temperature_effect",
	  "itemExpiration": 262800,
	  "maxStackable": 1,
	  "effectModifiers": [
		{
		  "statId": "playerTemperature",
		  "statModifier": 5
		},
		 {
		  "statId": "rainProtection",
		  "statModifier": 0
		}
	  ]
	}
  ]
}

Let's now look at the relevant properties of this object:

"itemId": "Modder Shirt",

This is the Unique Id of the item. It must be unique through the game, otherwise you could overwrite other items! You could use a simple prefix to be sure to have a unique id, something like “modname_” with the name of the current mod.

"itemSpriteName": "modder_shirt.png",

It's just referencing the name of the sprite it will look for in the Sprites folder of the item category.

"itemEffectOnUse": "clothing_temperature_effect",

This property references the effect to activate when you use the object.

"itemExpiration": 262800,

This is the expiration time in minutes game time of the item.

"maxStackable": 1,

With this value you control how many of this items can be stacked in a single inventory slot.

"effectModifiers": [
{
  "statId": "playerTemperature",
  "statModifier": 5
},
 {
  "statId": "rainProtection",
  "statModifier": 0
}
]

This refers to the “clothing_temperature_effect” effect activated on use. In ClothingItem items the itemEffectOnUse is activated on dressing and deactivated on undressing. The modifiers just tell the game to use those values instead of those provided with the base effect description. In this case “playerTemperature” is set to 5 meaning that the clothing givees you a +5 bonus on your perceived temperature. “rainProtection” is set to 0 meaning that this item doesent protect you from rain. Please refer to the Player Effects Modding Reference for more detailed infos on modding Player effects. Also refer to ClothingItem Modding Reference for more detailed infos on modding Clothing Items.

Once we have our item in the game we have to set the lang entries for it, including item name and description. Since we set the item id to “Modder Shirt” it will make sense in english even if we didn't provide a lang entry for it. However, in this case, in other languages the text will always look the same. Moreover we will have no description for the item. So let's create appropriate lang entries for the item you have just created. Go create a file in:

  C:\Users\{YOUR USERNAME}\AppData\LocalLow\RadicalFiction\HARDTIMES\Mods\MyMod_MODPKG\Lang\English\ClothingItems.json

Please note that in lang files the filename is uninfluent to the system. All keys are loaded in the same level.
Insert the appropriate lang entries so that the file will look like this:

{
  "items": [
    {
      "key": "Modder Shirt",
      "value": "Modder Shirt"
    },
    {
      "key": "Modder Shirt-DESCRIPTION",
      "value": "This is an awesome modder shirt created with the Hard Times wiki guides."
    }
  ]
}

The first item says that the id of the item will be translated to the correct name when displayed. The game will also look automatically for a key formed with the itemId plus “-DESCRIPTION” as a postfix for the description of the item.

If everything went well you should now be able to start again the game with no errors(!). Be sure you have your new mod active and start a new game.
The problem is that you will have to wander the streets waiting for a random stranger to pass by wearing your new item (like I did). Or you should be able to hack the game into spawning you random stuff, like I do.

So in the next modding guide we will learn how to quickly add your new item to a shop. Then in a next guide we will create a special spawner to spawn our clothings.

If you have problems or find errors in this guide please get in touch at info@tempi-duri.net.

You could leave a comment if you were logged in.
  • adding_a_new_item_to_the_game.txt
  • Last modified: 2019/02/09 07:35
  • by thorfinio