Advertisement
RanAway

[ Pawn - fun plugins ] story with ini

May 27th, 2022 (edited)
1,635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.60 KB | None | 0 0
  1. //-------------------- Includes --------------------//
  2. #include < amxmodx >
  3.  
  4. //-------------------- Defines --------------------//
  5. #define Prefix          "AMXX"
  6. #define StoryFile       "addons/amxmodx/configs/Story.ini"
  7.  
  8. //-------------------- Functions --------------------//
  9. new Storys[ 1000 ][ 512 ], StoryID[ 33 ], StoryLoaded = 0
  10.  
  11. //-------------------- Plugin init --------------------//
  12. public plugin_init()
  13. {
  14.     register_plugin( "Story", "v1.0", "RanAway`" )
  15.  
  16.     //-------------------- Commands --------------------//
  17.     register_clcmd( "say /story", "Story" )
  18. }
  19.  
  20. //-------------------- make sure it will start from the first line --------------------//
  21. public client_authorized( id ) if( StoryID[ id ] == 0 ) StoryID[ id ] = -1
  22.  
  23. //-------------------- Story --------------------//
  24. public Story( id )
  25. {
  26.     //-------------------- reload in real time --------------------//
  27.     LoadStory()
  28.  
  29.     //-------------------- if the ini is empty --------------------//
  30.     if( !StoryLoaded ) return ColorChat( id, "There is no ^3storys^1 yet." )
  31.  
  32.     //-------------------- make sure it will stop at maximum --------------------//
  33.     if( StoryID[ id ] <= StoryLoaded ) StoryID[ id ]++
  34.  
  35.     //-------------------- Chat msg --------------------//
  36.     return ColorChat( id, "%s.", Storys[ StoryID[ id ] ] )
  37. }
  38.  
  39. //-------------------- Load --------------------//
  40. LoadStory()
  41. {
  42.     //-------------------- clear the array for prevent bugs --------------------//
  43.     arrayset( Storys[ StoryLoaded ], 0, StoryLoaded )
  44.     StoryLoaded = 0
  45.  
  46.     //-------------------- instructions --------------------//
  47.     if( !file_exists( StoryFile ) ) write_file( StoryFile, "; Just add your story^n; Each line is Sentence^n" )
  48.  
  49.     new Line[ 512 ], File = fopen( StoryFile, "rt" )
  50.  
  51.     //-------------------- open the file --------------------//
  52.     while( !feof( File ) )
  53.     {
  54.         //-------------------- get the line --------------------//
  55.         fgets( File, Line, charsmax( Line ) ); trim( Line )
  56.  
  57.         //-------------------- skip if there is empty line or start with ; --------------------//
  58.         if( Line[ 0 ] == ';' || !Line[ 0 ] ) continue
  59.  
  60.         //-------------------- copy the line to array --------------------//
  61.         copy( Storys[ StoryLoaded++ ], sizeof( Storys ), Line )
  62.     }
  63.     //-------------------- close the file --------------------//
  64.     fclose( File )
  65.     return 1
  66. }
  67.  
  68. //-------------------- Stocks - ColorChat --------------------//
  69. stock ColorChat( id, const string[], any:... )
  70. {
  71.     new msg[ 191 ], len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
  72.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  73.  
  74.     client_print_color( id, print_team_default, msg )
  75.     return 1
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement