Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "amxxmodule.h"
- class Player {
- private:
- bool Initialized;
- bool Connected;
- bool HasCustomModel;
- size_t Index;
- edict_t * pEntity;
- public:
- void SetCustomModel( char * pModel ) {
- SET_CLIENT_KEYVALUE( Index, GET_INFOKEYBUFFER( pEntity ), "model", pModel );
- HasCustomModel = true;
- }
- void ResetCustomModel( void ) {
- SET_CLIENT_KEYVALUE( Index, GET_INFOKEYBUFFER( pEntity ), "model", "gordon" );
- HasCustomModel = false;
- }
- void OnConnect( void ) {
- Initialized = true;
- Connected = false;
- HasCustomModel = false;
- }
- void OnDisconnect( void ) {
- Initialized = false;
- Connected = false;
- HasCustomModel = false;
- }
- void OnJoin( void ) {
- Initialized = true;
- Connected = true;
- HasCustomModel = false;
- }
- void OnServerActivate( size_t GivenIndex, edict_t * pGivenEntity ) {
- Index = GivenIndex;
- pEntity = pGivenEntity;
- }
- edict_t * GetEdict( void ) {
- return pEntity;
- }
- bool OwnsCustomModel( void ) {
- return HasCustomModel;
- }
- bool IsConnected( void ) {
- return Connected;
- }
- bool IsInitialized( void ) {
- return Initialized;
- }
- };
- Player g_Players[ 33 ];
- cell AMX_NATIVE_CALL get_user_model( AMX * pHandle, cell * pParameters ) {
- static size_t Client;
- Client = pParameters[ 1 ];
- if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
- return 0;
- }
- else if( !g_Players[ Client ].IsConnected( ) ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
- return 0;
- }
- MF_SetAmxString( pHandle, pParameters[ 2 ], INFOKEY_VALUE( GET_INFOKEYBUFFER( g_Players[ Client ].GetEdict( ) ), "model" ), pParameters[ 3 ] );
- return 1;
- }
- cell AMX_NATIVE_CALL set_user_model( AMX * pHandle, cell * pParameters ) {
- static size_t Client;
- Client = pParameters[ 1 ];
- if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
- return 0;
- }
- else if( !g_Players[ Client ].IsConnected( ) ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
- return 0;
- }
- g_Players[ Client ].SetCustomModel( MF_GetAmxString( pHandle, pParameters[ 2 ], 0, NULL ) );
- return 1;
- }
- cell AMX_NATIVE_CALL reset_user_model( AMX * pHandle, cell * pParameters ) {
- static size_t Client;
- if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
- return 0;
- }
- else if( !g_Players[ Client ].IsConnected( ) ) {
- MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
- return 0;
- }
- g_Players[ Client ].ResetCustomModel( );
- return 1;
- }
- AMX_NATIVE_INFO g_ModelChangerFunctions[ ] = {
- { "get_user_model", get_user_model },
- { "set_user_model", set_user_model },
- { "reset_user_model", reset_user_model },
- { NULL, NULL }
- };
- void ServerActivate_Post( edict_t * pEntity, int, int ) {
- static size_t Client;
- for( Client = 1; Client <= ( size_t ) gpGlobals -> maxClients; Client ++ )
- g_Players[ Client ].OnServerActivate( Client, Client + pEntity );
- RETURN_META( MRES_IGNORED );
- }
- void ClientPutInServer( edict_t * pEntity ) {
- static size_t Client;
- Client = ( size_t ) ENTINDEX( pEntity );
- g_Players[ Client ].OnJoin( );
- RETURN_META( MRES_IGNORED );
- }
- void ClientDisconnect( edict_t * pEntity ) {
- static size_t Client;
- Client = ( size_t ) ENTINDEX( pEntity );
- if( g_Players[ Client ].IsInitialized( ) )
- g_Players[ Client ].OnDisconnect( );
- RETURN_META( MRES_IGNORED );
- }
- qboolean ClientConnect_Post( edict_t * pEntity, const char *, const char *, char * ) {
- static size_t Client;
- Client = ( size_t ) ENTINDEX( pEntity );
- g_Players[ Client ].OnConnect( );
- RETURN_META_VALUE( MRES_IGNORED, 0 );
- }
- void SetClientKeyValue( int Client, char *, char * pKey, char * ) {
- RETURN_META( g_Players[ Client ].OwnsCustomModel( ) && !strcmp( pKey, "model" ) ? MRES_SUPERCEDE : MRES_IGNORED );
- }
- void OnAmxxAttach( void ) {
- MF_AddNatives( g_ModelChangerFunctions );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement