Jump to content

Recommended Posts

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.

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.

  • Like 1
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 

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.

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 by GreatSound
for got to put something in
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.

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?

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",
}

 

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",
}

 

post-502721-0-03007100-1447467869.png

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

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 })
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?

 
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

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
×
  • Create New...