@@ -187,8 +187,9 @@ func (p *Player) IsScoped() bool {
187187}
188188
189189// IsDucking returns true if the player is currently crouching.
190+ // See also: Flags().Ducking() & Flags().DuckingKeyPressed()
190191func (p * Player ) IsDucking () bool {
191- return getBool ( p . Entity , "localdata.m_Local.m_bDucking" )
192+ return p . Flags (). Ducking () && p . Flags (). DuckingKeyPressed ( )
192193}
193194
194195// HasDefuseKit returns true if the player currently has a defuse kit in his inventory.
@@ -284,6 +285,51 @@ func (p *Player) Velocity() r3.Vector {
284285 }
285286}
286287
288+ // see https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
289+ const (
290+ flOnGround = 1 << iota
291+ flDucking
292+ flAnimDucking
293+ )
294+
295+ // PlayerFlags wraps m_fFlags and provides accessors for the various known flags a player may have set.
296+ type PlayerFlags uint32
297+
298+ func (pf PlayerFlags ) Get (f PlayerFlags ) bool {
299+ return pf & f != 0
300+ }
301+
302+ // OnGround returns true if the player is touching the ground.
303+ // See m_fFlags FL_ONGROUND https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
304+ func (pf PlayerFlags ) OnGround () bool {
305+ return pf .Get (flOnGround )
306+ }
307+
308+ // Ducking returns true if the player is/was fully crouched.
309+ // Fully ducked: Ducking() && DuckingKeyPressed()
310+ // Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
311+ // Fully unducked: !Ducking() && !DuckingKeyPressed()
312+ // Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()
313+ // See m_fFlags FL_DUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
314+ func (pf PlayerFlags ) Ducking () bool {
315+ return pf .Get (flDucking )
316+ }
317+
318+ // DuckingKeyPressed returns true if the player is holding the crouch key pressed.
319+ // Fully ducked: Ducking() && DuckingKeyPressed()
320+ // Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
321+ // Fully unducked: !Ducking() && !DuckingKeyPressed()
322+ // Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()
323+ // See m_fFlags FL_ANIMDUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
324+ func (pf PlayerFlags ) DuckingKeyPressed () bool {
325+ return pf .Get (flAnimDucking )
326+ }
327+
328+ // Flags returns flags currently set on m_fFlags.
329+ func (p * Player ) Flags () PlayerFlags {
330+ return PlayerFlags (getInt (p .Entity , "m_fFlags" ))
331+ }
332+
287333/////////////////////////////
288334// CCSPlayerResource stuff //
289335/////////////////////////////
0 commit comments