Jump to content

Recommended Posts

I am making a character and I am trying to figure out how to stop the beefalo from attacking me when they are in heat. 

 

I would also like to make it so that when my character is around beefalo their sanity gets raised. 

 

I also need to know how to make the pigmen drop my characters sanity. 

 

and finally I would like to know how to make grass edible. 

 

I am super new to all of this and I suck at editing all the codes and stuff. any help is seriously appreciated! also, if anyone has any suggestions for my Beefalo themed character I would love to hear them! thank you!!!

 

 

 

I am trying to figure out how to stop the beefalo from attacking me when they are in heat.

 

In your character prefab, inside common_postinit,

inst:AddTag("beefalo")

This tag grants us immunity on beefalo heat, so we give ourselves the tag.

 

But it would get removed after you unequip a beefalo hat. To fix this, in modmain,

local function RestoreTag(inst)	if GLOBAL.TheWorld.ismastersim then		local function _RT(inst, data)			if data.owner and data.owner.prefab == "wilson" then				data.owner:AddTag("beefalo")			end		end		inst:ListenForEvent("unequipped", _RT)	endendAddPrefabPostInit("beefalohat", RestoreTag)

where instead of wilson you put the prefab name of your character. This way, on unequip, we get the tag back.

 

I would also like to make it so that when my character is around beefalo their sanity gets raised. I also need to know how to make the pigmen drop my characters sanity.

 

In your character prefab,

local function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10	local max_bonus = TUNING.SANITYAURA_TINY * 2    local ents = TheSim:FindEntities(x, y, z, max_rad, nil, { "player" }, { "beefalo", "pig" })    for i, v in ipairs(ents) do		local sz = 0		if v:HasTag("beefalo") then			sz = TUNING.SANITYAURA_TINY		else -- Then it has tag pig			sz = -TUNING.SANITYAURA_LARGE        end		local distsq = inst:GetDistanceSqToInst(v) - 25		delta = delta + sz / math.max(1, distsq)    end    return math.min(delta, max_bonus)end

Inside this function, you get entities near you with certain tags, like beefalo and pig, and without the tags like player.

Then loops through the entities, and depending on their tag, you get a negative or positive value.

Then, depending on distance, it gets added to a variable.

After all calculations are done, the function returns the delta variable that got the different sanity values added up.

 

We use it in your character prefab, inside master_postinit,

inst.components.sanity.custom_rate_fn = sanityfn
finally I would like to know how to make grass edible.

 

It is edible. It is of the foodtype called ROUGHAGE.

 

So in your character prefab we add,

local function SetCanEatGrass(self)	table.insert(self.preferseating, FOODTYPE.ROUGHAGE)	table.insert(self.caneat, FOODTYPE.ROUGHAGE)	self.inst:AddTag(FOODTYPE.ROUGHAGE.."_eater")	local _TestFood = self.TestFood	self.TestFood = function(self, food, testvalues)		if food and food:HasTag("edible_"..FOODTYPE.ROUGHAGE) then			return food.prefab == "cutgrass"		end		return _TestFood(self, food, testvalues)	endend

This function, when given the eater component, makes the guy with eater be able to get the eat prompt for all ROUGHAGE foods.

He will only eat grass though, he will refuse twigs, for example.

 

Then, inside character prefab file, master_postinit,

SetCanEatGrass(inst.components.eater)

And I think that's it. The structure of your character prefab file would be

local MakePlayerCharacter = require("prefabs/player_common")local assets = {}local prefabs = {}local function common_postinit(inst)	inst:AddTag("beefalo")endlocal function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10	local max_bonus = TUNING.SANITYAURA_TINY * 2    local ents = TheSim:FindEntities(x, y, z, max_rad, nil, { "player" }, { "beefalo", "pig" })    for i, v in ipairs(ents) do		local sz = 0		if v:HasTag("beefalo") then			sz = TUNING.SANITYAURA_TINY		else -- Then it has tag pig			sz = -TUNING.SANITYAURA_LARGE        end		local distsq = inst:GetDistanceSqToInst(v) - 25		delta = delta + sz / math.max(1, distsq)    end    return math.min(delta, max_bonus)endlocal function SetCanEatGrass(self)	table.insert(self.preferseating, FOODTYPE.ROUGHAGE)	table.insert(self.caneat, FOODTYPE.ROUGHAGE)	self.inst:AddTag(FOODTYPE.ROUGHAGE.."_eater")	local _TestFood = self.TestFood	self.TestFood = function(self, food, testvalues)		if food and food:HasTag("edible_"..FOODTYPE.ROUGHAGE) then			return food.prefab == "cutgrass"		end		return _TestFood(self, food, testvalues)	endendlocal function master_postinit(inst)	inst.components.sanity.custom_rate_fn = sanityfn	SetCanEatGrass(inst.components.eater)endreturn MakePlayerCharacter("mycharacterprefabname", prefabs, assets, common_postinit, master_postinit)

 

