Your first mod. New item - Alexofp/BDCC GitHub Wiki

So, easiest way to add an item is to create a new file inside Inventory/Items folder. The game reads that folder and registers each file automatically. So, create a file in that folder named TestItem.gd and paste this code

extends ItemBase

func _init():
	id = "TestItem"

func getVisibleName():
	return "Test item"
	
func getDescription():
	return "This is my first item in BDCC"

So this is simplest item one can make. id must be unique. How can we get this item in-game? Well, at the moment, you can't. The only way is by using the debug panel. Enable it in the game's settings, that will add a DG button inside the game ui. Press it and select the "Give player item" option. That will open a menu with a list of all the items. TestItem should show up in there.

pic

Okay. You got the item. You can look at its name and description but you can't interact with it in any way. How do we fix that? Easy. Take a look at this code.

extends ItemBase

func _init():
	id = "TestItem"

func getVisibleName():
	return "Test item"
	
func getDescription():
	return "This is my first item in BDCC"

func canUseInCombat():
	return true

func useInCombat(_attacker, _receiver):
	_attacker.addPain(-100)
	destroyMe()
	return "{attacker.name} used a test item!"

The item can now be used in combat. _attacker variable is player and _receiver is the enemy. _attacker.addPain(-100) means 100 pain will be removed from the player, essentially healing him. destroyMe() means the item will be consumed on use. And the last line shows what text will be outputted. So this is essentially a single-use healing item. If you wanna turn it into an offensive item you can change _attacker.addPain(-100) line to _receiver.addPain(100) That will make the enemy take 100 pain when you use this item, like a grenade or something.

Okay, great, we can use it in combat. But we can also make it usable outside of it with minimal changes.

extends ItemBase

func _init():
	id = "TestItem"

func getVisibleName():
	return "Test item"
	
func getDescription():
	return "This is my first item in BDCC"

func canUseInCombat():
	return true

func useInCombat(_attacker, _receiver):
	_attacker.addPain(-100)
	destroyMe()
	return "{attacker.name} used a test item!"

func getPossibleActions():
	return [
		{
			"name": "Eat it!",
			"scene": "UseItemLikeInCombatScene",
			"description": "Eat the thing",
		},
	]

We added a new function getPossibleActions(). As you can see, it returns a list of actions that we can do with this item outside of combat (there can be more than one). Each action is described by its name, description and what scene it will run. Scenes in BDCC are described in another tutorial. In this case "UseItemLikeInCombatScene" will just call useInCombat() inside of it. Since there is no enemy when we're using the item alone, the _receiver variable will be null Calling any function on a null variable will result in a crash so be careful ^^

Sooo, we can use the item in so many ways now but how can we get this item legitimately? There are a few ways.

  • Adding it through code inside scenes
  • Adding ability to buy it from vendomats
  • Adding it as loot

First two are pretty use. To add an item using code use this GM.pc.getInventory().addItem(GlobalRegistry.createItem("TestItem"))

To add ability to buy the item take a look at this code:

extends ItemBase

func _init():
	id = "TestItem"

func getVisibleName():
	return "Test item"
	
func getDescription():
	return "This is my first item in BDCC"

func canUseInCombat():
	return true

func useInCombat(_attacker, _receiver):
	_attacker.addPain(-100)
	destroyMe()
	return "{attacker.name} used a test item!"

func getPossibleActions():
	return [
		{
			"name": "Eat it!",
			"scene": "UseItemLikeInCombatScene",
			"description": "Eat the thing",
		},
	]

func getPrice():
	return 1
	
func getTags():
	return [
		ItemTag.SoldByGeneralVendomat,
		]

We added the item's price and this getTags() function. Item tags are just little hints that the game can use to use your item. ItemTag.SoldByGeneralVendomat item tag will add ability to buy this item inside the general vendomat. There are a few tags currently defined. Most interesting are

  • ItemTag.Illegal Item is illegal and will be taken away during any searches
  • ItemTag.SoldByGeneralVendomat Item is sold in the general vendomat
  • ItemTag.SoldByMedicalVendomat Item is sold in the medical vendomat
  • ItemTag.SoldByUnderwearVendomat Item is sold in the underwear vendomat

This is only the basic information about making a new item. If you wanna make something complicated such as a new BDSM restraint or new clothing you will have to look at other items and use them as examples

Turning your item into a mod

Okay, great, you have an item. Now how do we make a mod that adds this item so other people don't have to use godot editor to use it?

Firstly, you have to create a module. What's a module? It's basically just a folder where you can group all your new stuff together all neatly.

Create a new folder inside Modules Name it TestItemMod or something. Move your TestItem.gd file inside it and also create a new file named Module.gd with this:

extends Module

func _init():
	id = "TestItemMod"
	author = "Rahi"
	
	items = [
		"res://Modules/TestItemMod/TestItem.gd",
	]

Change the author variable to your nickname ^^.

As you can see, the files aren't loaded automatically anymore, you have to define them so the game knows how to load them. But if you run the game, everything should stay the same.

Great. Now we can actually package our mod. Open the game, go into devtools menu and click on a 'ModMaker'. Find the module folder that you created and add it. That should add both files into the right list, that will be the contents of your mod.

pic2

Now press the 'Make mod' button. That will gather all the files that you added and present you with the folder. To completele the mod, you gotta select everything and make a .zip archive yourself, godot can't do that on its own. Can't you gather the files yourself? Yeah, but this tool preserves the folder structure which is important and also does extra things if your mod contains new textures/images. So its important to do it this way, just trust me.

Now that you have the mod, you can put it into the mods folder and try it in-game. To use/test mods you gotta have a separate complied version of your game since the mods don't work inside the editor (godot quirk). When you launch the game you should see a new module appear inside the mods menu together with your zip file loaded.

pic3

Here is the resulting mod from me. Use as example or to troubleshoot if you want

TestItemMod.zip

Do you have to make a module?

Not really, module is basically just a way of grouping all the files related to your mod into one folder. Very handy for organizing. But it's possible to create a mod without it having any modules in it.