Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************* Includes ***************/
- #include < amxmodx >
- #include < cstrike >
- #include < fvault >
- #include < hamsandwich >
- /************* Defines ***************/
- #define ModelsCfgFile "addons/amxmodx/configs/models.ini"
- #define Prefix "AMXX"
- #define Vault "Models"
- #define ADMIN_ACCESS ADMIN_IMMUNITY
- /************* Models ***************/
- enum _:ModelsProperties
- {
- name[ 31 ],
- file_name[ 120 ],
- AdminAccess
- }
- new Models[ 120 ][ ModelsProperties ], ModelsLoaded = 0, MyChoose[ 33 ], ModelStatus[ 33 ]
- /************* Plugin init ***************/
- public plugin_init()
- {
- register_plugin( "Player models", "v1.0", "RanAway`" )
- /************* Commands ***************/
- register_clcmd( "say /models", "ModelsPre" )
- /************* Spawning ***************/
- RegisterHam( Ham_Spawn, "player", "Spawning", 1 )
- }
- /************* Connecting / Disconnecting ***************/
- public client_putinserver( id ) return Load( id )
- public client_disconnect( id ) return Save( id )
- /************* Precache ***************/
- public plugin_precache()
- {
- LoadModels()
- new szItem[ 256 ]
- if( ModelsLoaded == 0 )
- return 1
- for( new i; i < ModelsLoaded; i++ )
- {
- formatex( szItem, charsmax( szItem ), "models/player/%s/%s.mdl", Models[ i ][ file_name ], Models[ i ][ file_name ] )
- precache_model( szItem )
- }
- return 1
- }
- /************* Spawning ***************/
- public Spawning( id )
- {
- if( !is_user_connected( id ) || !is_user_alive( id ) ) return 1
- if( cs_get_user_team( id ) & CS_TEAM_CT ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
- if( cs_get_user_team( id ) & CS_TEAM_T ) cs_set_user_model( id, Models[ MyChoose[ id ] ][ file_name ] )
- return 1
- }
- /************* Models menu ***************/
- public ModelsPre( id ) return ModelsMenu( id, 0 )
- public ModelsMenu( id, page )
- {
- new szMenu[ 250 ]
- 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 ] )
- new menu = menu_create( szMenu, "sub_playermodels" )
- formatex( szMenu, charsmax( szMenu ), "My models status is: \r%svisible \r(\w cl_minmodels \r)^n^n", ModelStatus[ id ] ? "\dIn" : "\y" )
- menu_additem( menu, szMenu )
- for( new i; i < ModelsLoaded; i++ )
- {
- 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]" : "" )
- menu_additem( menu, szMenu, .callback = menu_makecallback( "blockadmin" ) )
- }
- menu_display( id, menu, page )
- return 1
- }
- public blockadmin( id, menu, item )
- {
- if( !( get_user_flags( id ) & ADMIN_ACCESS ) && Models[ item ][ AdminAccess ] == 0 )
- return ITEM_DISABLED
- return 0
- }
- public sub_playermodels( id, menu, item )
- {
- if( item == MENU_EXIT ) return menu_destroy( menu )
- new access, callback, info[ 6 ], page
- menu_item_getinfo( menu, item, access, info, charsmax( info ), "", 0, callback )
- player_menu_info( id, menu, menu, page )
- if( item == 0 )
- {
- ModelStatus[ id ] = !ModelStatus[ id ]
- client_cmd( id, "cl_minmodels %s", ModelStatus[ id ] ? "1" : "0" )
- ColorChat( id, "Custom player models will be ^3%s^1 to you.", ModelStatus[ id ] ? "hidden" : "shown" )
- return ModelsMenu( id, page )
- }
- MyChoose[ id ] = item - 1
- if( is_user_connected( id ) && is_user_alive( id ) )
- cs_set_user_model( id, Models[ item - 1 ][ file_name ] )
- ColorChat( id, "You changed your player model to: ^3%s^1.", Models[ item - 1 ][ name ] )
- Save( id )
- return ModelsMenu( id, page )
- }
- /************* Load models ***************/
- public LoadModels()
- {
- if( !file_exists( ModelsCfgFile ) )
- {
- write_file( ModelsCfgFile, "; model name file name access^n" )
- write_file( ModelsCfgFile, "; Model name in menu - The name that will appear in the menu and chat" )
- write_file( ModelsCfgFile, "; File name - The name of the model file [ Folder and the mdl must be with the same name ]")
- write_file( ModelsCfgFile, "; Access - If the model will be only for admin or not [ ^"0^" for not / ^"^" for admin ]^n")
- write_file( ModelsCfgFile, "; Example - ^"Shadow the hedgehog^" ^"Shadow^" ^"0^"")
- log_message("[ models ] Failed to load file models.txt.")
- pause( "a" )
- return 1
- }
- if( file_exists( ModelsCfgFile ) )
- {
- new text[ 64 ]
- new file = fopen( ModelsCfgFile, "rt" )
- while( !feof( file ) )
- {
- fgets( file, text, charsmax( text ) )
- trim( text )
- if( text[ 0 ] == ';' || !text[ 0 ] )
- continue
- parse( text, Models[ ModelsLoaded ][ name ], charsmax( Models ), Models[ ModelsLoaded ][ file_name ], charsmax( Models ), Models[ ModelsLoaded ][ AdminAccess ], charsmax( Models ) )
- ModelsLoaded++
- }
- fclose( file )
- }
- return 1
- }
- /************* Save / Load ***************/
- stock Save( id )
- {
- new szData[ 256 ]
- formatex( szData, charsmax( szData ), "%d %s", MyChoose[ id ], GetName( id ) )
- fvault_set_data( Vault, GetAuth( id ), szData )
- return 1
- }
- stock Load( id )
- {
- new szData[ 256 ], Data[ 1 ][ 32 ]
- formatex( szData, charsmax( szData ), "%d", MyChoose[ id ] )
- fvault_get_data( Vault, GetAuth( id ), szData, charsmax( szData ) )
- parse( szData, Data[ 0 ], charsmax( Data ) )
- MyChoose[ id ] = str_to_num( Data[ 0 ] )
- return 1
- }
- /************* Stocks ***************/
- stock GetName( id )
- {
- static szName[ 33 ]
- get_user_name( id, szName, charsmax( szName ) )
- return szName
- }
- stock GetAuth( id )
- {
- static szAuth[ 35 ]
- get_user_authid( id, szAuth, charsmax( szAuth ) )
- return szAuth
- }
- stock ColorChat( const client, const string[ ], { Float, Sql, Resul,_ }:... )
- {
- new msg[ 191 ], players[ 32 ], count = 1
- static len; len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
- vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
- if( client )
- players[ 0 ] = client
- else
- get_players( players, count, "ch" )
- for( new i; i < count; i++ )
- {
- if( is_user_connected( players[ i ] ) )
- {
- message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
- write_byte( players[ i ] )
- write_string( msg )
- message_end()
- }
- }
- return 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement