Earthyburt Posted March 30, 2021 Share Posted March 30, 2021 (edited) Hello! I do not know how to do the action in the title, I tried asking in a list of questions post, but I wasn't given any Lua code to work off of, and my request for how to code that task was never answered, so I decided to make this post about it. (And maybe help somebody in the future who has this issue). Also if I cannot get the percentage directly, then just give me the way to get Current sanity/health and max sanity/health of the owner. Edited March 30, 2021 by Earthyburt Link to comment Share on other sites More sharing options...
IronHunter Posted March 30, 2021 Share Posted March 30, 2021 (edited) If it has the inventoryitem component Then inst.components.inventoryitem.owner Where inst is the item's reference in your code From there we can then do inst.components.inventoryitem.owner.components.health.current inst.components.inventoryitem.owner.components.health:GetPercent() inst.components.inventoryitem.owner.components.sanity.current inst.components.inventoryitem.owner.components.sanity:GetPercent() The same can be applied for obtaining max health, and other data for reference look at the components for InventoryItem Health Sanity Edited March 30, 2021 by IronHunter Typo 2 Link to comment Share on other sites More sharing options...
Earthyburt Posted March 30, 2021 Author Share Posted March 30, 2021 12 hours ago, IronHunter said: If it has the inventoryitem component Then inst.components.inventoryitem.owner Where inst is the item's reference in your code From there we can then do inst.components.inventoryitem.owner.components.health.current inst.components.inventoryitem.owner.components.health:GetPercent() inst.components.inventoryitem.owner.components.sanity.current inst.components.inventoryitem.owner.components.sanity:GetPercent() The same can be applied for obtaining max health, and other data for reference look at the components for InventoryItem Health Sanity @IronHunterThank you for your information. There is one more question (hopefully) I have to ask of you: I tried applying this value into my code and the game crashed. Could you give me insight on how to fix this? I have included a screenshot of this and code associated with it. playerSanity = inst.components.inventoryitem.owner.components.sanity:GetPercent() damageAddition = (30*playerSanity) inst:AddComponent("weapon") inst.components.weapon:SetDamage(damageAddition + 15) ---damage Link to comment Share on other sites More sharing options...
IronHunter Posted March 31, 2021 Share Posted March 31, 2021 This is because their is no owner unless the item is in a inventory. I would add a failsafe. So if there is no owner set it to a default value. Also you want to listenfor when this item is picked up and dropped so when the owner value changes. In this case because this is a weapon, I would simply have it update on equip and listenforevent the owners sanitydelta 2 Link to comment Share on other sites More sharing options...
Earthyburt Posted April 1, 2021 Author Share Posted April 1, 2021 23 hours ago, IronHunter said: This is because their is no owner unless the item is in a inventory. I would add a failsafe. So if there is no owner set it to a default value. Also you want to listenfor when this item is picked up and dropped so when the owner value changes. In this case because this is a weapon, I would simply have it update on equip and listenforevent the owners sanitydelta @IronHunter , sorry for pinging you again, but my anxiety got the better of me; How would I set the default value again? I am still new at modding. Link to comment Share on other sites More sharing options...
IronHunter Posted April 1, 2021 Share Posted April 1, 2021 (edited) Hey, sorry I haven't had time to reply. I would suggest considering its a weapon, you add to your on equip and unequip fns a listenforevent that will update whenever sanity changes, then have it update the weapon that way. local function updateDamage(owner) local sanity = owner.components.sanity and owner.components.sanity:GetPercent() or 0 local weapon = owner.components.inventory and owner.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) if weapon ~= nil then weapon.components.weapon:SetDamage(30*sanity + 15) end end local function OnEquip(inst, owner) --in OnEquip Function owner:ListenForEvent("sanitydelta", updateDamage) end local function OnUnEquip(inst, owner) --in OnUnEquipFunction owner:RemoveEventCallback("sanitydelta", updateDamage) end --in local function fn inst.components.weapon:SetDamage(15) inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable:SetOnUnequip(OnUnEquip) Edited April 1, 2021 by IronHunter 1 1 Link to comment Share on other sites More sharing options...
Earthyburt Posted April 2, 2021 Author Share Posted April 2, 2021 @IronHunter , there seems to be one more problem. It has something to do with declaring the UpdateDamage Function Link to comment Share on other sites More sharing options...
IronHunter Posted April 5, 2021 Share Posted April 5, 2021 @Earthyburt If you still are having problems troubleshooting. Please attach your file so I can make sure you have placed the code in the correct spots. 1 1 Link to comment Share on other sites More sharing options...
Earthyburt Posted April 6, 2021 Author Share Posted April 6, 2021 (edited) 9 hours ago, IronHunter said: @Earthyburt If you still are having problems troubleshooting. Please attach your file so I can make sure you have placed the code in the correct spots. sanityspear.lua @IronHunter Edited April 6, 2021 by Earthyburt Link to comment Share on other sites More sharing options...
IronHunter Posted April 6, 2021 Share Posted April 6, 2021 Try testing it out with the updateDamage fn outside the fn(sim) As that will put it in the scope for the listenforevents sanityspear.lua 1 1 Link to comment Share on other sites More sharing options...
Earthyburt Posted April 6, 2021 Author Share Posted April 6, 2021 (edited) 10 hours ago, IronHunter said: Try testing it out with the updateDamage fn outside the fn(sim) As that will put it in the scope for the listenforevents sanityspear.lua 2.26 kB · 0 downloads Oh! So I had to put the function ABOVE the function. Alright, thank you so much for helping me!! I greatly appreciate it. @IronHunter Edited April 6, 2021 by Earthyburt Link to comment Share on other sites More sharing options...
Earthyburt Posted April 20, 2021 Author Share Posted April 20, 2021 On 3/30/2021 at 6:02 AM, IronHunter said: If it has the inventoryitem component Then inst.components.inventoryitem.owner Where inst is the item's reference in your code From there we can then do inst.components.inventoryitem.owner.components.health.current inst.components.inventoryitem.owner.components.health:GetPercent() inst.components.inventoryitem.owner.components.sanity.current inst.components.inventoryitem.owner.components.sanity:GetPercent() The same can be applied for obtaining max health, and other data for reference look at the components for InventoryItem Health Sanity Hey, sorry for not asking this sooner, but what is the Syntax of getting Max Sanity / Max Health? I do not know how to get these values for it Link to comment Share on other sites More sharing options...
Earthyburt Posted April 21, 2021 Author Share Posted April 21, 2021 (edited) @IronHunter I forgot to include a tag in my most recent question on this thread Edited April 22, 2021 by Earthyburt Link to comment Share on other sites More sharing options...
IronHunter Posted April 22, 2021 Share Posted April 22, 2021 Like I said look at the components for health.lua and sanity.lua for max health.lua you can --the first will take into account black health which cannot be healed ..health:GetMaxWithPenalty() ..health.maxhealth for sanity.lua --its very similar ..sanity:GetMaxWithPenalty() ..sanity.max I seriously suggest you check out the files, as it could save you a lot of time. 1 1 Link to comment Share on other sites More sharing options...
Earthyburt Posted April 22, 2021 Author Share Posted April 22, 2021 12 hours ago, IronHunter said: Like I said look at the components for health.lua and sanity.lua for max health.lua you can --the first will take into account black health which cannot be healed ..health:GetMaxWithPenalty() ..health.maxhealth for sanity.lua --its very similar ..sanity:GetMaxWithPenalty() ..sanity.max I seriously suggest you check out the files, as it could save you a lot of time. Alright Thanks! It looks like I did get getmaxwithpenalty right (though I prefered just Max, so thank you for helping me with that). It seems like my problem is something else, but it is an unrelated issue. 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