Drown NPC

Hey guys i just have a simple Idea

Is it possible to make the Npcs Drowning when there stay too longer underwater ??

this should be better than see a npc walking underwater cause they cant swim :confused:

[lua]
if SERVER then

AddCSLuaFile( "autorun/filename.lua" )

local function npcDrown()
		
	for _, npc in pairs( ents.FindByClass( "npc_*" ) ) do
			
		if npc:WaterLevel() == 3 then
			
			if not npc.breath then
					
				npc.breath = CurTime() + 20
					
				umsg.Start( "npc_drown" )
				umsg.Short( 20 )
				umsg.Entity( npc )
				umsg.End()
					
			elseif npc.breath < CurTime() and ( not npc.lastDamaged or npc.lastDamaged < CurTime() ) then
					
				npc:TakeDamage( 10 )
				npc:EmitSound( "player/pl_drown" .. math.random( 1, 3 ) .. ".wav" )
				npc.lastDamaged = CurTime() + 1
					
			end
				
		elseif npc.breath then
				
			npc.breath = false
				
			umsg.Start( "npc_drown" )
			umsg.Short( 0 )
			umsg.Entity( npc )
			umsg.End()
				
		end
			
	end
		
end
hook.Add( "Think", "npc_drowning", npcDrown )

else

local function receiveBreathStart( msg )
		
	local breath = msg:ReadShort()
	local npc = msg:ReadEntity()
		
	npc.breath = CurTime() + breath
		
end
usermessage.Hook( "npc_drown", receiveBreathStart )
	
local function npcDrownMeter()
		
	for _, npc in pairs( ents.FindByClass( "npc_*" ) ) do
			
		if npc:WaterLevel() == 3 then
			
			local head = npc:LookupBone( "ValveBiped.Bip01_Head1" )
			local pos = npc:GetBonePosition( head ) + Vector( 0, 0, 12 )
			pos = pos:ToScreen()
				
			local str = "Drowning"

			if npc.breath and npc.breath > CurTime() then
					
				str = math.Round( npc.breath - CurTime(), 1 )
					
			end

			draw.SimpleText( str, "ChatFont", pos.x, pos.y, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER )
				
		end
			
	end
		
end
hook.Add( "HUDPaint", "npc_drownmeter", npcDrownMeter )

end
[/lua]

Goes in lua/autorun/

The reason valve didn’t add this is incase the game flipped out and spawned like, Alyx in a puddle and suddenly she choked to death on her own esophagus.