RanAway

[ Pawn ] Speech stand alone

May 27th, 2022 (edited)
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.24 KB | None | 0 0
  1. /****************** Include *******************/
  2. #include < amxmodx >
  3. #include < amxmisc >
  4. #include < colorchat >
  5.  
  6. /****************** Defines *******************/
  7. #define Prefix          "AMXX"
  8.  
  9. #define SpeechFile      "addons/amxmodx/configs/newspeech.ini"
  10.  
  11. /****************** Speech *******************/
  12. enum _:Properties
  13. {
  14.     SoundName[ 31 ],
  15.     file_name[ 120 ],
  16.     AdminAccess
  17. }
  18.  
  19. new Speech[ 120 ][ Properties ], SpeechLoaded = 0
  20.  
  21. /****************** Volume *******************/
  22. new const Volume[] [] =
  23. {
  24.     "[\r----------\w]",
  25.     "[\y+\r---------\w]",
  26.     "[\y++\r--------\w]",
  27.     "[\y+++\r-------\w]",
  28.     "[\y++++\r------\w]",
  29.     "[\y+++++\r-----\w]",
  30.     "[\y++++++\r----\w]",
  31.     "[\y+++++++\r---\w]",
  32.     "[\y++++++++\r--\w]",
  33.     "[\y+++++++++\r-\w]",
  34.     "[\y++++++++++\w]"
  35. }
  36.  
  37. new Float: Mp3value[ 33 ], VolumeCTRL[ 33 ]
  38.  
  39. /****************** News *******************/
  40. new MenuPage[ 33 ]
  41.  
  42. /****************** Plugin init *******************/
  43. public plugin_init()
  44. {
  45.     register_plugin( "SpeechStandAlone", "v1.0", "AMXX Devs team | RanAway`" )
  46.    
  47.     /****************** Speech *******************/
  48.     register_clcmd( "amx_speech", "BeforeSpeech" )
  49.     register_menucmd( register_menuid( "sub_menu" ), 1023, "sub_speech" )
  50. }
  51.  
  52. /************** Putinserver **************/
  53. public client_putinserver( id )
  54. {
  55.     Mp3value[ id ] = 0.60
  56.     VolumeCTRL[ id ] = 6
  57. }
  58.  
  59. /****************** plugin_precache *******************/
  60. public plugin_precache()
  61. {
  62.     LoadSpeech()
  63.    
  64.     new file = fopen( SpeechFile, "rt" )
  65.    
  66.     if( !file )
  67.         return 0
  68.    
  69.     new text[ 256 ], name[ 32 ], sound[ 128 ], sndExt[ 5 ], fieldNums
  70.     new field1[ 32 ], field2[ 64 ], field3[ 64 ]
  71.    
  72.     while( !feof( file ) )
  73.     {
  74.         fgets( file, text, charsmax( text ) )
  75.        
  76.         if( text[ 0 ] == ';' || text[ 0 ] == '/' )
  77.             continue
  78.        
  79.         parse( text, name, charsmax( name ), sound, charsmax( sound ) )
  80.        
  81.         fieldNums = parse( sound, field1, charsmax( field1 ), field2, charsmax( field2 ), field3, charsmax( field3 ) )
  82.        
  83.         if( fieldNums == 2 && field1[ 0 ] == 's' ) // .wav ( spk )
  84.         {
  85.             copy( sound, charsmax( sound ), field2 )
  86.             copy( sndExt, charsmax( sndExt ), ".wav" )
  87.         }
  88.         else if( fieldNums == 3 && field1[ 0 ] == 'm' && ( field2[ 0 ] == 'p' || field2[ 0 ] == 'l' ) ) // .mp3 ( mp3 play | mp3 loop )
  89.         {
  90.             copy( sound, charsmax( sound ), field3 )
  91.             copy( sndExt, charsmax( sndExt ), ".mp3" )
  92.         }
  93.         else // WTH is this sound, drop it.
  94.             continue
  95.        
  96.         if( sndExt[ 1 ] == 'm' || ( ! equali( sound, "vox", 3 ) && ! equali( sound, "fvox", 4 ) && ! equali( sound, "barney", 6 ) && ! equali( sound, "hgrunt", 6 ) ) )
  97.         {
  98.             // sound is a mp3, or a custom wav ( not a vox, fvox, or default sound from HL pak )
  99.             if( !equali( sound[ strlen( sound )-4 ], sndExt ) )
  100.                 add( sound, charsmax( sound ), sndExt ) // Add filetype extension if it isn't already specified
  101.            
  102.             if( sndExt[ 1 ] == 'w' )
  103.                 format( sound, charsmax( sound ), "sound/%s", sound ) // spk basedir is $moddir/sound, but mp3 play is $moddir, fix this for the file_exists check
  104.            
  105.             if( file_exists( sound ) )
  106.             {
  107.                 if( sndExt[ 1 ] == 'm' )
  108.                     precache_generic( sound ) // mp3
  109.                 else
  110.                 {
  111.                     replace( sound, charsmax( sound ), "sound/", "" ) // wav, strip the leading sound/ we added for our file_exists check
  112.                     precache_sound( sound )
  113.                 }
  114.             }
  115.         }
  116.     }
  117.    
  118.     fclose( file )
  119.     return 1
  120. }
  121.  
  122. /****************** Before menu *******************/
  123. public BeforeSpeech( id )
  124. {
  125.     if( !( get_user_flags( id ) & ADMIN_MENU ) )
  126.         return 0
  127.    
  128.     if( SpeechLoaded == 0 )
  129.     {
  130.         ColorChat( id, NORMAL, "^3[^1 %s ^3]^1 There is no ^3speech^1 yet", Prefix )
  131.         return 1
  132.     }
  133.    
  134.     Speechmenu( id, MenuPage[ id ] = 0 )
  135.    
  136.     return PLUGIN_HANDLED
  137. }
  138.  
  139. /****************** Speech menu *******************/
  140. public Speechmenu( id, page )
  141. {
  142.     if( page < 0 ) return
  143.    
  144.     new szMenu[ 512 ], b, start = page * 6, keys = MENU_KEY_0|MENU_KEY_7|MENU_KEY_8
  145.    
  146.     if( start >= SpeechLoaded ) start = page = MenuPage[ id ] = 0
  147.    
  148.     new limit = SpeechLoaded / 6 + SpeechLoaded % 6
  149.     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 )
  150.     new end = start + 6
  151.    
  152.     if( end > SpeechLoaded ) end = SpeechLoaded
  153.    
  154.     for( new a = start; a < end; ++a )
  155.     {
  156.         if( !access( id, Speech[ a ][ AdminAccess ] ) )
  157.             len += format( szMenu[ len ], charsmax( szMenu ) -len, "\r%d.\d %s^n", ++b, Speech[ a ][ SoundName ] )
  158.         else
  159.         {
  160.             keys |= ( 1 << b )
  161.             len += format( szMenu[ len ], charsmax( szMenu ) -len, "\r%d.\w %s^n", ++b, Speech[ a ][ SoundName ] )
  162.         }
  163.     }
  164.    
  165.     len += format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r7. \yVolume. \w%s^n", Volume[ VolumeCTRL[ id ] ] )
  166.     len += format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r8. \wStop sound^n" )
  167.    
  168.     if( end != SpeechLoaded )
  169.     {
  170.         format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r9.\w Next Page^n\r0.\w %s", page ? "Previous Page" : "Exit" )
  171.         keys |= MENU_KEY_9
  172.     }
  173.     else
  174.         format( szMenu[ len ], charsmax( szMenu ) -len, "^n\r0.\w %s", page ? "Previous Page" : "Exit" )
  175.    
  176.     show_menu( id, keys, szMenu, -1, "sub_menu" )
  177. }
  178.  
  179. public sub_speech( id, key )
  180. {
  181.     switch( key )
  182.     {
  183.         case 6:
  184.         {
  185.             if( Mp3value[ id ] > 1.00 )
  186.                 Mp3value[ id ] = 0.0
  187.             else
  188.                 Mp3value[ id ] += 0.10
  189.            
  190.             if( VolumeCTRL[ id ] == sizeof Volume - 1 )
  191.                 VolumeCTRL[ id] = 0
  192.             else
  193.                 VolumeCTRL[ id ]++
  194.            
  195.             client_cmd( 0, "MP3Volume %.1f", Mp3value[ id ] )
  196.             Speechmenu( id, MenuPage[ id ] )
  197.         }
  198.         case 7:
  199.         {
  200.             client_cmd( 0, "stopsound" )
  201.             client_cmd( 0, "mp3 stop" )
  202.             Speechmenu( id, MenuPage[ id ] )
  203.         }
  204.         case 8: Speechmenu( id, ++MenuPage[ id ] )
  205.         case 9: Speechmenu( id, --MenuPage[ id ] )
  206.         default:
  207.         {
  208.             new option = MenuPage[ id ] * 6 + key
  209.            
  210.             client_cmd( 0, "%s", Speech[ option ][ file_name ] )
  211.             Speechmenu( id, MenuPage[ id ] )
  212.         }
  213.     }
  214.    
  215.     return PLUGIN_HANDLED
  216. }
  217.  
  218. /****************** Load speech *******************/
  219. public LoadSpeech()
  220. {
  221.     new text[ 256 ]
  222.    
  223.     if( !file_exists( SpeechFile ) )
  224.     {
  225.         write_file( SpeechFile, "; Name in menu     mp3 / spk File location                 Access^n" )
  226.         write_file( SpeechFile, "; Name in menu - The name that will appear in the menu^n" )
  227.         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^" ]" )
  228.         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^" ]" )
  229.         write_file( SpeechFile, "; NOTE - you dont need to write .wav or .mp3 its build in^n" )
  230.         write_file( SpeechFile, "; Access - The access that will needed to play the sound" )
  231.         log_amx( "No speech were found!" )
  232.         pause( "a" )
  233.         return 1
  234.     }
  235.    
  236.     if( file_exists( SpeechFile ) )
  237.     {
  238.         new file = fopen( SpeechFile, "rt" )
  239.        
  240.         while( !feof( file ) )
  241.         {
  242.             fgets( file, text, charsmax( text ) )
  243.             trim( text )
  244.            
  245.             if( text[ 0 ] == ';' || !text[ 0 ] ) continue
  246.            
  247.             parse( text, Speech[ SpeechLoaded ][ SoundName ], charsmax( Speech ), Speech[ SpeechLoaded ][ file_name ], charsmax( Speech ), Speech[ SpeechLoaded ][ AdminAccess ], charsmax( Speech ) )
  248.            
  249.             read_flags( Speech[ SpeechLoaded ][ AdminAccess ] )
  250.             SpeechLoaded++
  251.         }
  252.         fclose( file )
  253.     }
  254.     return 1
  255. }
Add Comment
Please, Sign In to add comment