Advertisement
Guest User

Model Changer

a guest
Apr 20th, 2013
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 KB | None | 0 0
  1. #include "amxxmodule.h"
  2.  
  3. class Player {
  4. private:
  5.     bool Initialized;
  6.     bool Connected;
  7.     bool HasCustomModel;
  8.     size_t Index;
  9.     edict_t * pEntity;
  10.  
  11. public:
  12.     void SetCustomModel( char * pModel ) {
  13.         SET_CLIENT_KEYVALUE( Index, GET_INFOKEYBUFFER( pEntity ), "model", pModel );
  14.  
  15.         HasCustomModel = true;
  16.     }
  17.  
  18.     void ResetCustomModel( void ) {
  19.         SET_CLIENT_KEYVALUE( Index, GET_INFOKEYBUFFER( pEntity ), "model", "gordon" );
  20.  
  21.         HasCustomModel = false;
  22.     }
  23.  
  24.     void OnConnect( void ) {
  25.         Initialized = true;
  26.  
  27.         Connected = false;
  28.  
  29.         HasCustomModel = false;
  30.     }
  31.  
  32.     void OnDisconnect( void ) {
  33.         Initialized = false;
  34.  
  35.         Connected = false;
  36.  
  37.         HasCustomModel = false;
  38.     }
  39.  
  40.     void OnJoin( void ) {
  41.         Initialized = true;
  42.  
  43.         Connected = true;
  44.  
  45.         HasCustomModel = false;
  46.     }
  47.  
  48.     void OnServerActivate( size_t GivenIndex, edict_t * pGivenEntity ) {
  49.         Index = GivenIndex;
  50.  
  51.         pEntity = pGivenEntity;
  52.     }
  53.  
  54.     edict_t * GetEdict( void ) {
  55.         return pEntity;
  56.     }
  57.  
  58.     bool OwnsCustomModel( void ) {
  59.         return HasCustomModel;
  60.     }
  61.  
  62.     bool IsConnected( void ) {
  63.         return Connected;
  64.     }
  65.  
  66.     bool IsInitialized( void ) {
  67.         return Initialized;
  68.     }
  69. };
  70.  
  71. Player g_Players[ 33 ];
  72.  
  73. cell AMX_NATIVE_CALL get_user_model( AMX * pHandle, cell * pParameters ) {
  74.     static size_t Client;
  75.  
  76.     Client = pParameters[ 1 ];
  77.  
  78.     if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
  79.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
  80.  
  81.         return 0;
  82.     }
  83.  
  84.     else if( !g_Players[ Client ].IsConnected( ) ) {
  85.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
  86.  
  87.         return 0;
  88.     }
  89.  
  90.     MF_SetAmxString( pHandle, pParameters[ 2 ], INFOKEY_VALUE( GET_INFOKEYBUFFER( g_Players[ Client ].GetEdict( ) ), "model" ), pParameters[ 3 ] );
  91.  
  92.     return 1;
  93. }
  94.  
  95. cell AMX_NATIVE_CALL set_user_model( AMX * pHandle, cell * pParameters ) {
  96.     static size_t Client;
  97.  
  98.     Client = pParameters[ 1 ];
  99.  
  100.     if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
  101.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
  102.  
  103.         return 0;
  104.     }
  105.  
  106.     else if( !g_Players[ Client ].IsConnected( ) ) {
  107.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
  108.  
  109.         return 0;
  110.     }
  111.  
  112.     g_Players[ Client ].SetCustomModel( MF_GetAmxString( pHandle, pParameters[ 2 ], 0, NULL ) );
  113.  
  114.     return 1;
  115. }
  116.  
  117. cell AMX_NATIVE_CALL reset_user_model( AMX * pHandle, cell * pParameters ) {
  118.     static size_t Client;
  119.  
  120.     if( Client < 1 || Client > ( size_t ) gpGlobals -> maxClients ) {
  121.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is invalid!", Client );
  122.  
  123.         return 0;
  124.     }
  125.  
  126.     else if( !g_Players[ Client ].IsConnected( ) ) {
  127.         MF_LogError( pHandle, AMX_ERR_NATIVE, "Client %d is not connected!", Client );
  128.  
  129.         return 0;
  130.     }
  131.  
  132.     g_Players[ Client ].ResetCustomModel( );
  133.  
  134.     return 1;
  135. }
  136.  
  137. AMX_NATIVE_INFO g_ModelChangerFunctions[ ] = {
  138.     { "get_user_model", get_user_model },
  139.     { "set_user_model", set_user_model },
  140.     { "reset_user_model", reset_user_model },
  141.  
  142.     { NULL, NULL }
  143. };
  144.  
  145. void ServerActivate_Post( edict_t * pEntity, int, int ) {
  146.     static size_t Client;
  147.  
  148.     for( Client = 1; Client <= ( size_t ) gpGlobals -> maxClients; Client ++ )
  149.         g_Players[ Client ].OnServerActivate( Client, Client + pEntity );
  150.  
  151.     RETURN_META( MRES_IGNORED );
  152. }
  153.  
  154. void ClientPutInServer( edict_t * pEntity ) {
  155.     static size_t Client;
  156.  
  157.     Client = ( size_t ) ENTINDEX( pEntity );
  158.  
  159.     g_Players[ Client ].OnJoin( );
  160.  
  161.     RETURN_META( MRES_IGNORED );
  162. }
  163.  
  164. void ClientDisconnect( edict_t * pEntity ) {
  165.     static size_t Client;
  166.  
  167.     Client = ( size_t ) ENTINDEX( pEntity );
  168.  
  169.     if( g_Players[ Client ].IsInitialized( ) )
  170.         g_Players[ Client ].OnDisconnect( );
  171.  
  172.     RETURN_META( MRES_IGNORED );
  173. }
  174.  
  175. qboolean ClientConnect_Post( edict_t * pEntity, const char *, const char *, char * ) {
  176.     static size_t Client;
  177.  
  178.     Client = ( size_t ) ENTINDEX( pEntity );
  179.  
  180.     g_Players[ Client ].OnConnect( );
  181.  
  182.     RETURN_META_VALUE( MRES_IGNORED, 0 );
  183. }
  184.  
  185. void SetClientKeyValue( int Client, char *, char * pKey, char * ) {
  186.     RETURN_META( g_Players[ Client ].OwnsCustomModel( ) && !strcmp( pKey, "model" ) ? MRES_SUPERCEDE : MRES_IGNORED );
  187. }
  188.  
  189. void OnAmxxAttach( void ) {
  190.     MF_AddNatives( g_ModelChangerFunctions );
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement