Advertisement
RanAway

[ Pawn ] Player models menu

May 27th, 2022 (edited)
1,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.32 KB | None | 0 0
  1. /************* Includes ***************/
  2. #include < amxmodx >
  3. #include < cstrike >
  4. #include < fvault >
  5. #include < hamsandwich >
  6.  
  7. /************* Defines ***************/
  8. #define ModelsCfgFile   "addons/amxmodx/configs/models.ini"
  9.  
  10. #define Prefix      "AMXX"
  11. #define Vault       "Models"
  12.  
  13. #define ADMIN_ACCESS    ADMIN_IMMUNITY
  14.  
  15. /************* Models ***************/
  16. enum _:ModelsProperties
  17. {
  18.     name[ 31 ],
  19.     file_name[ 120 ],
  20.     AdminAccess
  21. }
  22.  
  23. new Models[ 120 ][ ModelsProperties ], ModelsLoaded = 0, MyChoose[ 33 ], ModelStatus[ 33 ]
  24.  
  25. /************* Plugin init ***************/
  26. public plugin_init()
  27. {
  28.     register_plugin( "Player models", "v1.0", "RanAway`" )
  29.    
  30.     /************* Commands ***************/
  31.     register_clcmd( "say /models", "ModelsPre" )
  32.    
  33.     /************* Spawning ***************/
  34.     RegisterHam( Ham_Spawn, "player", "Spawning", 1 )
  35. }
  36.  
  37. /************* Connecting / Disconnecting ***************/
  38. public client_putinserver( id ) return Load( id )
  39. public client_disconnect( id ) return Save( id )
  40.  
  41. /************* Precache ***************/
  42. public plugin_precache()
  43. {
  44.     LoadModels()
  45.    
  46.     new szItem[ 256 ]
  47.    
  48.     if( ModelsLoaded == 0 )
  49.         return 1
  50.    
  51.     for( new i; i < ModelsLoaded; i++ )
  52.     {
  53.         formatex( szItem, charsmax( szItem ), "models/player/%s/%s.mdl", Models[ i ][ file_name ], Models[ i ][ file_name ] )
  54.         precache_model( szItem )
  55.     }
  56.    
  57.     return 1
  58. }
  59.  
  60. /************* Spawning ***************/
  61. public Spawning( id )
  62. {
  63.     if( !is_user_connected( id ) || !is_user_alive( id ) ) return 1
  64.    
  65.     if( cs_get_user_team( id ) & CS_TEAM_CT ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
  66.     if( cs_get_user_team( id ) & CS_TEAM_T ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
  67.    
  68.     return 1
  69. }
  70.  
  71. /************* Models menu ***************/
  72. public ModelsPre( id ) return ModelsMenu( id, 0 )
  73. public ModelsMenu( id, page )
  74. {
  75.     new szMenu[ 250 ]
  76.    
  77.     formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Choose player model for yourself \r[\w %d \r]^n\d-\w %s %s", Prefix, ModelsLoaded, ModelsLoaded <= 0 ? "There is no models yet" : "Your current model is:", Models[ MyChoose[ id ] ][ name ] )
  78.     new menu = menu_create( szMenu, "sub_playermodels" )
  79.    
  80.     formatex( szMenu, charsmax( szMenu ), "My models status is: \r%svisible \r(\w cl_minmodels \r)^n^n", ModelStatus[ id ] ? "\dIn" : "\y" )
  81.     menu_additem( menu, szMenu )
  82.    
  83.     for( new i; i < ModelsLoaded; i++ )
  84.     {
  85.         formatex( szMenu, charsmax( szMenu ), "%s%s%s", Models[ i ][ name ], Models[ i ][ AdminAccess ] == 0 ? " \d- \rOwner only" : "", i == MyChoose[ id ] ? " \r[\w Your model \r]" : "" )
  86.         menu_additem( menu, szMenu, .callback = menu_makecallback( "blockadmin" ) )
  87.     }
  88.    
  89.     menu_display( id, menu, page )
  90.     return 1
  91. }
  92.  
  93. public blockadmin( id, menu, item )
  94. {
  95.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) && Models[ item ][ AdminAccess ] == 0 )
  96.         return ITEM_DISABLED
  97.    
  98.     return 0
  99. }
  100.  
  101. public sub_playermodels( id, menu, item )
  102. {
  103.     if( item == MENU_EXIT ) return menu_destroy( menu )
  104.    
  105.     new access, callback, info[ 6 ], page
  106.     menu_item_getinfo( menu, item, access, info, charsmax( info ), "", 0, callback )
  107.     player_menu_info( id, menu, menu, page )
  108.    
  109.     if( item == 0 )
  110.     {
  111.         ModelStatus[ id ] = !ModelStatus[ id ]
  112.         client_cmd( id, "cl_minmodels %s", ModelStatus[ id ] ? "1" : "0" )
  113.        
  114.         ColorChat( id, "Custom player models will be ^3%s^1 to you.", ModelStatus[ id ] ? "hidden" : "shown" )
  115.        
  116.         return ModelsMenu( id, page )
  117.     }
  118.    
  119.     MyChoose[ id ] = item - 1
  120.    
  121.     if( is_user_connected( id ) && is_user_alive( id ) )
  122.         cs_set_user_model( id, Models[ item - 1 ][ file_name ] )
  123.    
  124.     ColorChat( id, "You changed your player model to: ^3%s^1.", Models[ item - 1 ][ name ] )
  125.    
  126.     Save( id )
  127.     return ModelsMenu( id, page )
  128. }
  129.  
  130. /************* Load models ***************/
  131. public LoadModels()
  132. {
  133.     if( !file_exists( ModelsCfgFile ) )
  134.     {
  135.         write_file( ModelsCfgFile, "; model name                    file name               access^n" )
  136.         write_file( ModelsCfgFile, "; Model name in menu - The name that will appear in the menu and chat" )
  137.         write_file( ModelsCfgFile, "; File name - The name of the model file [ Folder and the mdl must be with the same name ]")
  138.         write_file( ModelsCfgFile, "; Access - If the model will be only for admin or not [ ^"0^" for not / ^"^" for admin ]^n")
  139.         write_file( ModelsCfgFile, "; Example - ^"Shadow the hedgehog^"     ^"Shadow^"              ^"0^"")
  140.         log_message("[ models ] Failed to load file models.txt.")
  141.         pause( "a" )
  142.         return 1
  143.     }
  144.    
  145.     if( file_exists( ModelsCfgFile ) )
  146.     {
  147.         new text[ 64 ]
  148.         new file = fopen( ModelsCfgFile, "rt" )
  149.        
  150.         while( !feof( file ) )
  151.         {
  152.             fgets( file, text, charsmax( text ) )
  153.             trim( text )
  154.            
  155.             if( text[ 0 ] == ';' || !text[ 0 ] )
  156.                 continue
  157.            
  158.             parse( text, Models[ ModelsLoaded ][ name ], charsmax( Models ), Models[ ModelsLoaded ][ file_name ], charsmax( Models ), Models[ ModelsLoaded ][ AdminAccess ], charsmax( Models ) )
  159.            
  160.             ModelsLoaded++
  161.         }
  162.        
  163.         fclose( file )
  164.     }
  165.    
  166.     return 1
  167. }
  168.  
  169. /************* Save / Load ***************/
  170. stock Save( id )
  171. {
  172.     new szData[ 256 ]
  173.    
  174.     formatex( szData, charsmax( szData ), "%d %s", MyChoose[ id ], GetName( id ) )
  175.     fvault_set_data( Vault, GetAuth( id ), szData )
  176.    
  177.     return 1
  178. }
  179.  
  180. stock Load( id )
  181. {
  182.     new szData[ 256 ], Data[ 1 ][ 32 ]
  183.    
  184.     formatex( szData, charsmax( szData ), "%d", MyChoose[ id ] )
  185.     fvault_get_data( Vault, GetAuth( id ), szData, charsmax( szData ) )
  186.    
  187.     parse( szData, Data[ 0 ], charsmax( Data ) )
  188.    
  189.     MyChoose[ id ] = str_to_num( Data[ 0 ] )
  190.    
  191.     return 1
  192. }
  193.  
  194. /************* Stocks ***************/
  195. stock GetName( id )
  196. {
  197.     static szName[ 33 ]
  198.     get_user_name( id, szName, charsmax( szName ) )
  199.     return szName
  200. }
  201.  
  202. stock GetAuth( id )
  203. {
  204.     static szAuth[ 35 ]
  205.     get_user_authid( id, szAuth, charsmax( szAuth ) )
  206.     return szAuth
  207. }
  208.  
  209. stock ColorChat( const client, const string[ ], { Float, Sql, Resul,_ }:... )
  210. {
  211.     new msg[ 191 ], players[ 32 ], count = 1
  212.    
  213.     static len; len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
  214.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  215.    
  216.     if( client )
  217.         players[ 0 ] = client
  218.     else
  219.         get_players( players, count, "ch" )
  220.    
  221.     for( new i; i < count; i++ )
  222.     {
  223.         if( is_user_connected( players[ i ] ) )
  224.         {
  225.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
  226.             write_byte( players[ i ] )
  227.             write_string( msg )
  228.             message_end()
  229.         }
  230.     }
  231.     return 1
  232. }
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement