GreatSound Posted July 5, 2016 Share Posted July 5, 2016 I want to give the cat cap infinite durability but i don't know how i'm new to coding and all the other stuff Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/ Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 Cat caps have the fueled component. It's a code add-on that has a number that when it reaches 0, it consumes the cap. What you do is remove it. local function catcoonhatPostInit(inst) if inst.components.fueled then inst:RemoveComponent("fueled") end end AddPrefabPostInit("catcoonhat", catcoonhatPostInit) So when the prefab catcoonhat is spawned, you run the function catcoonhatPostInit on it. If the entity (inst) has the fueled component, you remove it. Infinite durability. Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790197 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 (edited) it this for all characters? i just want to do it for the custom character that i made i don't want everyone on my server walking around with a infinite cat cap Edited July 6, 2016 by GreatSound misspelled word Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790204 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 In that case: local function catcoonhatPostInit(inst) if inst.components.fueled then local _DoDelta = inst.components.fueled.DoDelta inst.components.fueled.DoDelta = function(self, amount) local owner = inst.components.inventoryitem.owner if owner and owner.prefab == "wilson" then return end _DoDelta(self, amount) end end end AddPrefabPostInit("catcoonhat", catcoonhatPostInit) Instead of editing the entire component, you edit a function of it. You save the old function in _DoDelta. You make a new DoDelta. If the item owner is Wilson, when the fuel is going to change, then it doesn't change. This way only one character gets the cat cap to last. Replace "wilson" with your character prefab name. 1 Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790211 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 14 minutes ago, DarkXero said: In that case: local function catcoonhatPostInit(inst) if inst.components.fueled then local _DoDelta = inst.components.fueled.DoDelta inst.components.fueled.DoDelta = function(self, amount) local owner = inst.components.inventoryitem.owner if owner and owner.prefab == "wilson" then return end _DoDelta(self, amount) end end end AddPrefabPostInit("catcoonhat", catcoonhatPostInit) Instead of editing the entire component, you edit a function of it. You save the old function in _DoDelta. You make a new DoDelta. If the item owner is Wilson, when the fuel is going to change, then it doesn't change. This way only one character gets the cat cap to last. Replace "wilson" with your character prefab name. So do i add this to my prefabs? I'm sorry if i'm causing you trouble Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790216 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 4 minutes ago, GreatSound said: So do i add this to my prefabs? I'm sorry if i'm causing you trouble This goes in modmain.lua. The code in modmain has access to functions like AddPrefabPostInit and AddComponentPostInit, which you wouldn't normally access from places like your character prefab file. Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790217 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 (edited) 10 minutes ago, DarkXero said: This goes in modmain.lua. The code in modmain has access to functions like AddPrefabPostInit and AddComponentPostInit, which you wouldn't normally access from places like your character prefab file. Thanks for your help but i just need help with two more things. I want to make it where i start with the cat cap and only able to eat meat like wigfrid Edited July 6, 2016 by GreatSound for got to put something in Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790219 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 local start_inv = { "spear_wathgrithr", "wathgrithrhat", "meat", "meat", "meat", "meat", } This is what Wigfrid has to start with a spear, a helmet, and four meat. The cat cap prefab is "catcoonhat". inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) This is what Wigfrid has on her master_postinit function to change her diet. Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790222 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 13 minutes ago, DarkXero said: local start_inv = { "spear_wathgrithr", "wathgrithrhat", "meat", "meat", "meat", "meat", } This is what Wigfrid has to start with a spear, a helmet, and four meat. The cat cap prefab is "catcoonhat". inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) This is what Wigfrid has on her master_postinit function to change her diet. so i just put the catcoonhat in the local star_inv with Wigfrid's starting items? Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790225 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 6 minutes ago, GreatSound said: so i just put the catcoonhat in the local star_inv with Wigfrid's starting items? Wigfrid has a start_inv table where she has the items she starts with. Your character prefab file should have a start_inv table where you can put the items you start with. Wigfrid has those 6 items. You want one, "catcoonhat". local start_inv = { "catcoonhat", } Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790226 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 7 minutes ago, DarkXero said: Wigfrid has a start_inv table where she has the items she starts with. Your character prefab file should have a start_inv table where you can put the items you start with. Wigfrid has those 6 items. You want one, "catcoonhat". local start_inv = { "catcoonhat", } Im getting this i tried to add wigfrids files and catcoonhat my game ended up crashing upon world start up i fixed the problem and ended up with this Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790231 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 When your game crashes, you can find info in MyDocuments/Klei/DoNotStarveTogether/client_log.txt In can also give us information about what might be wrong. You can also post your character's prefab file to check for errors. Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790241 Share on other sites More sharing options...
GreatSound Posted July 6, 2016 Author Share Posted July 6, 2016 4 hours ago, DarkXero said: When your game crashes, you can find info in MyDocuments/Klei/DoNotStarveTogether/client_log.txt In can also give us information about what might be wrong. You can also post your character's prefab file to check for errors. Where do i put this? so I will only be able to eat meat inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT }) Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790293 Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 15 hours ago, GreatSound said: Where do i put this? so I will only be able to eat meat Inside the master_postinit function of your character prefab file. Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-790494 Share on other sites More sharing options...
MrYiang Posted June 23, 2022 Share Posted June 23, 2022 On 7/5/2016 at 8:54 PM, DarkXero said: local function catcoonhatPostInit(inst) if inst.components.fueled then local _DoDelta = inst.components.fueled.DoDelta inst.components.fueled.DoDelta = function(self, amount) local owner = inst.components.inventoryitem.owner if owner and owner.prefab == "wilson" then return end _DoDelta(self, amount) end end end AddPrefabPostInit("catcoonhat", catcoonhatPostInit) I know it's been 6 years since this post but... is all of this still working on current versions? And if so, what would it be like to want to apply the same thing but in armors? Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-1579139 Share on other sites More sharing options...
Boogiepop210 Posted September 22, 2022 Share Posted September 22, 2022 On 6/22/2022 at 10:32 PM, MrYiang said: I know it's been 6 years since this post but... is all of this still working on current versions? And if so, what would it be like to want to apply the same thing but in armors? Most likely still works. If you want to do the same for an amour then replace the "catcoonhat" with the prefab your changing and the catcoonhatpostint with something like logamourPostint or whatever you wanna change Link to comment https://forums.kleientertainment.com/forums/topic/68661-giving-an-item-infinite-durability/#findComment-1599212 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now