M PlayerAnimState/TempEnt: Difference between revisions
Jump to navigation
Jump to search
TomEdwards (talk | contribs) (Created page with 'This temporary entity will dispatch player animation events to onlooking clients in the animating player's PVS. It is not needed in singleplayer. T…') |
m (link fix) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
This [[temporary entity]] will dispatch [[m_PlayerAnimState|player animation]] events to onlooking clients in the animating player's [[PVS]]. It is not needed in singleplayer. | This [[Temporary Entity|temporary entity]] will dispatch [[m_PlayerAnimState|player animation]] events to onlooking clients in the animating player's [[PVS]]. It is not needed in singleplayer. | ||
The code can go anywhere, but your player CPP files are the best location. | The code can go anywhere, but your player CPP files are the best location. Dispatch it from your player's <code>DoAnimationEvent()</code> function (before or after calling into the serverside AnimState). | ||
== Server == | == Server == | ||
Line 37: | Line 37: | ||
g_TEPlayerAnimEvent.m_nData = nData; | g_TEPlayerAnimEvent.m_nData = nData; | ||
g_TEPlayerAnimEvent.Create( filter, 0 ); | g_TEPlayerAnimEvent.Create( filter, 0 ); | ||
} | } | ||
</source> | </source> | ||
Line 80: | Line 73: | ||
RecvPropInt( RECVINFO( m_nData ) ) | RecvPropInt( RECVINFO( m_nData ) ) | ||
END_RECV_TABLE() | END_RECV_TABLE() | ||
</source> | </source> | ||
<< [[m_PlayerAnimState|Return to m_PlayerAnimState]] {{DISPLAYTITLE:m_PlayerAnimState/TempEnt}} | << [[m_PlayerAnimState|Return to m_PlayerAnimState]] {{DISPLAYTITLE:m_PlayerAnimState/TempEnt}} |
Latest revision as of 09:54, 18 June 2024
This temporary entity will dispatch player animation events to onlooking clients in the animating player's PVS. It is not needed in singleplayer.
The code can go anywhere, but your player CPP files are the best location. Dispatch it from your player's DoAnimationEvent()
function (before or after calling into the serverside AnimState).
Server
class CTEPlayerAnimEvent : public CBaseTempEntity
{
public:
DECLARE_CLASS( CTEPlayerAnimEvent, CBaseTempEntity );
DECLARE_SERVERCLASS();
CTEPlayerAnimEvent( const char* name ) : CBaseTempEntity( name ) {}
CNetworkHandle( CBasePlayer, m_hPlayer );
CNetworkVar( int, m_iEvent );
CNetworkVar( int, m_nData );
};
IMPLEMENT_SERVERCLASS_ST_NOBASE( CTEPlayerAnimEvent, DT_TEPlayerAnimEvent )
SendPropEHandle( SENDINFO( m_hPlayer ) ),
SendPropInt( SENDINFO( m_iEvent ), Q_log2( PLAYERANIMEVENT_COUNT ) + 1, SPROP_UNSIGNED ),
SendPropInt( SENDINFO( m_nData ), 32 )
END_SEND_TABLE()
static CTEPlayerAnimEvent g_TEPlayerAnimEvent( "PlayerAnimEvent" );
void TE_PlayerAnimEvent( CBasePlayer* pPlayer, PlayerAnimEvent_t event, int nData )
{
CPVSFilter filter( (const Vector&)pPlayer->EyePosition() );
//Tony; use prediction rules.
filter.UsePredictionRules();
g_TEPlayerAnimEvent.m_hPlayer = pPlayer;
g_TEPlayerAnimEvent.m_iEvent = event;
g_TEPlayerAnimEvent.m_nData = nData;
g_TEPlayerAnimEvent.Create( filter, 0 );
}
Client
#include "c_basetempentity.h"
#include "prediction.h"
class C_TEPlayerAnimEvent : public C_BaseTempEntity
{
public:
DECLARE_CLASS( C_TEPlayerAnimEvent, C_BaseTempEntity );
DECLARE_CLIENTCLASS();
virtual void PostDataUpdate( DataUpdateType_t updateType )
{
// Create the effect.
C_MyPlayer* pPlayer = (C_MyPlayer*)m_hPlayer.Get();
if ( pPlayer && !pPlayer->IsDormant() )
pPlayer->DoAnimationEvent( (PlayerAnimEvent_t)m_iEvent.Get(), m_nData )
}
public:
CNetworkHandle( CBasePlayer, m_hPlayer );
CNetworkVar( int, m_iEvent );
CNetworkVar( int, m_nData );
};
IMPLEMENT_CLIENTCLASS_EVENT( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent, CTEPlayerAnimEvent );
BEGIN_RECV_TABLE_NOBASE( C_TEPlayerAnimEvent, DT_TEPlayerAnimEvent )
RecvPropEHandle( RECVINFO( m_hPlayer ) ),
RecvPropInt( RECVINFO( m_iEvent ) ),
RecvPropInt( RECVINFO( m_nData ) )
END_RECV_TABLE()