In your character prefab, inside common_postinit,

inst:AddTag("beefalo")

This tag grants us immunity on beefalo heat, so we give ourselves the tag.

 

But it would get removed after you unequip a beefalo hat. To fix this, in modmain,

local function RestoreTag(inst)	if GLOBAL.TheWorld.ismastersim then		local function _RT(inst, data)			if data.owner and data.owner.prefab == "wilson" then				data.owner:AddTag("beefalo")			end		end		inst:ListenForEvent("unequipped", _RT)	endendAddPrefabPostInit("beefalohat", RestoreTag)

where instead of wilson you put the prefab name of your character. This way, on unequip, we get the tag back.

 

 

 

 

In your character prefab,

local function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10	local max_bonus = TUNING.SANITYAURA_TINY * 2    local ents = TheSim:FindEntities(x, y, z, max_rad, nil, { "player" }, { "beefalo", "pig" })    for i, v in ipairs(ents) do		local sz = 0		if v:HasTag("beefalo") then			sz = TUNING.SANITYAURA_TINY		else -- Then it has tag pig			sz = -TUNING.SANITYAURA_LARGE        end		local distsq = inst:GetDistanceSqToInst(v) - 25		delta = delta + sz / math.max(1, distsq)    end    return math.min(delta, max_bonus)end

Inside this function, you get entities near you with certain tags, like beefalo and pig, and without the tags like player.

Then loops through the entities, and depending on their tag, you get a negative or positive value.

Then, depending on distance, it gets added to a variable.

After all calculations are done, the function returns the delta variable that got the different sanity values added up.

 

We use it in your character prefab, inside master_postinit,

inst.components.sanity.custom_rate_fn = sanityfn

It is edible. It is of the foodtype called ROUGHAGE.

 

So in your character prefab we add,

local function SetCanEatGrass(self)	table.insert(self.preferseating, FOODTYPE.ROUGHAGE)	table.insert(self.caneat, FOODTYPE.ROUGHAGE)	self.inst:AddTag(FOODTYPE.ROUGHAGE.."_eater")	local _TestFood = self.TestFood	self.TestFood = function(self, food, testvalues)		if food and food:HasTag("edible_"..FOODTYPE.ROUGHAGE) then			return food.prefab == "cutgrass"		end		return _TestFood(self, food, testvalues)	endend

This function, when given the eater component, makes the guy with eater be able to get the eat prompt for all ROUGHAGE foods.

He will only eat grass though, he will refuse twigs, for example.

 

Then, inside character prefab file, master_postinit,

SetCanEatGrass(inst.components.eater)

And I think that's it. The structure of your character prefab file would be

local MakePlayerCharacter = require("prefabs/player_common")local assets = {}local prefabs = {}local function common_postinit(inst)	inst:AddTag("beefalo")endlocal function sanityfn(inst)    local x, y, z = inst.Transform:GetWorldPosition()     local delta = 0    local max_rad = 10	local max_bonus = TUNING.SANITYAURA_TINY * 2    local ents = TheSim:FindEntities(x, y, z, max_rad, nil, { "player" }, { "beefalo", "pig" })    for i, v in ipairs(ents) do		local sz = 0		if v:HasTag("beefalo") then			sz = TUNING.SANITYAURA_TINY		else -- Then it has tag pig			sz = -TUNING.SANITYAURA_LARGE        end		local distsq = inst:GetDistanceSqToInst(v) - 25		delta = delta + sz / math.max(1, distsq)    end    return math.min(delta, max_bonus)endlocal function SetCanEatGrass(self)	table.insert(self.preferseating, FOODTYPE.ROUGHAGE)	table.insert(self.caneat, FOODTYPE.ROUGHAGE)	self.inst:AddTag(FOODTYPE.ROUGHAGE.."_eater")	local _TestFood = self.TestFood	self.TestFood = function(self, food, testvalues)		if food and food:HasTag("edible_"..FOODTYPE.ROUGHAGE) then			return food.prefab == "cutgrass"		end		return _TestFood(self, food, testvalues)	endendlocal function master_postinit(inst)	inst.components.sanity.custom_rate_fn = sanityfn	SetCanEatGrass(inst.components.eater)endreturn MakePlayerCharacter("mycharacterprefabname", prefabs, assets, common_postinit, master_postinit)

Thank you THANK YOU so much. This was so incredibly helpful and it worked PERFECTLY. so Thank you!!!!

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