Jump to content

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


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!

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...