Kiibie Posted August 24, 2017 Share Posted August 24, 2017 Hi! I've been trying to make my character mod gain sanity when using the sewing kit (or gaining sanity when holding it, at the very least). I have succeeded to make my character gain sanity upon catching fireflies, but this code does not seem to work for the sewing kit. inst:ListenForEvent( "finishedwork", function(inst, data) if(data and data.target and data.target.prefab=="dress") then if(data.action and data.action.id=="SEW") then if(inst and inst.components and inst.components.sanity) then inst.components.sanity:DoDelta(20) -- amount of sanity gain here inst.components.talker:Say("It feels nice to sew after a while...") end end end end ) I tried countless times to make this work with a bunch of references from other codes, but I can't seem to make it work as easy as it seems! I think it's the 'prefab' target that is set wrong, as I want all clothing to be affected, not a specific one. Does anyone have an idea how this works? Link to comment Share on other sites More sharing options...
Kiibie Posted August 25, 2017 Author Share Posted August 25, 2017 I tried to change the event for 'repair', the target to 'tophat' and it still doesn't do anything in game. No crash, it simply does not work. I'm really trying all I can, I'd be really grateful to anyone helping ;_; Link to comment Share on other sites More sharing options...
ptr Posted August 26, 2017 Share Posted August 26, 2017 The sewing kit has nothing to do with the 'work' thing. You should use AddComponentPostInit for 'sewing', and hook up the Sewing:DoSewing(target, doer) function. Link to comment Share on other sites More sharing options...
ZupaleX Posted August 26, 2017 Share Posted August 26, 2017 Repair should work and is much simpler than doing a component post init. That's why the events are here for. So could you post your attempt with the "repair" event and a bit more code for the context? Link to comment Share on other sites More sharing options...
ptr Posted August 26, 2017 Share Posted August 26, 2017 Oh, I understand what you did. The key problem is that the 'repair' event won't push a 'data' variable like 'finishedwork' did, so you cannot get the target from 'data.target'. So if you don't care about the target, you can simply remove the 'if' part. The example for listening a 'repair' event can be found in "prefabs/player_classified.lua", which is a child prefab for player's prefabs. But if you care about that, you could override the 'DoSewing' function with 'AddComponentPostInit'. Or by overriding the 'inst.components.sewing.onsewn' function with 'AddPrefabPostInit' for 'sewingkit'. The original function can be found in "prefabs/sewingkit.lua": local function onsewn(inst, target, doer) doer:PushEvent("repair") end Link to comment Share on other sites More sharing options...
Kiibie Posted August 27, 2017 Author Share Posted August 27, 2017 (edited) Thanks a bunch guys! @ptr I was exactly looking for a way to affect all clothing, so what you suggested is perfect. I just tried it and it works like I wanted! I still tried to use the 'AddComponentPostInit' to change the duration/use of the sewing kit, and the game keeps crashing and telling me "the 'AddComponentPostInit' is not declared", obviously I am missing something. Am I supposed to hook something to declare it? With these lines of code to set the Uses: AddComponentPostInit("finiteuses", function(self) self.inst:ListenForEvent("percentusedchange", function(inst, data) local owner = nil if inst.components.inventoryitem then owner = inst.components.inventoryitem.owner end if owner and owner.prefab == "jayden" then inst.components.finiteuses:SetUses(10) end end) end) Edited August 27, 2017 by Kiibie Link to comment Share on other sites More sharing options...
ZupaleX Posted August 27, 2017 Share Posted August 27, 2017 Where do you put this function? Link to comment Share on other sites More sharing options...
Kiibie Posted August 27, 2017 Author Share Posted August 27, 2017 I put it in the end of MasterPostInit, probably not supposed to be there? (no base knowledge in coding sorry for putting up with me guys;;;) Link to comment Share on other sites More sharing options...
ZupaleX Posted August 27, 2017 Share Posted August 27, 2017 (edited) Indeed. These types of functions just go in your modmain. This is a function which will affect a component and has nothing to do with the master post init of your character. On a side note, you are using a rocket launcher to kill a fly. If you just want to modify the durability of the sewing kit only you should do a AddPrefabPostInit on the sewing kit itself and just set a new maximum use, or perform more complex operations if required (like changing the percentage consumed by each use if a specific character perform the action). But as a general rules, try to modify the lowest level possible before adding functions which will affect a lot of other entities for no reason Edited August 27, 2017 by ZupaleX Link to comment Share on other sites More sharing options...
Kiibie Posted August 27, 2017 Author Share Posted August 27, 2017 Aha okayy, I am indeed flying a rocket without knowing how it works I'm learning from my mistakes at the moment, at least. Well, I'm trying my best with your advice, thank you again! It can't be as simple as this in the modmain, right?: AddComponentPostInit("sewing_kit", function(self) inst.components.finiteuses:SetMaxUses( 10 * TUNING.SEWINGKIT_USES) inst.components.finiteuses:SetUses( 10 * TUNING.SEWINGKIT_USES) end) As I tried, it didn't do anything, as I thought ;o; Link to comment Share on other sites More sharing options...
ptr Posted August 28, 2017 Share Posted August 28, 2017 Well, it should be: AddPrefabPostInit("sewing_kit", function(inst) ... Link to comment Share on other sites More sharing options...
Kiibie Posted August 28, 2017 Author Share Posted August 28, 2017 Oh thanks!--- Hmmm, I tried to change it and it still does not work in game. I tried adding the repair value also, to see if this one would work and I also tried to change sewing_kit to sewingkit. The default values are 5 for all, so I thought I'd double to 10 to see a difference. AddComponentPostInit("sewing_kit", function(inst) inst.components.finiteuses:SetMaxUses( 10 * TUNING.SEWINGKIT_USES) inst.components.finiteuses:SetUses( 10 * TUNING.SEWINGKIT_USES) inst.components.sewing.repair_value = 10 * TUNING.SEWINGKIT_REPAIR_VALUE end) Link to comment Share on other sites More sharing options...
Lumina Posted August 28, 2017 Share Posted August 28, 2017 It's still addcomponent, and not addprefab. Link to comment Share on other sites More sharing options...
Kiibie Posted August 28, 2017 Author Share Posted August 28, 2017 URGH omg, sorry, I derped hard on that one. Everything works like a dream now!! You're all the best, thanks to all of you, especially for sticking with me! I'm always here if someone wants advice or help with art in return ~ Link to comment 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