Jump to content

How do I give an item has infinite durability?


Recommended Posts

I am making a character mod and I want to give the character a miner hat with infinite durability, but, it's my first mod so I'm actually not good at coding. Do anyone know how to do it?

Link to comment
Share on other sites

2 minutes ago, Guij2 said:

I am making a character mod and I want to give the character a miner hat with infinite durability, but, it's my first mod so I'm actually not good at coding. Do anyone know how to do it?

just DONT give it durability, like "fueled" or "armor" or "finiteuses"

Link to comment
Share on other sites

Yeah but, how do I place the miner's hat in the character's start inventory without giving it durability?

Should I make a custom item? If that's the case, I don't even know where to start ;-;. Is there a specific thread in the forum about custom items?

Link to comment
Share on other sites

11 hours ago, Guij2 said:

Yeah but, how do I place the miner's hat in the character's start inventory without giving it durability?

Well, first of all you would need a "minerhat" in the start_inv table of your character.

Then you would need a OnNewSpawn function on your master_postinit that would get that miner hat, and apply some code to it to remove the fueled component, and also give it some flags so when you restart the server, the game remembers to give that miner hat the special properties.

Then in modmain you would need to make a miner hat prefab post init and give it OnSave and OnLoad functions so you would be able to load your code again, editing the miner hat on server restart if the functions pick up your flags.

So yeah, go for:

12 hours ago, Guij2 said:

Should I make a custom item?

but you don't really need to. Just copy paste the miner code into a separate file!

Except it's all tossed into the hats.lua prefab file.

So yeah.

 

Well, I did it for you.

I copy pasted all relevant code and removed the fueled component.

Just like you have your character prefab file in PrefabFiles in modmain, add guijtwo_minerhat to the table to load the prefab.

Then in start_inv, add a guijtwo_minerhat so you start the game with one.

guijtwo_minerhat.lua

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...