samjviana Posted April 8, 2023 Share Posted April 8, 2023 I'm trying to keep track of when the player chops down a tree, but i can't figure it out i have this code right now: Spoiler function TreePostInit(inst) print("[Analytics] Tree evergreen_sparse spawned!") print("[Analytics] components: ") printTable(inst.components) if inst.components.workable == nil then print("[Analytics] components.workable is nil!") return end local oldonfinish = inst.components.workable.onfinish inst.components.workable.onfinish = function(inst, chopper) if chopper then print("[Analytics] Tree chopped down!") print("[Analytics] Chopped by: " .. chopper.name) end oldonfinish(inst, chopper) end end local trees = { "evergreen", "evergreen_normal", "evergreen_tall", "evergreen_short", "twiggy_short" } for k,v in pairs(trees) do AddPrefabPostInit(v, TreePostInit) end Link to comment https://forums.kleientertainment.com/forums/topic/147026-how-to-listen-when-a-player-chop-down-a-tree/ Share on other sites More sharing options...
-LukaS- Posted April 11, 2023 Share Posted April 11, 2023 Instead of editing the tree prefabs it would be better to override the player prefab. Something like this should do the trick: local function OnFinishWork(inst, data) if data.action == ACTIONS.CHOP then -- Your code here end end inst:ListenForEvent("finishedwork", OnFinishWork) 1 Link to comment https://forums.kleientertainment.com/forums/topic/147026-how-to-listen-when-a-player-chop-down-a-tree/#findComment-1629363 Share on other sites More sharing options...
samjviana Posted April 11, 2023 Author Share Posted April 11, 2023 this worked, thanks one more thing, this works for server side, can i do something like for the client? Link to comment https://forums.kleientertainment.com/forums/topic/147026-how-to-listen-when-a-player-chop-down-a-tree/#findComment-1629413 Share on other sites More sharing options...
-LukaS- Posted April 12, 2023 Share Posted April 12, 2023 `finishedwork` is pushed only on the server so it's not possible but you can send an RPC to the client and send information that way. Here's a post on RPCs in case you want to look further into it: 1 Link to comment https://forums.kleientertainment.com/forums/topic/147026-how-to-listen-when-a-player-chop-down-a-tree/#findComment-1629452 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