Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************** Include *******************/
- #include < amxmodx >
- #include < amxmisc >
- #include < colorchat >
- /****************** Defines *******************/
- #define Prefix "AMXX"
- #define SpeechFile "addons/amxmodx/configs/newspeech.ini"
- /****************** Speech *******************/
- enum _:Properties
- {
- SoundName[ 31 ],
- file_name[ 120 ],
- AdminAccess
- }
- new Speech[ 120 ][ Properties ], SpeechLoaded = 0
- /****************** Volume *******************/
- new const Volume[] [] =
- {
- "[\r----------\w]",
- "[\y+\r---------\w]",
- "[\y++\r--------\w]",
- "[\y+++\r-------\w]",
- "[\y++++\r------\w]",
- "[\y+++++\r-----\w]",
- "[\y++++++\r----\w]",
- "[\y+++++++\r---\w]",
- "[\y++++++++\r--\w]",
- "[\y+++++++++\r-\w]",
- "[\y++++++++++\w]"
- }
- new Float: Mp3value[ 33 ], VolumeCTRL[ 33 ]
- /****************** News *******************/
- new MenuPage[ 33 ]
- /****************** Plugin init *******************/
- public plugin_init()
- {
- register_plugin( "SpeechStandAlone", "v1.0", "AMXX Devs team | RanAway`" )
- /****************** Speech *******************/
- register_clcmd( "amx_speech", "BeforeSpeech" )
- register_menucmd( register_menuid( "sub_menu" ), 1023, "sub_speech" )
- }
- /************** Putinserver **************/
- public client_putinserver( id )
- {
- Mp3value[ id ] = 0.60
- VolumeCTRL[ id ] = 6
- }
- /****************** plugin_precache *******************/
- public plugin_precache()
- {
- LoadSpeech()
- new file = fopen( SpeechFile, "rt" )
- if( !file )
- return 0
- new text[ 256 ], name[ 32 ], sound[ 128 ], sndExt[ 5 ], fieldNums
- new field1[ 32 ], field2[ 64 ], field3[ 64 ]
- while( !feof( file ) )
- {
- fgets( file, text, charsmax( text ) )
- if( text[ 0 ] == ';' || text[ 0 ] == '/' )
- continue
- parse( text, name, charsmax( name ), sound, charsmax( sound ) )
- fieldNums = parse( sound, field1, charsmax( field1 ), field2, charsmax( field2 ), field3, charsmax( field3 ) )
- if( fieldNums == 2 && field1[ 0 ] == 's' ) // .wav ( spk )
- {
- copy( sound, charsmax( sound ), field2 )
- copy( sndExt, charsmax( sndExt ), ".wav" )
- }
- else if( fieldNums == 3 && field1[ 0 ] == 'm' && ( field2[ 0 ] == 'p' || field2[ 0 ] == 'l' ) ) // .mp3 ( mp3 play | mp3 loop )
- {
- copy( sound, charsmax( sound ), field3 )
- copy( sndExt, charsmax( sndExt ), ".mp3" )
- }
- else // WTH is this sound, drop it.
- continue
- if( sndExt[ 1 ] == 'm' || ( ! equali( sound, "vox", 3 ) && ! equali( sound, "fvox", 4 ) && ! equali( sound, "barney", 6 ) && ! equali( sound, "hgrunt", 6 ) ) )
- {
- // sound is a mp3, or a custom wav ( not a vox, fvox, or default sound from HL pak )
- if( !equali( sound[ strlen( sound )-4 ], sndExt ) )
- add( sound, charsmax( sound ), sndExt ) // Add filetype extension if it isn't already specified
- if( sndExt[ 1 ] == 'w' )
- format( sound, charsmax( sound ), "sound/%s", sound ) // spk basedir is $moddir/sound, but mp3 play is $moddir, fix this for the file_exists check
- if( file_exists( sound ) )
- {
- if( sndExt[ 1 ] == 'm' )
- precache_generic( sound ) // mp3
- else
- {
- replace( sound, charsmax( sound ), "sound/", "" ) // wav, strip the leading sound/ we added for our file_exists check
- precache_sound( sound )
- }
- }
- }
- }
- fclose( file )
- return 1
- }
- /****************** Before menu *******************/
- public BeforeSpeech( id )
- {
- if( !( get_user_flags( id ) & ADMIN_MENU ) )
- return 0
- if( SpeechLoaded == 0 )
- {
- ColorChat( id, NORMAL, "^3[^1 %s ^3]^1 There is no ^3speech^1 yet", Prefix )
- return 1
- }
- Speechmenu( id, MenuPage[ id ] = 0 )
- return PLUGIN_HANDLED
- }
- /****************** Speech menu *******************/
- public Speechmenu( id, page )
- {
- if( page < 0 ) return
- new szMenu[ 512 ], b, start = page * 6, keys = MENU_KEY_0|MENU_KEY_7|MENU_KEY_8
- if( start >= SpeechLoaded ) start = page = MenuPage[ id ] = 0
- new limit = SpeechLoaded / 6 + SpeechLoaded % 6
- new len = format( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Speech Menu \r[ \y%d\w Speeches \r]\w\R%d/%d^n^n", Prefix, SpeechLoaded, page + 1, limit == 0 ? 1 : limit )
- new end = start + 6
- if( end > SpeechLoaded ) end = SpeechLoaded
- for( new a = start; a < end; ++a )
- {
- if( !access( id, Speech[ a ][ AdminAccess ] ) )
- len += format( szMenu[ len ], charsmax( szMenu ) -len, "\r%d.\d %s^n", ++b, Speech[ a ][ SoundName ] )
- else
- {
- keys |= ( 1 << b )
- len += format( szMenu[ len ], charsmax( szMenu ) -len, "\r%d.\w %s^n", ++b, Speech[ a ][ SoundName ] )
- }
- }
- len += format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r7. \yVolume. \w%s^n", Volume[ VolumeCTRL[ id ] ] )
- len += format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r8. \wStop sound^n" )
- if( end != SpeechLoaded )
- {
- format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r9.\w Next Page^n\r0.\w %s", page ? "Previous Page" : "Exit" )
- keys |= MENU_KEY_9
- }
- else
- format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r0.\w %s", page ? "Previous Page" : "Exit" )
- show_menu( id, keys, szMenu, -1, "sub_menu" )
- }
- public sub_speech( id, key )
- {
- switch( key )
- {
- case 6:
- {
- if( Mp3value[ id ] > 1.00 )
- Mp3value[ id ] = 0.0
- else
- Mp3value[ id ] += 0.10
- if( VolumeCTRL[ id ] == sizeof Volume - 1 )
- VolumeCTRL[ id] = 0
- else
- VolumeCTRL[ id ]++
- client_cmd( 0, "MP3Volume %.1f", Mp3value[ id ] )
- Speechmenu( id, MenuPage[ id ] )
- }
- case 7:
- {
- client_cmd( 0, "stopsound" )
- client_cmd( 0, "mp3 stop" )
- Speechmenu( id, MenuPage[ id ] )
- }
- case 8: Speechmenu( id, ++MenuPage[ id ] )
- case 9: Speechmenu( id, --MenuPage[ id ] )
- default:
- {
- new option = MenuPage[ id ] * 6 + key
- client_cmd( 0, "%s", Speech[ option ][ file_name ] )
- Speechmenu( id, MenuPage[ id ] )
- }
- }
- return PLUGIN_HANDLED
- }
- /****************** Load speech *******************/
- public LoadSpeech()
- {
- new text[ 256 ]
- if( !file_exists( SpeechFile ) )
- {
- write_file( SpeechFile, "; Name in menu mp3 / spk File location Access^n" )
- write_file( SpeechFile, "; Name in menu - The name that will appear in the menu^n" )
- write_file( SpeechFile, "; mp3 / spk File location - if the sound is mp3 you must write mp3 play before the sound location [ Example ^"mp3 play sound/speech/hello^" ]" )
- write_file( SpeechFile, "; mp3 / spk File location - if the sound is wav you must write spk before the sound location [ Example ^"spk sound/speech/hellow^" ]" )
- write_file( SpeechFile, "; NOTE - you dont need to write .wav or .mp3 its build in^n" )
- write_file( SpeechFile, "; Access - The access that will needed to play the sound" )
- log_amx( "No speech were found!" )
- pause( "a" )
- return 1
- }
- if( file_exists( SpeechFile ) )
- {
- new file = fopen( SpeechFile, "rt" )
- while( !feof( file ) )
- {
- fgets( file, text, charsmax( text ) )
- trim( text )
- if( text[ 0 ] == ';' || !text[ 0 ] ) continue
- parse( text, Speech[ SpeechLoaded ][ SoundName ], charsmax( Speech ), Speech[ SpeechLoaded ][ file_name ], charsmax( Speech ), Speech[ SpeechLoaded ][ AdminAccess ], charsmax( Speech ) )
- read_flags( Speech[ SpeechLoaded ][ AdminAccess ] )
- SpeechLoaded++
- }
- fclose( file )
- }
- return 1
- }
Add Comment
Please, Sign In to add comment