OnEntityEnter working as expected?
Hi i was wondering if its possible to see if a player is swimming, or in water using OnEntityEnter. It says in the api that is works on water but running simple test it does not fire when entering water. Im currently using Wetness value but if the player has a radsuit on they will not die because you dont get wet(thanks garry) :)
Thanks! Any ideas?
You could maybe try BasePlayer.IsSwimming
5e6f8629518b5.jpg Pho3niX90
You could maybe try BasePlayer.IsSwimming

I did think about this. Im guessing this could be used instead of wetness value ill give it a try!

yeah should be the only one you need to use. 
So I had a go. Its a lot more inefficent compared to checking the wetness value. So im going to see if theres another way of doing it. if not i will use your idea
mrcameron999
So I had a go. Its a lot more inefficent compared to checking the wetness value. So im going to see if theres another way of doing it. if not i will use your idea

What is more inefficient? And why do you say so?



Merged post

        void OnEntityEnter(TriggerBase trigger, BaseEntity entity) {
            Puts("OnEntityEnter works!");
            BasePlayer pl = entity as BasePlayer;
            if(pl!= null && pl.IsSwimming()) {
                // do something
            }
        }


Merged post

Another suggestion. See how other plugins are doing it if the above doesn't work, for example:
https://umod.org/plugins/water-limits

does
        private bool IsInWater(BasePlayer player)
        {
            ModelState modelState = player.modelState;
#if DEBUG
            LogWarning($"{player.displayName} is {System.Math.Ceiling(modelState.waterLevel)}% underwater");
#endif
            return modelState != null && modelState.waterLevel > 0f && player.metabolism.wetness.value > 0f;
        }​

This does not get called when I enter water. And thats what I was initally confused with. Was wondering if something was up with it. Tried couple things like doing isSwimming when metabolism is called but its to expensive compared to checkecking the wetness value

void OnEntityEnter(TriggerBase trigger, BaseEntity entity) {
So it seems that is only for entities, and not BasePlayer after some tests. 

wetness is part of the PlayerMetabolism.  So use the following

    public bool IsSwimming()
    {
        return this.WaterFactor() >= 0.65f;
    }​
and WaterFactor is 
    public override float WaterFactor()
    {
        if (this.isMounted)
        {
            return this.GetMounted().WaterFactorForPlayer(this);
        }
        if (base.GetParentEntity() != null && base.GetParentEntity().BlocksWaterFor(this))
        {
            return 0f;
        }
        return base.WaterFactor();
    }​
Seems like thats the best way to do it. Ill do that. Thanks for your help!