Jump to content

Get waterproofness of character [Solved]


Recommended Posts

Hi, I'm working on a character that takes damage from the sunlight but can hide under trees / umbrellas.
I was thinking I could implement this by checking the characters current waterproofness level since it should be affected by standing under trees and such.

How can I get the waterproofness of my character?

Edited by WhiteAutumn
Link to comment
Share on other sites

you will only get a final number for waterproofness, so shelter + modifier + clothes in one. So if you only want to get the shelter, you should directly search for shelter.
in the sheltered component, which is attached to every player, you see that there are events pushed whenever the shelter is changing:
self.inst:PushEvent("sheltered", false)

So you simply can put in your commonpostinit character code:

inst:ListenForEvent("sheltered",function(inst,issheltered)
    if issheltered then
        --- your code
    else -- not sheltered anymore
        -- your code
    end
end)

 

Edited by Serpens
Link to comment
Share on other sites

On 10/8/2019 at 4:37 PM, Serpens said:

you will only get a final number for waterproofness, so shelter + modifier + clothes in one. So if you only want to get the shelter, you should directly search for shelter.
in the sheltered component, which is attached to every player, you see that there are events pushed whenever the shelter is changing:
self.inst:PushEvent("sheltered", false)

So you simply can put in your commonpostinit character code:


inst:ListenForEvent("sheltered",function(inst,issheltered)
    if issheltered then
        --- your code
    else -- not sheltered anymore
        -- your code
    end
end)

 

Thanks! I might go with just shelter then.
I did also want it to work for stuff like umbrellas but not for rain-coasts, I guess I will have to check manually if the player is holding an umbrella?

Edited by WhiteAutumn
Link to comment
Share on other sites

1 hour ago, WhiteAutumn said:

Thanks! I might go with just shelter then.
I did also want it to work for stuff like umbrellas but not for rain-coasts, I guess I will have to check manually if the player is holding an umbrella?

yes, I fear so.

you can do it eg in modmain.lua with sth like this:
 

AddPrefabPostnit("umbrella",function(inst)
    if inst.components.equippable~=nil then
        local old_onequip = inst.components.equippable.onequipfn
        local function new_onequip(inst, owner,...)
            if owner.prefab=="yourcharacter" then
                -- your code, you char just equipped an umbrella
            end
            if old_onequip~=nil then
                old_onequip(inst,owner,...)
            end
        end
        inst.components.equippable.onequipfn = new_onequip
        
        local old_onunequip = inst.components.equippable.onunequipfn
        local function new_onunequip(inst, owner,...)
            if owner.prefab=="yourcharacter" then
                -- your code, you char just unequipped an umbrella
            end
            if old_onunequip~=nil then
                old_onunequip(inst,owner,...)
            end
        end
        inst.components.equippable.onunequipfn = new_onunequip
    end
end)

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...