@@ -186,9 +186,28 @@ func (p *Player) IsScoped() bool {
186
186
return getBool (p .Entity , "m_bIsScoped" )
187
187
}
188
188
189
- // IsDucking returns true if the player is currently crouching.
189
+ // IsDucking returns true if the player is currently fully crouching.
190
+ // See also: Flags().Ducking() & Flags().DuckingKeyPressed()
190
191
func (p * Player ) IsDucking () bool {
191
- return getBool (p .Entity , "localdata.m_Local.m_bDucking" )
192
+ return p .Flags ().Ducking () && p .Flags ().DuckingKeyPressed ()
193
+ }
194
+
195
+ // IsDuckingInProgress returns true if the player is currently in the progress of going from standing to crouched.
196
+ // See also: Flags().Ducking() & Flags().DuckingKeyPressed()
197
+ func (p * Player ) IsDuckingInProgress () bool {
198
+ return ! p .Flags ().Ducking () && p .Flags ().DuckingKeyPressed ()
199
+ }
200
+
201
+ // IsUnDuckingInProgress returns true if the player is currently in the progress of going from crouched to standing.
202
+ // See also: Flags().Ducking() & Flags().DuckingKeyPressed()
203
+ func (p * Player ) IsUnDuckingInProgress () bool {
204
+ return p .Flags ().Ducking () && ! p .Flags ().DuckingKeyPressed ()
205
+ }
206
+
207
+ // IsStaning returns true if the player is currently fully standing upright.
208
+ // See also: Flags().Ducking() & Flags().DuckingKeyPressed()
209
+ func (p * Player ) IsStanding () bool {
210
+ return ! p .Flags ().Ducking () && ! p .Flags ().DuckingKeyPressed ()
192
211
}
193
212
194
213
// HasDefuseKit returns true if the player currently has a defuse kit in his inventory.
@@ -284,6 +303,51 @@ func (p *Player) Velocity() r3.Vector {
284
303
}
285
304
}
286
305
306
+ // see https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
307
+ const (
308
+ flOnGround = 1 << iota
309
+ flDucking
310
+ flAnimDucking
311
+ )
312
+
313
+ // PlayerFlags wraps m_fFlags and provides accessors for the various known flags a player may have set.
314
+ type PlayerFlags uint32
315
+
316
+ func (pf PlayerFlags ) Get (f PlayerFlags ) bool {
317
+ return pf & f != 0
318
+ }
319
+
320
+ // OnGround returns true if the player is touching the ground.
321
+ // See m_fFlags FL_ONGROUND https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
322
+ func (pf PlayerFlags ) OnGround () bool {
323
+ return pf .Get (flOnGround )
324
+ }
325
+
326
+ // Ducking returns true if the player is/was fully crouched.
327
+ // Fully ducked: Ducking() && DuckingKeyPressed()
328
+ // Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
329
+ // Fully unducked: !Ducking() && !DuckingKeyPressed()
330
+ // Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()
331
+ // See m_fFlags FL_DUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
332
+ func (pf PlayerFlags ) Ducking () bool {
333
+ return pf .Get (flDucking )
334
+ }
335
+
336
+ // DuckingKeyPressed returns true if the player is holding the crouch key pressed.
337
+ // Fully ducked: Ducking() && DuckingKeyPressed()
338
+ // Previously fully ducked, unducking in progress: Ducking() && !DuckingKeyPressed()
339
+ // Fully unducked: !Ducking() && !DuckingKeyPressed()
340
+ // Previously fully unducked, ducking in progress: !Ducking() && DuckingKeyPressed()
341
+ // See m_fFlags FL_ANIMDUCKING https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/const.h#L146-L188
342
+ func (pf PlayerFlags ) DuckingKeyPressed () bool {
343
+ return pf .Get (flAnimDucking )
344
+ }
345
+
346
+ // Flags returns flags currently set on m_fFlags.
347
+ func (p * Player ) Flags () PlayerFlags {
348
+ return PlayerFlags (getInt (p .Entity , "m_fFlags" ))
349
+ }
350
+
287
351
/////////////////////////////
288
352
// CCSPlayerResource stuff //
289
353
/////////////////////////////
0 commit comments