Garry's Mod Wiki

util.PointContents

  number util.PointContents( Vector position )

Description

Returns the contents of the position specified.

This function will sample only the world environments. It can be used to check if Entity:GetPos is underwater for example unlike Entity:WaterLevel which works for players only.

Arguments

1 Vector position
Position to get the contents sample from.

Returns

1 number
Contents bitflag, see CONTENTS enum

Example

Check if the trace position is underwater.

local tr = Entity( 1 ):GetEyeTrace() print( bit.band( util.PointContents( tr.HitPos ), CONTENTS_WATER ) == CONTENTS_WATER )

Example

Check if the trace entity position is underwater assuming the object is already valid.

if ( bit.band( util.PointContents( tr.Entity:GetPos() ), CONTENTS_WATER ) == CONTENTS_WATER ) then -- Do stuff here when the entity's position is underwater. end