whismerhill Posted October 9, 2016 Share Posted October 9, 2016 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 ... Link to comment Share on other sites More sharing options...
whismerhill Posted October 10, 2016 Author Share Posted October 10, 2016 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 ^^ Link to comment Share on other sites More sharing options...
whismerhill Posted October 11, 2016 Author Share Posted October 11, 2016 on another note : I can't find back the wiki that had some information on DS modding.... Link to comment Share on other sites More sharing options...
whismerhill Posted October 11, 2016 Author Share Posted October 11, 2016 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.... Link to comment Share on other sites More sharing options...
Recommended Posts
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.