Question regarding WaterLevel()

Hi there!

Currently i’m making a system for my swep base that checks if the player has gone underwater, and if so, it gives him this special swep i created. The swep cannot be holstered untill the player is out of the water. However, i checked the wiki and the possible values in the swep are:

0 = Not in water
1 = Feet in water
2 = Majority of body in water
3 = Fully submerged

However, whenever the player is swimming on the surface of water, (which SHOULD be 2), it holsters the swep. I wanted to force the player to use the swep untill he isn’t swimming anymore. And by swimming i mean being able to move on the surface of the water. However if i try to get as high up as i can, it holsters the swep.

If i use 1, it works, but it only holsters if the player is not touching the water with his feet.

How can i holster it if the water is, say, at the player’s belt level?

This might be a bit confusing, and if so, ill try to provide some pictures and be more descriptive if i can.

Thanks!

Code:
[lua]
if (SERVER) then
AddCSLuaFile(“shared.lua”)
end

SWEP.PrintName = “swimming”
SWEP.Base = “weapon_base”

SWEP.ViewModel = “models/weapons/c_swim.mdl”
SWEP.WorldModel = “”
SWEP.ViewModelFOV = 64
SWEP.UseHands = true

SWEP.Primary.Ammo = “none”

SWEP.Spawnable = false
SWEP.AdminSpawnable = false

SWEP.DrawCrosshair = false
SWEP.HoldType = “normal”

SWEP.Slot = 6

SWEP.SwimDelay = 1

SWEP.Primary.Ammo = “none”
SWEP.Primary.Clipsize = -1
SWEP.Primary.DefaultClip = -1

SWEP.Secondary.Ammo = “none”
SWEP.Secondary.Clipsize = -1
SWEP.Secondary.DefaultClip = -1

SWEP.DrawAmmo = false

function SWEP:Deploy()
local player = self:GetOwner()
player:EmitSound(“player/water/water_wade”…math.random(1,4)…".wav",70,100)
self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
timer.Simple(0.40,function() if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
timer.Simple(0.90,function() if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-5,5),math.random(-5,5),math.random(-5,5)))end end)
return true
end

function SWEP:Holster()

local player = self:GetOwner()

if player:WaterLevel() >= 2 then
	return false
end

return true

end

function SWEP:OnRemove()

if self.WaterLoop != nil then
	self.WaterLoop:Stop()
end

end

function SWEP:PrimaryAttack()
return false
end

function SWEP:SecondaryAttack()
return false
end

function SWEP:Reload()
return false
end

function SWEP:Think()

self.WaterLoop = CreateSound(self,"")
local player = self:GetOwner()
if player:WaterLevel() < 2 then
self.WaterLoop:Stop()
else
if self:IsValid() then
self.WaterLoop = CreateSound(self,“ambient/water/underwater.wav”)
self.WaterLoop:Play()
end
self.WaterLoop:ChangeVolume(0,0)
end
//print(self.SwimDelay)

if player:WaterLevel() &lt; 2 then

	if (SERVER) then
		player:StripWeapon(self:GetClass())
		player:ConCommand("lastinv")
	end

	return
end

self.SwimDelay 	= self.SwimDelay -0.01
if self.SwimDelay &lt; 0.01 then
self.SwimDelay = 1
 	
	local player = self:GetOwner()
	if player:KeyDown(IN_FORWARD) then
	player:EmitSound("player/water/water_wade"..math.random(1,4)..".wav",70,100)
	self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER )
	timer.Simple(0.40,function()	if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
	timer.Simple(0.90,function()	if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-5,5),math.random(-5,5),math.random(-5,5)))end end)
	end
	if player:KeyDown(IN_BACK) then
	player:EmitSound("player/water/water_wade"..math.random(1,4)..".wav",70,100)
		 self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER2 )
		 timer.Simple(0.40,function()if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
	end
	if player:KeyDown(IN_MOVELEFT) then
	player:EmitSound("player/water/water_wade"..math.random(1,4)..".wav",70,100)
		 self.Weapon:SendWeaponAnim( ACT_VM_HITLEFT )
		 timer.Simple(0.40,function()if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
		 timer.Simple(0.80,function()if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
	end
	if player:KeyDown(IN_MOVERIGHT) then
	player:EmitSound("player/water/water_wade"..math.random(1,4)..".wav",70,100)
		 self.Weapon:SendWeaponAnim( ACT_VM_HITRIGHT )
		 timer.Simple(0.40,function()if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-3,3),math.random(-3,3),math.random(-3,3)))end end)
		 timer.Simple(0.90,function()	if self:IsValid() then self.Owner:ViewPunch(Angle(math.random(-5,5),math.random(-5,5),math.random(-5,5)))end end)
	end 
	if player:KeyDown(IN_SPEED) then
		local vModel = player:GetViewModel()
		vModel:SetPlaybackRate(2)
	end
end

end
[/lua]

Without seeing your code it sounds like you might be checking it using < when you should use <= ?
Code pls.

To go with what wh1 says, you can use util.PointContents( pos ); to get the type of stuff at a vector location. Full code is there to fix the swimming animation, but you can do the same thing, modify the height, and then do what you need to do based on the data.

Remember, PLAYER:GetPos( ) z coord is at the players feet.

Well if I still sees the player is in the water you use ply:IsOnGround() to check If the player is standing. http://gmodwiki.net/Lua/Classes/Entity/IsOnGround

Added the code to OP.

Im on phone and can’t really read through properly, but in your think function you’re doing
[LUA]if player:WaterLevel() < 2 then [/LUA]
try <=