Advertisement
RanAway

[ Pawn - fun plugins ] story with ini

May 27th, 2022 (edited)
1,623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.08 KB | None | 0 0
  1. //-------------------- Includes --------------------//
  2. #include < amxmodx >
  3.  
  4. //-------------------- Defines --------------------//
  5. #define Prefix          "AMXX"
  6. #define MAX_STORYS      120
  7. #define StoryFile       "addons/amxmodx/configs/Story.ini"
  8.  
  9. //-------------------- Functions --------------------//
  10. new Storys[ MAX_STORYS ][ 200 ], StoryID[ 33 ], StoryLoaded = 0
  11.  
  12. //-------------------- Plugin init --------------------//
  13. public plugin_init()
  14. {
  15.     register_plugin( "Story", "v1.0", "RanAway`" )
  16.  
  17.     //-------------------- Commands --------------------//
  18.     register_clcmd( "say /story", "Story" )
  19.  
  20.     //-------------------- Load --------------------//
  21.     LoadStory()
  22. }
  23.  
  24. //-------------------- make sure it will start from the first line --------------------//
  25. public client_authorized( id ) if( StoryID[ id ] == 0 ) StoryID[ id ] = -1
  26.  
  27. //-------------------- Story --------------------//
  28. public Story( id )
  29. {
  30.     //-------------------- reload in real time --------------------//
  31.     StoryLoaded = 0
  32.     LoadStory()
  33.  
  34.     //-------------------- if the ini is empty --------------------//
  35.     if( StoryLoaded == 0 ) return ColorChat( id, "There is not ^3storys^1 yet." )
  36.  
  37.     //-------------------- make sure it will stop at maximum --------------------//
  38.     if( StoryID[ id ] < StoryLoaded - 1 ) StoryID[ id ]++
  39.  
  40.     //-------------------- Chat msg --------------------//
  41.     return ColorChat( id, "%s.", Storys[ StoryID[ id ] ] )
  42. }
  43.  
  44. //-------------------- Load --------------------//
  45. LoadStory()
  46. {
  47.     //-------------------- instructions --------------------//
  48.     if( !file_exists( StoryFile ) ) write_file( StoryFile, "; Just add your story^n; Each line is Sentence^n" )
  49.  
  50.     new text[ 500 ], File = fopen( StoryFile, "rt" )
  51.  
  52.     //-------------------- open the file --------------------//
  53.     while( !feof( File ) )
  54.     {
  55.         //-------------------- get the line --------------------//
  56.         fgets( File, text, charsmax( text ) )
  57.  
  58.         //-------------------- removes whitespace characters from the beginning and end of a string --------------------//
  59.         trim( text )
  60.  
  61.         //-------------------- skip if there is empty line or start with ; --------------------//
  62.         if( text[ 0 ] == ';' || !text[ 0 ] ) continue
  63.  
  64.         //-------------------- copy the line to array --------------------//
  65.         copy( Storys[ StoryLoaded ], sizeof( Storys ), text )
  66.  
  67.         //-------------------- count the lines --------------------//
  68.         StoryLoaded++
  69.     }
  70.     //-------------------- close the file --------------------//
  71.     fclose( File )
  72.     return 1
  73. }
  74.  
  75. //-------------------- Stocks - ColorChat --------------------//
  76. stock ColorChat( id, const string[], any:... )
  77. {
  78.     new msg[ 191 ], players[ 32 ], count = 1
  79.  
  80.     new len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
  81.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  82.  
  83.     if( id )
  84.         players[ 0 ] = id
  85.     else
  86.         get_players( players, count, "ch" )
  87.  
  88.     for( new i = 0; i < count; i++ )
  89.     {
  90.         if( is_user_connected( players[ i ] ) )
  91.         {
  92.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
  93.             write_byte( players[ i ] )
  94.             write_string( msg )
  95.             message_end()
  96.         }
  97.     }
  98.     return 1
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement