FurryEskimo Posted August 27, 2020 Share Posted August 27, 2020 (edited) So I can now repair amulets, but there're two things I haven't figured out. I want only a specific character to be able to perform this action, and I want it to be less effective. Right now this code causes the amulet to be repaired by 50%, and all characters can do it.. --Test code. Makes blue amulet refuel-able. local AllRecipes = GLOBAL.AllRecipes local Ingredient = GLOBAL.Ingredient local RECIPETABS = GLOBAL.RECIPETABS local STRINGS = GLOBAL.STRINGS local TECH = GLOBAL.TECH local FUELTYPE = GLOBAL.FUELTYPE AddPrefabPostInit("blueamulet", function (inst) inst:AddComponent("fueled") inst.components.fueled.fueltype = FUELTYPE.NIGHTMARE inst.components.fueled:InitializeFuelLevel(TUNING.BLUEAMULET_FUEL) inst.components.fueled:SetDepletedFn(inst.Remove) inst.components.fueled:SetFirstPeriod(TUNING.TURNON_FUELED_CONSUMPTION, TUNING.TURNON_FULL_FUELED_CONSUMPTION) inst.components.fueled.accepting = true end) Edited August 27, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/ Share on other sites More sharing options...
penguin0616 Posted August 28, 2020 Share Posted August 28, 2020 (edited) local inst = ... inst:AddComponents("fueled") local oldTakeFuelItem = inst.components.fueled.TakeFuelItem inst.components.fueled.TakeFuelItem = function(self, item, doer) if doer.prefab == "wilson" then print("I.. am Wilson.") return oldCanAcceptFuelItem(self, item) end return false end Here's a rough example of something you could do. You'll probably need to edit it though. Edited August 28, 2020 by penguin0616 2 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1366784 Share on other sites More sharing options...
FurryEskimo Posted August 28, 2020 Author Share Posted August 28, 2020 I think I know what you're doing, but do you mind explaining it? I think you're adding a component to the amulet, so it will only accept being refueled if the one trying to refuel it is my character, yes? Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1366801 Share on other sites More sharing options...
FurryEskimo Posted August 28, 2020 Author Share Posted August 28, 2020 (edited) @penguin0616 Cool, so I did manage to get the code inserted and it's, sort of working. When anyone other than Wilson tries to refuel the amulet they're told no, and drop the nightmare fuel, which is a little weird.. Obviously I tried replacing Wilson's name with my character's, but the game crashes when I try refueling it. Next I tried checking the 'doer''s tags instead of prefab, but that also causes the game to crash when I try to refuel. Hopefully I can get this working soon. if doer:HasTag("furryeskimo") then Edit: I loaded up as wilson and when his name is the prefab, the game crashes, so it seems like there's some kind of issue when the player's prefab matches the condition. I tried commenting out the Print code, but it still has a problem. Thoughts? if doer.prefab == "wilson" then --if doer:HasTag("furryeskimo") then -- print("I.. am Wilson.") return oldCanAcceptFuelItem(self, item) --Note: Causes game to crash. end return false end Edited August 28, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1366974 Share on other sites More sharing options...
FurryEskimo Posted August 28, 2020 Author Share Posted August 28, 2020 (edited) Edit: Figured it out. You wrote 'oldTakeFuelItem' and 'oldCanAcceptFuelItem'. I made these both 'oldTakeFuelItem' and now it's working. It's still a little weird that characters unable to repair the amulet will drop fuel when attempting to repair, but it's not tragic. Next on my list of things to do is nerf the repair ability from 50% to something closer to 10%. No luck so far. Edit: Bad news.. I've been poking around the 'fueled' component file and I don't think I can change the 50% bonus via nightmare fuel. All of the values that relate to it seem to be based on the nightmare fuel's fuel value. If I change that value, All items that rely on nightmare fuel will be effected. I'm going to try testing the 'bonusmult' value, but that's tied to Willow's mastery of fire and may do nothing. self:DoDelta(item.components.fuel.fuelvalue * self.bonusmult * wetmult * masterymult, doer) I can change the total durability of the amulet, and the rate at which it is used, creating the illusion of being repaired by less, but it caused all existing amulets to suddenly loose almost all of their durability.. Edit: Haha! It seems 'bonusmult' does work, though I'm not entirely sure yet if this edit has any far reaching consequences. In the meantime, this value allows me to edit how much the amulet is refueled by. Weirdly, I've never been able to get code like 'print("That's better.")' to work. Is the character supposed to say that aloud? Edited August 28, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367004 Share on other sites More sharing options...
penguin0616 Posted August 29, 2020 Share Posted August 29, 2020 Yeah, I didn't fully complete the code. I hope that when you fixed it, you passed in doer as well for oldTakeFuelItem. No, print does not make the character say anything aloud. The print function prints the string to the console and thus the corresponding log file. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367174 Share on other sites More sharing options...
FurryEskimo Posted August 29, 2020 Author Share Posted August 29, 2020 (edited) @penguin0616 Passed in doer? Sorry, I don't understand. This is what it is now, and appears to work: --Test code. Makes it so only this character can refuel Chilled Amulets. local oldTakeFuelItem = inst.components.fueled.TakeFuelItem inst.components.fueled.TakeFuelItem = function(self, item, doer) if doer.prefab == "furryeskimo" then -- print("That's better.") --Note: Doesn't seem to work. return oldTakeFuelItem(self, item) --Repair amulet, if refuel is performed by this character. end return false --Unsure what this does. end Edited August 29, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367198 Share on other sites More sharing options...
penguin0616 Posted August 29, 2020 Share Posted August 29, 2020 Change return oldTakeFuelItem(self, item) --Repair amulet, if refuel is performed by this character. to return oldTakeFuelItem(self, item, doer) --Repair amulet, if refuel is performed by this character. It will save you a couple crashes. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367227 Share on other sites More sharing options...
FurryEskimo Posted August 29, 2020 Author Share Posted August 29, 2020 Ok, I made the change, but nothing seems to have changed. Hopefully it is more stable, but it didn't seem unstable before, haha. Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367294 Share on other sites More sharing options...
penguin0616 Posted August 30, 2020 Share Posted August 30, 2020 It is now more stable, yes. Good luck with your project! 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367460 Share on other sites More sharing options...
FurryEskimo Posted August 30, 2020 Author Share Posted August 30, 2020 Thanks. The last bit of code I’m working on is 95% done. The character can befriend hounds, but the hounds don’t stay trained once the game is saved and exited. I’m trying to figure out how to save those traits, and reload them in when the game loads. Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367475 Share on other sites More sharing options...
penguin0616 Posted August 30, 2020 Share Posted August 30, 2020 Assuming you're using the same follower stuff as Klei (like pigs), then I regret to inform you that followers don't save. At least, I know that pig followers don't (rip all my meat). Here's an example though. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367526 Share on other sites More sharing options...
FurryEskimo Posted August 30, 2020 Author Share Posted August 30, 2020 (edited) @penguin0616 I think I might be able to do it. My code is different than theirs. I haven’t shared all the code yet, since it’s adapted from a few others I’m piecing together, but it seems like hounds have a component for loyalty time, and have a leader component, but it Seems, like the component that actually makes them follow an individual is saved to the player’s statistics, so unless that value is saved, I’m not sure it’ll work correctly. Edited August 30, 2020 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367679 Share on other sites More sharing options...
penguin0616 Posted August 30, 2020 Share Posted August 30, 2020 (edited) Hounds have the follower component so they can follow their Vargs. Edited August 30, 2020 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367760 Share on other sites More sharing options...
FurryEskimo Posted August 31, 2020 Author Share Posted August 31, 2020 @penguin0616 Is that how it works? From what I could tell, that info was pushed to the player's file. Let me just post the file. modmain.lua Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367768 Share on other sites More sharing options...
penguin0616 Posted August 31, 2020 Share Posted August 31, 2020 (edited) @FurryEskimo I don't know what you want me to do with that. Also, I don't recommend you put your config data directly in the GLOBAL table. Edited August 31, 2020 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367810 Share on other sites More sharing options...
FurryEskimo Posted August 31, 2020 Author Share Posted August 31, 2020 @penguin0616 You don’t have to do anything. I felt silly quoting chunks of it each time, cluttering up the chat. Also no? I think I tried it a few different ways, and that was the only way I was able to get it to work. I haven’t messed with it since because I’m not exactly sure how it works, but it appears to work. Link to comment https://forums.kleientertainment.com/forums/topic/121309-repairing-amulets-code/#findComment-1367839 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