7Bukaj7 Posted December 12, 2022 Share Posted December 12, 2022 Hello I am working on a character that will get a stats boost while he is wet. I have been trying some codes but none of them seem to work the closest one was: local old_on_update = inst.components.moisture.OnUpdate local new_on_update = function(inst, dt) old_on_update(inst,dt) inst.components.sanity.dapperness = 10 inst.components.combat.damagemultiplier = 1.8 inst.components.health.absorb = 0.3 -- inst.moisture will give you current wetness level end inst.components.moisture.OnUpdate = new_on_update end Any tips or help? Would also like to make him able to wet himself using a "Watering Can" but idk if that's possible and now im focusing on stat boost when wet and back to normal stats when dry. Link to comment https://forums.kleientertainment.com/forums/topic/145185-help-with-code-stats-boost-when-wet-and-aplying-wetness-to-themself/ Share on other sites More sharing options...
-LukaS- Posted December 12, 2022 Share Posted December 12, 2022 There's a few problems with your code here: First off, the first parameter of OnUpdate is the component itself (self). Your new_on_update function has its first parameter as inst, which wouldn't be a problem if you weren't already using this name as the player entity variable name. So when trying to do: inst.components.sanity.dapperness = 10 inst.components.combat.damagemultiplier = 1.8 inst.components.health.absorb = 0.3 the inst in here is the moisture component not the player entity, therefor you're basically trying to access the components table of the moisture component (which doesn't exist). Secondly, you don't have any if statements in your function to check the players current moisture value. You should try something like this: if self.moisture > 20 then -- Using 'self' instead of 'inst' to not confuse with the player 'inst' self.inst.components.sanity.dapperness = 10 -- 'self.inst' is your player entity self.inst.components.combat.damagemultiplier = 1.8 self.inst.components.health.absorb = 0.3 end Lastly, about the Watering Can action. You can do that simply by adding a new component action. Create a new blank component. (name it something unique) Add this component to the Watering Can prefab using AddPrefabPostInit. Add AddComponentAction, AddAction and AddStategraphPostInit with appropriate states for you action. Make sure you're using "EQUIPPED" as the actiontype. You can check out how these component actions work in componentaction.lua. 1 Link to comment https://forums.kleientertainment.com/forums/topic/145185-help-with-code-stats-boost-when-wet-and-aplying-wetness-to-themself/#findComment-1614868 Share on other sites More sharing options...
7Bukaj7 Posted December 13, 2022 Author Share Posted December 13, 2022 So I have updated my code as u told me to (I belive, im kinda trash at coding) local old_on_update = inst.components.moisture.OnUpdate local rain_udpate = function(inst, dt) old_on_update(inst,dt) if self.moisture > 20 then -- Using 'self' instead of 'inst' to not confuse with the player 'inst' self.inst.components.sanity.dapperness = 10 -- 'self.inst' is your player entity self.inst.components.combat.damagemultiplier = 1.8 self.inst.components.health.absorb = 0.3 end end inst.components.moisture.OnUpdate = rain_udpate and got error that self in self.moisture is not determined. Also I have put that code in local master_postinit = function(inst). Correct me if I should put if outside or just in another function. Link to comment https://forums.kleientertainment.com/forums/topic/145185-help-with-code-stats-boost-when-wet-and-aplying-wetness-to-themself/#findComment-1614968 Share on other sites More sharing options...
7Bukaj7 Posted December 13, 2022 Author Share Posted December 13, 2022 whoops I copied the wrong code: There is the good one local old_on_update = inst.components.moisture.OnUpdate local rain_udpate = function(inst, dt) old_on_update(inst,dt) if self.moisture > 20 then -- Using 'self' instead of 'inst' to not confuse with the player 'inst' self.inst.components.sanity.dapperness = 10 -- 'self.inst' is your player entity self.inst.components.combat.damagemultiplier = 1.8 self.inst.components.health.absorb = 0.3 end inst.components.moisture.OnUpdate = rain_udpate end Link to comment https://forums.kleientertainment.com/forums/topic/145185-help-with-code-stats-boost-when-wet-and-aplying-wetness-to-themself/#findComment-1614969 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