Jump to content

Editing item properties


Recommended Posts

Quick question: Is there a way to edit an item's properties in order to change its type and effects? I wanted to make the Beefalo Hat a head armor and lower its insulation, but I have no idea where to start.

Link to comment
Share on other sites

This might be a tiny bit more complicated than most prefabs since all the hats are held in one file, but it could work. If you are familiar with AddPrefabPostInit, see if you can add a function to the prefab "beefalohat" that adds a certain tag or component. You can make a hat in game to see if your desired properties exist.

After thinking about it for a another minute, this should work since when the game loads up, all the hat prefabs are already compiled and considered their own entities.

In any case, the components you're looking for are the "armor" and "insulator" components.

Your function might look like this:

AddPrefabPostInit("beefalohat", function(prefab)
	prefab:AddComponent("armor")
 	prefab.components.armor:InitCondition(*health of the hat as a number*, *damage absorption number*)
 	--inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)
 	--The line above is an example so you can look at what the numbers normally look like in tuning.lua
    
 	prefab:AddComponent("insulator")
 	inst.components.insulator:SetSummer() --not sure what this does; I copied it from hats.lua. You probably don't need it. Look in insulator.lua for more functions
 	inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL) --You can look in tuning.lua to see what value this is and put in your own.
end)

If you're interested in other properties or components, you can always look for examples in the prefabs folder for when they use AddTag or AddComponent. Also I don't know how much you know, but you can also use RemoveTag or RemoveComponent just as simply.

Link to comment
Share on other sites

I don't know much to be honest, I just got into modding this week, and most of what I'm doing is just personal stuff. I tried using AddTag and AddComponent before, but the game either just crashed as soon as I opened it, or nothing changed at all.

Also, I just tested what you proposed, and it crashed as soon as I crafted the hat.

AddPrefabPostInit("beefalohat", function(prefab)
    prefab:AddComponent("armor")
    prefab.components.armor:InitCondition(525, 80)
    inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)
         
     prefab:AddComponent("insulator")
     inst.components.insulator:SetSummer()
inst.components.insulator:SetInsulation(TUNING.INSULATION_SMALL)
end)

Was it a mistake on my end, or are we to assume this approach doesn't work?
 

Edited by -Penta-
Link to comment
Share on other sites

What did the crash screen say?

Also you can delete these lines:

inst.components.armor:InitCondition(TUNING.ARMOR_WATHGRITHRHAT, TUNING.ARMOR_WATHGRITHRHAT_ABSORPTION)

inst.components.insulator:SetSummer()

Also, change all the times you see the word "inst" to "prefab".

Also also, just to supplement what we're trying here, try to look for a simple mod that changes something about a prefab and check out its modmain file.

Edited by rawii22
Link to comment
Share on other sites

I don't remember what it said, actually, and the logs have already been deleted so I can't really check now :/

I tried looking for mods that did similar things to re-purpose the code, but I haven't found any so far. Still, I'll keep trying to make it work. There's still some things I didn't test, and the Beefalo Hat isn't the only clothing item whose properties I'm trying to change.

Also, as a side note, is there any way to change an item's name?

Edited by -Penta-
Link to comment
Share on other sites

Yes there is a way to change names. In a similar manner, there is a strings.lua file that holds all the strings the game uses.

You can probably make a change like this in modmain:

GLOBAL.STRINGS.NAMES.BEEFALOHAT = "My name here"

In the game the hover text should reflect that change. Descriptions from the character speech files can be changed in just the same way like this:

GLOBAL.STRINGS.CHARACTERS.WILSON.DESCRIBE.BEEFALOHAT = "My description here."

 

Link to comment
Share on other sites

Thanks, I managed to get it to work!

I know I'm asking too much stuff already, but do you know how practical it is to change a mob's loot table?

Also, sorry for the late response by the way.

Link to comment
Share on other sites

Well, if you check out any of the prefabs that can be destroyed, the loot is defined in the prefab file itself in a local table. I'm not sure if it's possible to redefine it from outside using an AddPrefabPostInit, but if it is, you know what to look at.

And you can keep asking anything, it's fine:wilson_smile:

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...