Jump to content

Recommended Posts

inst:ListenForEvent("finishedwork", function(inst, data)

if data.action == ACTIONS.CHOP then

if data.target:HasTag("tree") then

if inst.components.sanity then

inst.components.sanity:DoDelta(-5)

end

end

end

end)

I don't know if DarkXero's code will only apply when the tree is cut down but in case it does, here's code I got from Wallflower to do it per hit.

local function onworked(inst, data)    if data.target.components.workable.action == ACTIONS.CHOP then        inst.components.sanity:DoDelta(-.5)if inst.components.talker ~= nil theninst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_KILLED_TREE")) -- Hurt a friendly tree, you should feel bad!end    endend

And make sure to

inst:ListenForEvent("working", onworked)

 

 

Edit: Might as well do the exact same, I'm not sure

Edited by Thibooms
why do you need this line? What does this do?

 

It's not really needed since the player gets the talker component in both human and ghost form.

No instance of RemoveComponent("talker") either.

 

It checks that the talker component exists.

If you try to index the function Say, and there is no talker component, game crashes.

You can't do that to a nil value.

 

Better to check than to run into a once-in-a-lifetime error.

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