View Full Version : how to check player ducked or not?
how to check player ducked or not?
when i duck or not, server only print "Not Ducked"
new m_OffsetDuck;
public OnPluginStart()
{
m_OffsetDuck=FindSendPropOffs("CBasePlayer","m_bDucked"); //i have try CSSPlayer
HookEvent("bullet_impact",ev_bullet_impact);
}
public Action:ev_bullet_impact(Handle:event, const String:name[], bool:dontBroadcast)
{
decl client;
decl duck;
client = GetClientOfUserId(GetEventInt(event,"userid"));
duck=GetEntData(client,m_OffsetDuck,4); //i haven try 1,2,
if ( duck == 1)
{
PrintToServer("Ducked");
} else {
PrintToServer("Not Ducked");
}
}
BAILOPAN
09-12-2007, 10:03
If it's "m_bDucked" then it's probably boolean and thus 1 byte.
I haven't looked at the SDK yet but I think there is a flag for ducking which might be more useful.
Gruzilkin
09-12-2007, 13:11
can someone pls give a link to maybe some tutorial, or article that describes how to work with Entities?
I know C++, so I understand all this stuff, I'm just looking for some overview to start with...
or maybe just some description of a CBasePlayer class with it's properties...
http://developer.valvesoftware.com/wiki/CBasePlayer is empty
I'm also downloading Source SDK in Steam, and hope to find some information on CBasePlayer there :)
BAILOPAN
09-12-2007, 13:31
http://wiki.alliedmods.net/Entity_Properties is a good place to start if you're reading the SDK (which you should).
I found this in the HL2 source code, gamemovement.cpp:
player->GetFlags() & FL_DUCKING
//-----------------------------------------------------------------------------
// Purpose: Stop ducking
//-----------------------------------------------------------------------------
void CGameMovement::FinishUnDuck( void )
{
int i;
trace_t trace;
Vector newOrigin;
VectorCopy( mv->m_vecAbsOrigin, newOrigin );
if ( player->GetGroundEntity() != NULL )
{
for ( i = 0; i < 3; i++ )
{
newOrigin[i] += ( VEC_DUCK_HULL_MIN[i] - VEC_HULL_MIN[i] );
}
}
else
{
// If in air an letting go of crouch, make sure we can offset origin to make
// up for uncrouching
Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = ( hullSizeNormal - hullSizeCrouch );
viewDelta.Negate();
VectorAdd( newOrigin, viewDelta, newOrigin );
}
player->m_Local.m_bDucked = false;
player->RemoveFlag( FL_DUCKING );
player->m_Local.m_bDucking = false;
player->SetViewOffset( GetPlayerViewOffset( false ) );
player->m_Local.m_flDucktime = 0;
VectorCopy( newOrigin, mv->m_vecAbsOrigin );
// Recategorize position since ducking can change origin
CategorizePosition();
}
//-----------------------------------------------------------------------------
// Purpose: Finish ducking
//-----------------------------------------------------------------------------
void CGameMovement::FinishDuck( void )
{
int i;
player->AddFlag( FL_DUCKING );
player->m_Local.m_bDucked = true;
player->m_Local.m_bDucking = false;
player->SetViewOffset( GetPlayerViewOffset( true ) );
// HACKHACK - Fudge for collision bug - no time to fix this properly
if ( player->GetGroundEntity() != NULL )
{
for ( i = 0; i < 3; i++ )
{
mv->m_vecAbsOrigin[i] -= ( VEC_DUCK_HULL_MIN[i] - VEC_HULL_MIN[i] );
}
}
else
{
Vector hullSizeNormal = VEC_HULL_MAX - VEC_HULL_MIN;
Vector hullSizeCrouch = VEC_DUCK_HULL_MAX - VEC_DUCK_HULL_MIN;
Vector viewDelta = ( hullSizeNormal - hullSizeCrouch );
VectorAdd( mv->m_vecAbsOrigin, viewDelta, mv->m_vecAbsOrigin );
}
// See if we are stuck?
FixPlayerCrouchStuck( true );
// Recategorize position since ducking can change origin
CategorizePosition();
}
I don't know how much this helps, but I hate not trying...
how to work on source mod?
check the property 'm_iFlags' (I think..)
then do (if m_iFlags & FL_DUCKING)
Depends if FL_DUCKING is defined.
You might need to add
#define FL_DUCKING (1<<1)
SamuraiBarbi
09-12-2007, 22:43
I'm pretty sure there's an easier way to do that. When I needed to know if a player was ducked using eventscripts i used
es_getplayerprop is_ducking event_var(userid) CCSPlayer.baseclass.localdata.m_Local.m_bDuck ed
You just may be able to use GetEntProp to return the value.
Edit: Whoops. Yeah what Bailopan said, hehe.
NIGathan
05-19-2012, 15:56
I know this is an old thread, but I was having the same problem. This thread eventually helped me find this solution:
GetEntityFlags(client) & FL_DUCKING
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.