Jump to content

[Help]How could I determine the eater?


Recommended Posts

I make a new food item, the food could change character property(like temperature),  but I don't want the monster(spider, hound...) or pigman eat it, because the monster seems not this components(temperaturem talk...), How could I do?

 

My code:
local function oneaten(inst, eater)  -- Must determine eater is not a character  -- How to do??  if eater not character then  -- I need the code.     return  end  -- Do something for character	end

Link to comment
Share on other sites

In your character's prefab

local function oneat(inst, food)    if food and food.components.edible and food.prefab == "yourfoodprefab" then        inst.components.health:DoDelta(numberToChangeHealthBy)        inst.components.hunger:DoDelta(numberToChangeHungerBy)    end    end

As to how to do something like temperature I have no idea. My only guess would be looking at something you know changes temperature by using it.

 

 

 

In your character's prefab master_postinit

inst.components.eater:SetOnEatFn(oneat)
Link to comment
Share on other sites

Alternatively,

if not eater:HasTag("player") then

for the check and,

local temp = eater.components.temperature:GetCurrent() + 5local maxtemp = eater.components.temperature.maxtempif temp < maxtemp then   eater.components.temperature:SetTemp(temp)else   eater.components.temperature:SetTemp(maxtemp)end

for the temperature.

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