jimmosio Posted June 5, 2015 Share Posted June 5, 2015 (edited) I have this code right here that increases crafted armor's starting HP by 35%.local function ab(inst,data) if data.item.prefab == "armorwood" or data.item.prefab == "armormarble" or data.item.prefab == "armorruins" or data.item.prefab == "ruinshat" or data.item.prefab == "armordragonfly" or data.item.prefab == "footballhat" or data.item.prefab == "armorgrass" or data.item.prefab == "armor_sanity" or data.item.prefab == "beehat" then data.item.components.armor:SetPercent(1.35) endendThat executes thanks to this:inst:ListenForEvent("builditem", ab)Works perfectly in DS, but I'm having trouble porting it to DST. I checked the log, but it says nothing about the problem.Thanks in advance. EDIT: Another question: if talk_LP is linked to sounds when examining things, the sounds when making a gesture (angry, sad, joy, ecc.) are linked to what? Edited June 5, 2015 by jimmosio Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/ Share on other sites More sharing options...
Kzisor Posted June 5, 2015 Share Posted June 5, 2015 @jimmosio, look at how the reviver.lua prefab works. I believe there is an OnBuilt function which is called when items are built in DST, which can be manipulated like you want them to be. Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644146 Share on other sites More sharing options...
jimmosio Posted June 5, 2015 Author Share Posted June 5, 2015 (edited) @jimmosio, look at how the reviver.lua prefab works. I believe there is an OnBuilt function which is called when items are built in DST, which can be manipulated like you want them to be.There is no real "onbuilt" function there, only a smart way of using "onpickedup", where the drain on life and sanity is done, then the function to look for when picked up changes.But that code is item-side, and couldn't think of a way to make it player-side. Back to my code, I tried to use "prod" and "item" instead of "data.item", but no results. Edited June 5, 2015 by jimmosio Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644160 Share on other sites More sharing options...
DarkXero Posted June 5, 2015 Share Posted June 5, 2015 (edited) When you build something:1) The event builditem gets pushed to the builder, with the data containing item and recipe2) An onBuild attached to the builder component is sought and ran, with builder and item parameters.3) Also, an onBuilt attached to the product prefab is sought and ran, with item and builder parameters. Your listener is fine in this case. The problem here is in SetPercent:SetPercent(1.35) runs SetCondition(max * 1.35)newcondition equals min of ( max * 1.35, max ) So you don't change the max condition.You change the armor condition to be full, but because you just crafted it, it's already full. Do:data.item.components.armor.maxcondition = data.item.components.armor.maxcondition * 1.35data.item.components.armor:SetPercent(1)This should improve the armor's maxcondition, and then up the condition so it shows 100%.Unless you make a more convoluted change, you can't display 135%. If you try to have armor with condition = 135, and maxcondition = 100 then when you get hit for say, 5 damage, you get:SetCondition(135 - 5) = SetCondition(130)newcondition equals min of ( 130, 100 ), which gives 100 and renders your upgrade void. There's another issue here.The maxcondition doesn't get saved.So if you save, quit, then load the game, the armor will get the old maxcondition.Then, when applying the saved condition, the game will pick between the oldmax * 1.35 and the restoredmax, and will choose restoredmax, making your upgrade void. Edited June 5, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644170 Share on other sites More sharing options...
jimmosio Posted June 5, 2015 Author Share Posted June 5, 2015 (edited) -snip-Are you telling me that what I want to do is impossible in DST? Or that I need to store some variables somewhere when the world is saved (and closed)? Edited June 5, 2015 by jimmosio Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644173 Share on other sites More sharing options...
Kzisor Posted June 5, 2015 Share Posted June 5, 2015 There is no real "onbuilt" function there, only a smart way of using "onpickedup", where the drain on life and sanity is done, then the function to look for when picked up changes.But that code is item-side, and couldn't think of a way to make it player-side. Back to my code, I tried to use "prod" and "item" instead of "data.item", but no results. Yes my apologies, the reviver was changed. You can look in the builder.lua component file and see this line:prod:OnBuilt(self.inst)This line is called the OnBuilt function of the instance you're trying to build. Simply create a function and attach it to the OnBuilt of the instance. Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644193 Share on other sites More sharing options...
DarkXero Posted June 5, 2015 Share Posted June 5, 2015 (edited) @jimmosio, no, there are many ways to do it and I was weighing the different options. I think what you should do is copy paste the SetCondition function of the armor component, and put in your modmain:AddComponentPostInit("armor", function(self) function self:SetCondition(amount) self.condition = amount self.inst:PushEvent("percentusedchange", {percent = self:GetPercent()}) if self.condition <= 0 then self.condition = 0 GLOBAL.ProfileStatsSet("armor_broke_" .. self.inst.prefab, true) GLOBAL.ProfileStatsSet("armor", self.inst.prefab) if GLOBAL.METRICS_ENABLED then GLOBAL.FightStat_BrokenArmor(self.inst.prefab) end if self.onfinished then self.onfinished() end self.inst:Remove() end endend)Then your listener will work. Edited June 6, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644194 Share on other sites More sharing options...
jimmosio Posted June 6, 2015 Author Share Posted June 6, 2015 (edited) -snip-Thank you so much, it works now./thread Edited June 6, 2015 by jimmosio Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644409 Share on other sites More sharing options...
Kzisor Posted June 6, 2015 Share Posted June 6, 2015 (edited) @DarkXero, it takes less code to actually use the on built method.AddComponentPostInit("armor", function( armor ) armor.inst._OnBuilt = armor.inst.OnBuilt armor.inst.OnBuilt = function( inst ) armor.inst._OnBuilt( inst ) inst.components.armor:InitCondition( ( inst.components.armor.condition * 1.35 ), inst.components.armor.absorp_percent ) endend) Edited June 6, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644484 Share on other sites More sharing options...
DarkXero Posted June 6, 2015 Share Posted June 6, 2015 @Kzisor, that is useful if you want to do it for all characters.The issue remaining there is that when you save/load, only the condition is saved, not the maxcondition.So you have to also edit the save/load functions, to avoid having the prefab file's InitCondition override your new max one. So in the end it would look like this:AddComponentPostInit("armor", function( armor ) armor.inst._OnBuilt = armor.inst.OnBuilt armor.inst.OnBuilt = function( inst, builder ) armor.inst._OnBuilt( inst, builder ) if builder.prefab == "wilson" then inst.components.armor:InitCondition( ( inst.components.armor.condition * 1.35 ), inst.components.armor.absorp_percent ) end end armor._OnSave = armor.OnSave armor.OnSave = function( armor ) local ret = armor._OnSave( armor ) ret.maxcondition = armor.maxcondition return ret end armor._OnLoad = armor.OnLoad armor.OnLoad = function( armor, data ) armor._OnLoad( armor, data ) if data.maxcondition then armor.maxcondition = data.maxcondition end endend)However, the real reason I copied the SetCondition function and changed the math.min to the amount, is to display percentages over 100%. Imagine you have a Willow and a Wilson master crafter. Wilson crafts an armorwood, Willow does too.Which armor is the more resilient one?You can't know unless you get hit or you keep track of which armor is which. Instead of having implicit knowledge, I prefer having two different percentages, that way it's clear which armor is which.Unless the 135% gets the percentage down to 100%, in which case they are the same armor. Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644486 Share on other sites More sharing options...
Kzisor Posted June 6, 2015 Share Posted June 6, 2015 @DarkXero, eh, the percentage displaying is a differing of opinion. Also since you pointed out about the issue not saving the maxcondition or the absorb_percent I think that is a mod-ability issue more than anything. We should see if PeterA could push an update to that particular code to save/load those two values. Link to comment https://forums.kleientertainment.com/forums/topic/54838-increase-crafted-armor-durability-works-in-ds-not-in-dst/#findComment-644517 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