Rejack

Untitled

Feb 12th, 2017 (edited)
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.71 KB | None | 0 0
  1. #include < amxmodx >
  2. #include < fvault >
  3. #include < unixtime >
  4.  
  5. new const szVault[ ]    = "jbWishPlayers";
  6.  
  7. #define WISH_INTERVAL       12  // hours
  8. #define BASE_TIME       1486900800 
  9. new g_mPlayerWished[ 33 ];
  10. new szItem[ 128 ];
  11.  
  12. public plugin_init()
  13. {
  14.     register_plugin( "Jailbreak: Make A Wish", "1.0", "Rejack" );
  15.    
  16.     register_clcmd( "say /wish",        "cmdCanWish" ); // Check if you can wish
  17.     register_clcmd( "say /make",        "cmdMakeWish" );// Make a wish (if you can)
  18.    
  19.     checkWishTimer();
  20.    
  21.     set_task( 600.0, "Task_checkWishTimer", 0,_,_, "b" );
  22. }
  23.  
  24. public cmdCanWish( const client )
  25. {
  26.     if ( !g_mPlayerWished[ client ] )
  27.         szItem  = "Can";
  28.    
  29.     else
  30.         szItem  = "Can't";
  31.    
  32.     client_print( client, print_chat, "You -[ %s ]- Make a Wish!", szItem );
  33.    
  34.     return 1;
  35. }
  36.        
  37. public cmdMakeWish( const client )
  38. {
  39.     if ( g_mPlayerWished[ client ] != 0 )
  40.     {
  41.         g_mPlayerWished[ client ]   = 0;
  42.        
  43.         SavePlayer( client );
  44.        
  45.         client_print( 0, print_chat, "Rejack just made a wish!" );
  46.        
  47.         return 1;
  48.     }
  49.    
  50.     client_print( client, print_chat, "You can't make a wish" );
  51.    
  52.     return 0;
  53. }
  54.    
  55. public client_putinserver( client )
  56. {
  57.     static g_szAuthid[ 35 ];
  58.    
  59.     get_user_authid( client, g_szAuthid, charsmax( g_szAuthid ) );
  60.    
  61.     if ( fvault_get_keynum( szVault, g_szAuthid ) == -1 )   // Player not found, default bPlayerWished = false
  62.     {
  63.         g_mPlayerWished[ client ]   = 1;
  64.        
  65.         SavePlayer( client );
  66.     }
  67.    
  68.     else
  69.     {
  70.         static szData[ 6 ];
  71.        
  72.         fvault_get_data( szVault, g_szAuthid, szData, charsmax( szData ) );
  73.        
  74.         g_mPlayerWished[ client ]   = str_to_num( szData );
  75.     }
  76. }
  77.  
  78. stock SavePlayer( const index )
  79. {
  80.     static g_szAuthid[ 35 ];
  81.     static szData[ 6 ];
  82.    
  83.     num_to_str( g_mPlayerWished[ index ], szData, charsmax( szData ) );
  84.    
  85.     fvault_set_data( szVault, g_szAuthid, szData );
  86. }
  87.  
  88. public Task_checkWishTimer( )
  89. {
  90.     checkWishTimer( );
  91. }
  92.  
  93. /* Stocks */
  94.  
  95. new g_iNextWish;
  96.  
  97. stock calculate_time( )
  98. {
  99.     static iTime, iTimeAdjusted, iYear , iMonth , iDay , iHour , iMinute , iSecond;
  100.    
  101.     iTime   = get_systime( );
  102.    
  103.    
  104.    
  105.     UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
  106.    
  107.    
  108.    
  109.    
  110. stock checkWishTimer( )
  111. {
  112.     static iNextWish;
  113.    
  114.     if ( fvault_get_keynum( szVault, "0" ) == -1 )
  115.     {
  116.         static iTime/*, iTimeAdjusted */, iYear , iMonth , iDay , iHour , iMinute , iSecond;
  117.        
  118.         iTime   = get_systime( );
  119.        
  120.         UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
  121.     }
  122.    
  123.     else
  124.     {
  125.         static szData[ 16 ];
  126.        
  127.         fvault_get_data( szVault, "0", szData, charsmax( szData ) );
  128.        
  129.         iNextWish   = str_to_num( szData );
  130.     }
  131.    
  132.     static iCurrentTime;
  133.    
  134.     iCurrentTime    = get_systime( );
  135.    
  136.     if ( iCurrentTime < iNextWish ) // Can't make a wish, do nothing.
  137.         return 1;
  138.    
  139.     // Can make a wish
  140.     fvault_clear( szVault );    // clear vault for disconnected player to have a wish.
  141.    
  142.     static Players[ 32 ], iNum, index, i;
  143.    
  144.     get_players( Players, iNum, "ch" );
  145.    
  146.     for ( i = 0; i < iNum; i++ )    // Set wishes to '1' for everyone and save.
  147.     {
  148.         g_mPlayerWished[ Players[ i ] ] = 1;
  149.        
  150.         SavePlayer( Players[ i ] );
  151.     }
  152.    
  153.     // Calculate nex wish
  154.    
  155.     static iTime;
  156.    
  157.     iTime   = WISH_INTERVAL * 60 * 60;
  158.    
  159.     if ( iNextWish == 0 )
  160.     {
  161.         // First entry need to set next wish
  162.        
  163.    
  164.     iNextWish   += iTime;
  165.    
  166.    
  167.    
  168.     if ( iCurrentTime + iTime >
  169.    
  170.     if ( fvault_size( szVault ) < 1 )
  171.     {
  172.         // No vault, first entry need to set wish timer
  173.         static iTime/*, iTimeAdjusted */, iYear , iMonth , iDay , iHour , iMinute , iSecond;
  174.        
  175.         iTime   = get_systime( );
  176.        
  177.         UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
  178.        
  179.         if ( !iDay && !iHour && !iSecond )  // Remove a second because its 00:00:00
  180.             iTime--;
  181.        
  182.         iTime   +=  ( WISH_INTERVAL * 60 * 60 );
  183.        
  184.        
  185.        
  186.        
  187.         return 1;
  188.     }
  189.    
  190.     return 1;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment