meromaro Posted October 12, 2017 Share Posted October 12, 2017 I'm attempting to make an item for my character where in it can detect my characters sanity, in such that if the sanity of the character is above 50%, it will give a small amount of sanity (similar to the garland and parasol), but if the character's sanity is below 50%, then it will reduce a small amount of sanity (similar to the sanity loss at night) so far I've tried: local function sanitycheck(inst) if owner.sanity = >= 50 then inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL else inst.components.equippable.dapperness = TUNING.CRAZINESS_MED end end and putting it under local function Onequip: local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_ella", "swap_ella") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") if owner.sanity = >= 50 then inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL else inst.components.equippable.dapperness = TUNING.CRAZINESS_MED end end but neither works. Could anyone give some advice on how to fix this please? Thank you Link to comment Share on other sites More sharing options...
ptr Posted October 12, 2017 Share Posted October 12, 2017 First, what is "= >=" operator? Second, shouldn't that be "owner.components.sanity.current >= 50"? Link to comment Share on other sites More sharing options...
w00tyd00d Posted October 12, 2017 Share Posted October 12, 2017 (edited) What I would suggest try taking a look at the onemanband.lua script and see how they use equippable.dapperfn, since it calculates how much sanity you lose based on how many followers you currently have. You can just make a similar function but instead of checking for followers, check for sanity levels instead and return the intended values accordingly. In the equippable component, dapperfn overrides dapperness, so all you have to worry about is returning the proper value with your custom dapperfn and you should be good. Hope this helps EDIT: And yeah, @ptr is 100% right in that it should be "owner.components.sanity.current >= 50" Edited October 12, 2017 by w00tyd00d Link to comment Share on other sites More sharing options...
meromaro Posted October 13, 2017 Author Share Posted October 13, 2017 (edited) Alright thanks for giving me something to work with, and for correcting that operator Edited October 13, 2017 by meromaro grammar Link to comment Share on other sites More sharing options...
SourNVitriol Posted October 13, 2017 Share Posted October 13, 2017 I think from what w00t said, it should go like: local function CalcDapperness(inst, owner) if owner.components.sanity:GetPercent() > .5 then return TUNING.DAPPERNESS_SMALL elseif owner.components.sanity:GetPercent() <= .5 then return -TUNING.DAPPERNESS_SMALL end end --then in the local fn inst.components.equippable.dapperfn = CalcDapperness --this is how its implemented in the onemanband.lua, basically you can assign any "name" to the function Link to comment Share on other sites More sharing options...
meromaro Posted October 13, 2017 Author Share Posted October 13, 2017 AAANND IT WORKS NOW! Works like a dream. Thanks w00tyd00d and SourNVitriol!!! 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