Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < fvault >
- #include < unixtime >
- new const szVault[ ] = "jbWishPlayers";
- #define WISH_INTERVAL 12 // hours
- #define BASE_TIME 1486900800
- new g_mPlayerWished[ 33 ];
- new szItem[ 128 ];
- public plugin_init()
- {
- register_plugin( "Jailbreak: Make A Wish", "1.0", "Rejack" );
- register_clcmd( "say /wish", "cmdCanWish" ); // Check if you can wish
- register_clcmd( "say /make", "cmdMakeWish" );// Make a wish (if you can)
- checkWishTimer();
- set_task( 600.0, "Task_checkWishTimer", 0,_,_, "b" );
- }
- public cmdCanWish( const client )
- {
- if ( !g_mPlayerWished[ client ] )
- szItem = "Can";
- else
- szItem = "Can't";
- client_print( client, print_chat, "You -[ %s ]- Make a Wish!", szItem );
- return 1;
- }
- public cmdMakeWish( const client )
- {
- if ( g_mPlayerWished[ client ] != 0 )
- {
- g_mPlayerWished[ client ] = 0;
- SavePlayer( client );
- client_print( 0, print_chat, "Rejack just made a wish!" );
- return 1;
- }
- client_print( client, print_chat, "You can't make a wish" );
- return 0;
- }
- public client_putinserver( client )
- {
- static g_szAuthid[ 35 ];
- get_user_authid( client, g_szAuthid, charsmax( g_szAuthid ) );
- if ( fvault_get_keynum( szVault, g_szAuthid ) == -1 ) // Player not found, default bPlayerWished = false
- {
- g_mPlayerWished[ client ] = 1;
- SavePlayer( client );
- }
- else
- {
- static szData[ 6 ];
- fvault_get_data( szVault, g_szAuthid, szData, charsmax( szData ) );
- g_mPlayerWished[ client ] = str_to_num( szData );
- }
- }
- stock SavePlayer( const index )
- {
- static g_szAuthid[ 35 ];
- static szData[ 6 ];
- num_to_str( g_mPlayerWished[ index ], szData, charsmax( szData ) );
- fvault_set_data( szVault, g_szAuthid, szData );
- }
- public Task_checkWishTimer( )
- {
- checkWishTimer( );
- }
- /* Stocks */
- new g_iNextWish;
- stock calculate_time( )
- {
- static iTime, iTimeAdjusted, iYear , iMonth , iDay , iHour , iMinute , iSecond;
- iTime = get_systime( );
- UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
- stock checkWishTimer( )
- {
- static iNextWish;
- if ( fvault_get_keynum( szVault, "0" ) == -1 )
- {
- static iTime/*, iTimeAdjusted */, iYear , iMonth , iDay , iHour , iMinute , iSecond;
- iTime = get_systime( );
- UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
- }
- else
- {
- static szData[ 16 ];
- fvault_get_data( szVault, "0", szData, charsmax( szData ) );
- iNextWish = str_to_num( szData );
- }
- static iCurrentTime;
- iCurrentTime = get_systime( );
- if ( iCurrentTime < iNextWish ) // Can't make a wish, do nothing.
- return 1;
- // Can make a wish
- fvault_clear( szVault ); // clear vault for disconnected player to have a wish.
- static Players[ 32 ], iNum, index, i;
- get_players( Players, iNum, "ch" );
- for ( i = 0; i < iNum; i++ ) // Set wishes to '1' for everyone and save.
- {
- g_mPlayerWished[ Players[ i ] ] = 1;
- SavePlayer( Players[ i ] );
- }
- // Calculate nex wish
- static iTime;
- iTime = WISH_INTERVAL * 60 * 60;
- if ( iNextWish == 0 )
- {
- // First entry need to set next wish
- iNextWish += iTime;
- if ( iCurrentTime + iTime >
- if ( fvault_size( szVault ) < 1 )
- {
- // No vault, first entry need to set wish timer
- static iTime/*, iTimeAdjusted */, iYear , iMonth , iDay , iHour , iMinute , iSecond;
- iTime = get_systime( );
- UnixToTime( iTime , iYear , iMonth , iDay , iHour , iMinute , iSecond );
- if ( !iDay && !iHour && !iSecond ) // Remove a second because its 00:00:00
- iTime--;
- iTime += ( WISH_INTERVAL * 60 * 60 );
- return 1;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment