Jump to content

Recommended Posts

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.

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.

  1. Create a new blank component. (name it something unique)
  2. Add this component to the Watering Can prefab using AddPrefabPostInit.
  3. Add AddComponentActionAddAction and AddStategraphPostInit with appropriate states for you action.
  4. Make sure you're using "EQUIPPED" as the actiontype.

You can check out how these component actions work in componentaction.lua.

  • Like 1

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. 

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...