whismerhill Posted October 9, 2016 Share Posted October 9, 2016 (edited) hi, I'm trying to build a mod that will add new "interesting" tools, that the player will want to spend precious resources on, but they will also have detrimental effects that can be mitigated given the right conditions, or that you might even be able to use to "work for you" !!! Anyways, I'm currently trying to find a way to acquire the target of a tool for example there will be red gem based tools, so the target might catch fire (hence why I need the target inside the tool prefab), at first I thought it would be simple since , components.weapon.onattack function has parameters : self, owner & target , but finiteuse.onusedasitem doesn't... do I need to use TheSim:FindEntities ? even then, if entities (such as saplings) are tightly packed together, I'm not sure it will return the right one in my opinion... edit: forgot to precise I also thought of using inst:ListenForEvent("FinishedWork",ToolWorkFinished(inst, data)) which has the same problem, it's attached to the tool prefab... so don't know what's the target of the tool ... Edited October 9, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70753-target-of-a-tool/ Share on other sites More sharing options...
whismerhill Posted October 10, 2016 Author Share Posted October 10, 2016 (edited) found something in workable.lua worker:PushEvent("working", {target = self.inst}) self.inst:PushEvent("worked", {worker = worker, workleft = self.workleft}) ... worker:PushEvent("finishedwork", {target = self.inst, action = self.action}) I wonder if I can " ListenForEvent " inside " onusedasitem " function. I'll have to try it out I suppose ^^ Edited October 10, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70753-target-of-a-tool/#findComment-823714 Share on other sites More sharing options...
whismerhill Posted October 11, 2016 Author Share Posted October 11, 2016 (edited) on another note : I can't find back the wiki that had some information on DS modding.... Edited October 12, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70753-target-of-a-tool/#findComment-823985 Share on other sites More sharing options...
whismerhill Posted October 11, 2016 Author Share Posted October 11, 2016 (edited) Spoiler inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(data.uses) inst.components.finiteuses:SetUses(data.uses) inst.components.finiteuses:SetOnFinished( onfinished) inst.components.finiteuses:SetConsumption(data.action, 1) inst.components.weapon.onattack = onattackred inst.components.finiteuses.onusedasitem = onusedasitemredaxe STRINGS.CHARACTERS.GENERIC.DESCRIBE.REDAXE = { "I don't think it will set the trees on fire, will it?", "So shiny...", "It's really warm...", } local function onusedasitemredaxe(self, action) print("whis_onusedasitemredaxe") local owner, dat --local tempfunc self.ListenForEvent("working", function(owner,dat) print("whis_listen") return owner,dat end ) local objectworkedon = dat.target if owner.components.temperature then -- player overheats owner.components.temperature:DoDelta(0.1) print("whis_overheat") end local rng = math.random()*100 -- the chance will be for each single hit !!! if rng < 100 and objectworkedon.components.burnable and not objectworkedon.components.burnable:IsBurning() then print("whis_burnable") if objectworkedon.components.freezable and objectworkedon.components.freezable:IsFrozen() then objectworkedon.components.freezable:Unfreeze() elseif objectworkedon.components.burnable:IsSmoldering() then objectworkedon.components.burnable:Ignite(true) else prin("whis_startwildfire") objectworkedon.components.burnable:StartWildfire() end end end here's my first try: it doesn't do anything. I'm probably missing something obvious. scratch that, the whole function is not fired, no wonder it's not working lol added the code that generates onusedasitem. I tested out that the redaxe item description works, which means this part of the code is fired up. so I don't get why when using the redaxe to cut trees, when using "prints", none appear in console.... Edited October 12, 2016 by whismerhill Link to comment https://forums.kleientertainment.com/forums/topic/70753-target-of-a-tool/#findComment-824030 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