Jump to content

Recommended Posts

As the title says Is it possible to detect when a tree is chopped down or when rocks are mined?

That is , when the actual loot is dropped, not during the animation phase. I know you can use a Listener somehow. Would it be possible to add a component to the player character that can listen to events in the world such as these? If so, how would it be done? Preferably something with Post Init.

Thanks!

@Fadingwhite

local function check_worked(inst)	inst:ListenForEvent("workfinished", function(inst)		-- ...	end)endAddPrefabPostInit("rock1", check_worked)AddPrefabPostInit("rock2", check_worked)-- AddPrefabPostInit("prefab_name", check_worked)-- etc...

Check the workable component to see how the events are called.

("..\scripts\components\workable", copied for reference)

function Workable:WorkedBy(worker, numworks)    numworks = numworks or 1    self.workleft = self.workleft - numworks    self.lastworktime = GetTime()    worker:PushEvent("working", {target = self.inst})    self.inst:PushEvent("worked", {worker = worker, workleft = self.workleft})        if self.onwork then        self.onwork(self.inst, worker, self.workleft)    end    if self.workleft <= 0 then                if self.onfinish then self.onfinish(self.inst, worker) end                self.inst:PushEvent("workfinished")        worker:PushEvent("finishedwork", {target = self.inst, action = self.action})    endend

The worker pushes the event "working" with data.target being the tree, rock, structure, grave, etc.

Use this if you are making a character.

 

The tree, rock, etc. pushes an event as seen in BlueBerrys post.

Use this if your mod is character-independent.

Edited by Mobbstar

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