Advertisement
sancio

recordsystem

Dec 15th, 2014
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4. enum rekInfo {
  5.     data [ 30 ] ,
  6.     rekordas
  7. }
  8. new rek [ rekInfo ] ;
  9.  
  10. stock getPlayers ( ) {
  11.     new players = 0;
  12.     for ( new i = 0; i < MAX_PLAYERS; i ++ )
  13.         players ++ ;
  14.     return players;
  15. }
  16. stock loadRecord ( ) {
  17.     new query [ 50 ] , result [ 100 ] ;
  18.     format ( query , sizeof ( query ) , "SELECT rekordas,data FROM options" ) ;
  19.     mysql_query ( query ) ;
  20.     mysql_store_result ( ) ;
  21.     if ( mysql_num_rows ( ) ) {
  22.         mysql_fetch_row ( result ) ;
  23.  
  24.         mysql_fetch_field_row ( query , "rekordas" ) ;             
  25.         rek [ rekordas ] = strval ( query ) ;
  26.  
  27.         mysql_fetch_field_row ( query , "data" ) ;                 
  28.         format ( rek [ data ] , 30 , "%s" , query ) ;
  29.     }
  30.     mysql_free_result ( ) ;
  31.     return true;
  32. }
  33. stock saveRecord ( ) {
  34.     new query [ 50 ] ;
  35.     format ( query , sizeof ( query ) ,
  36.         "UPDATE options SET \
  37.         rekordas = %d,\
  38.         data = '%s'" ,
  39.         rek [ rekordas ] , rek [ data ]
  40.     ) ;
  41.     mysql_query ( query ) ;
  42.     return true;
  43. }
  44. public OnGameModeInit ( ) {
  45.     loadRecord ( ) ;
  46.     return true;
  47. }
  48. public OnGameModeExit ( ) {
  49.     saveRecord ( ) ;
  50.     return true;
  51. }
  52. public OnPlayerConnect ( playerid ) {
  53.  
  54.     if ( getPlayers ( ) >= rek [ rekordas ] ) {
  55.         new string [ 65 ] ;
  56.         rek [ rekordas ] = getPlayers ( ) ;
  57.         new time [ 6 ] ;
  58.         getdate ( time [ 0 ] , time [ 1 ] , time [ 2 ] ) ;
  59.         gettime ( time [ 3 ] , time [ 4 ] , time [ 5 ] ) ;
  60.         format ( rek [ data ] , 30 , "%d-%02d-%02d %02d:%02d:%02d" , time [ 0 ] , time [ 1 ] , time [ 2 ] , time [ 3 ] , time [ 4 ] , time [ 5 ] ) ;
  61.         format ( string , sizeof ( string ) , "Senas rekordas: %d, naujas rekordas %d" , rek [ rekordas ] , getPlayers ( ) ) ;
  62.         SendClientMessageToAll ( -1 , string ) ;
  63.         format ( string , sizeof ( string ) , "Pasiektas %s" , rek [ data ] ) ;
  64.         SendClientMessageToAll ( -1 , string ) ;
  65.     }
  66.     return true;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement