Advertisement
RanAway

[ Pawn ] Player models menu

May 27th, 2022
594
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 ] = 0
  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", "ModelsMenu" )
  32.    
  33.     /************* Spawning ***************/
  34.     RegisterHam( Ham_Spawn, "player", "Spawning", 1 )
  35.    
  36.     /*********** Load the models **************/
  37.     LoadModels()
  38. }
  39.  
  40. /************* Connecting / Disconnecting ***************/
  41. public client_putinserver( id ) return Load( id )
  42. public client_disconnect( id ) return Save( id )
  43.  
  44. /************* Precache ***************/
  45. public plugin_precache()
  46. {
  47.     new szItem[ 256 ]
  48.    
  49.     for( new i; i < ModelsLoaded; i++ )
  50.     {
  51.         formatex( szItem, charsmax( szItem ), "models/player/%s/%s.mdl", Models[ i ][ file_name ], Models[ i ][ file_name ] )
  52.         precache_model( szItem )
  53.     }
  54. }
  55.  
  56. /************* Spawning ***************/
  57. public Spawning( id )
  58. {
  59.     if( !is_user_connected( id ) || !is_user_alive( id ) ) return 1
  60.    
  61.     if( cs_get_user_team( id ) & CS_TEAM_CT ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
  62.     if( cs_get_user_team( id ) & CS_TEAM_T ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
  63.    
  64.     return 1
  65. }
  66.  
  67. /************* Models menu ***************/
  68. public ModelsMenu( id )
  69. {
  70.     new szMenu[ 250 ]
  71.    
  72.     formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Choose player model for yourself^n\d-\w Your current model \d-\r %s", Prefix, Models[ MyChoose[ id ] ][ name ] )
  73.     new menu = menu_create( szMenu, "sub_playermodels" )
  74.    
  75.     for( new i; i < ModelsLoaded; i++ )
  76.     {
  77.         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]" : "" )
  78.         menu_additem( menu, szMenu, .callback = menu_makecallback( "blockadmin" ) )
  79.     }
  80.    
  81.     menu_display( id, menu )
  82.     return 1
  83. }
  84.  
  85. public blockadmin( id, menu, item )
  86. {
  87.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) && Models[ item ][ AdminAccess ] == 0 )
  88.         return ITEM_DISABLED
  89.    
  90.     return 0
  91. }
  92.  
  93. public sub_playermodels( id, menu, item )
  94. {
  95.     if( item == MENU_EXIT ) return menu_destroy( menu )
  96.    
  97.     MyChoose[ id ] = item
  98.    
  99.     if( is_user_connected( id ) && is_user_alive( id ) )
  100.         cs_set_user_model( id, Models[ item ][ file_name ] )
  101.    
  102.     ColorChat( id, "You changed your player model to: ^3%s", Models[ item ][ name ] )
  103.    
  104.     Save( id )
  105.     return ModelsMenu( id )
  106. }
  107.  
  108. /************* Load models ***************/
  109. public LoadModels()
  110. {
  111.     if( !file_exists( ModelsCfgFile ) )
  112.     {
  113.         write_file( ModelsCfgFile, "; model name                    file name               access^n" )
  114.         write_file( ModelsCfgFile, "; Model name in menu - The name that will appear in the menu and chat" )
  115.         write_file( ModelsCfgFile, "; File name - The name of the model file [ Folder and the mdl must be with the same name ]")
  116.         write_file( ModelsCfgFile, "; Access - If the model will be only for admin or not [ ^"0^" for not / ^"^" for admin ]^n")
  117.         write_file( ModelsCfgFile, "; Example - ^"Shadow the hedgehog^"     ^"Shadow^"              ^"0^"")
  118.         log_message("[ models ] Failed to load file models.txt.")
  119.         pause( "a" )
  120.         return 1
  121.     }
  122.    
  123.     if( file_exists( ModelsCfgFile ) )
  124.     {
  125.         new text[ 64 ]
  126.         new file = fopen( ModelsCfgFile, "rt" )
  127.        
  128.         while( !feof( file ) )
  129.         {
  130.             fgets( file, text, charsmax( text ) )
  131.             trim( text )
  132.            
  133.             if( text[ 0 ] == ';' || !text[ 0 ] )
  134.                 continue
  135.            
  136.             parse( text, Models[ ModelsLoaded ][ name ], 31, Models[ ModelsLoaded ][ file_name ], 31, Models[ ModelsLoaded ][ AdminAccess ], 31 )
  137.             replace_all( Models[ ModelsLoaded ][ name ], 31, "_", " " )
  138.            
  139.             ModelsLoaded++
  140.         }
  141.        
  142.         fclose( file )
  143.     }
  144.    
  145.     return 1
  146. }
  147.  
  148. /************* Save / Load ***************/
  149. stock Save( id )
  150. {
  151.     new szData[ 256 ]
  152.    
  153.     formatex( szData, charsmax( szData ), "%i %s", MyChoose[ id ], GetName( id ) )
  154.     fvault_set_data( Vault, GetAuth( id ), szData )
  155.    
  156.     return 1
  157. }
  158.  
  159. stock Load( id )
  160. {
  161.     new szData[ 256 ], Data[ 1 ][ 32 ]
  162.    
  163.     formatex( szData, charsmax( szData ), "%i", MyChoose[ id ] )
  164.     fvault_get_data( Vault, GetAuth( id ), szData, charsmax( szData ) )
  165.    
  166.     parse( szData, Data[ 0 ], charsmax( Data ) )
  167.    
  168.     MyChoose[ id ] = str_to_num( Data[ 0 ] )
  169.    
  170.     return 1
  171. }
  172.  
  173. /************* Stocks ***************/
  174. stock GetName( id )
  175. {
  176.     static szName[ 33 ]
  177.     get_user_name( id, szName, charsmax( szName ) )
  178.     return szName
  179. }
  180.  
  181. stock GetAuth( id )
  182. {
  183.     static szAuth[ 35 ]
  184.     get_user_authid( id, szAuth, charsmax( szAuth ) )
  185.     return szAuth
  186. }
  187.  
  188. stock ColorChat( const client, const string[ ], { Float, Sql, Resul,_ }:... )
  189. {
  190.     new msg[ 191 ], players[ 32 ], count = 1
  191.    
  192.     static len; len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
  193.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  194.    
  195.     if( client )
  196.         players[ 0 ] = client
  197.     else
  198.         get_players( players, count, "ch" )
  199.    
  200.     for( new i; i < count; i++ )
  201.     {
  202.         if( is_user_connected( players[ i ] ) )
  203.         {
  204.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
  205.             write_byte( players[ i ] )
  206.             write_string( msg )
  207.             message_end()
  208.         }
  209.     }
  210.     return 1
  211. }
Advertisement
RAW Paste Data Copied
Advertisement