AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
03-02-2015
, 19:30
Re: Hours is not saved
|
#14
|
I have not thoroughly tested this so let me know if you have any issues. You have to use the nvault_util include file I attached below because it has a new function I had to create that doesn't exist yet in the include file in the nvault utility thread.
Every aw_checkwarnsevery days, the plugin will: - Check all players warns and remove any that are greater than aw_warnexpiredays days old.
- Check players play time and if it is less than their required time, it will issue a warn. When a warn is issued, their play time is reset to 0 because a new cycle is starting.
- If warns are >= aw_maxwarns, their admin power is removed.
Each admins required play time (required hours per aw_checkwarnsevery cycle) must be set in admini.ini in the configs folder in the below format.
Code:
"STEAM_0:0:11111" "7"
"STEAM_0:0:22222" "7"
"STEAM_0:0:33333" "14"
To calculate the value for the config file, do aw_checkwarnsevery * desired number of hours per day. In the above example, the first 2 would be 1 hour per day, the third would be 2 hours per day if you have aw_checkwarnsevery set to 7.
If you set aw_maxwarns greater than 10, you must increase the MAX_WARNS value in the source and recompile. If you forget to update the code, you will see this error on map change: "Plugin cannot handle ad_maxwarns greater than X. Must increase MAX_WARNS in plugin source."
Update: Player will be shown the below message if they have any warns on record:
Code:
* You currently have 2 warns. You must play at least 2 hours per day or 14 hours per 7 day(s).
PHP Code:
#include <amxmodx> #include <nvault_util>
new const Version[] = "0.3";
const AW_ADMIN_FLAG = ADMIN_KICK; const HOUR_SECONDS = 3600; const DAY_SECONDS = 86400; const MAX_WARNS = 10; const TASK_DELAYMSG = 0x1234;
new const g_szFileName[] = "/admini.ini"; new const g_szVaultName[] = "adminwarning";
enum _:AdminData { ad_ConnectTime, ad_TimePlayed, ad_NumWarns, ad_Warns[ 5 ] };
new g_Vault , g_pWarns , g_pCheckWarnsEvery , g_pWarnExpireDays , g_Admins; new g_szAuthID[ MAX_PLAYERS + 1 ][ 34 ] , g_adData[ MAX_PLAYERS + 1 ][ AdminData ]; new g_szConfigFile[ 128 ] , g_szUsersFile[ 128 ];
#define IsAdmin(%1) ( g_Admins & ( 1 << ( %1 & 31 ) ) )
public plugin_init() { register_plugin( "Admin Warn" , Version , "bugsy" ); copy( g_szConfigFile[ get_configsdir( g_szConfigFile , charsmax( g_szConfigFile ) ) ] , charsmax( g_szConfigFile ) , g_szFileName ); copy( g_szUsersFile[ get_configsdir( g_szUsersFile , charsmax( g_szUsersFile ) ) ] , charsmax( g_szUsersFile ) , "/users.ini" ); g_pWarns = register_cvar( "aw_maxwarns" , "5" ); g_pCheckWarnsEvery = register_cvar( "aw_checkwarnsevery" , "7" ); g_pWarnExpireDays = register_cvar( "aw_warnexpiredays" , "30" ); }
public plugin_cfg() { new iDay , iMaxWarns , iWarnExpireDays , iSysTime , iPos , bool:bRecordUpdated , adData[ AdminData ] , iVault , iCount , iTS , szKey[ 34 ] , szDay[ 3 ]; if ( get_pcvar_num( g_pWarns ) > MAX_WARNS ) set_fail_state( "Plugin cannot handle ad_maxwarns greater than %d. Must increase MAX_WARNS in plugin source." , MAX_WARNS ); date( _ , _ , iDay ); if ( ( iDay % get_pcvar_num( g_pCheckWarnsEvery ) ) == 0 ) { iMaxWarns = get_pcvar_num( g_pWarns ); iWarnExpireDays = get_pcvar_num( g_pWarnExpireDays ); iSysTime = get_systime(); g_Vault = nvault_open( g_szVaultName ); if ( nvault_get( g_Vault , "LastCheck" ) != iDay ) { iVault = nvault_util_open( g_szVaultName ); iCount = nvault_util_count( iVault ); //Loop through all records in vault for ( new i = 0 ; i < iCount ; i++ ) { bRecordUpdated = false; iPos = nvault_util_read_array( iVault , iPos , szKey , charsmax( szKey ) , adData , sizeof( adData ) , iTS ); //Check all existing warns and remove any that have expired. for ( new p = 0 ; p < iMaxWarns ; p++ ) { if ( adData[ ad_Warns ][ p ] && ( adData[ ad_Warns ][ p ] < ( iSysTime - ( iWarnExpireDays * DAY_SECONDS ) ) ) ) { adData[ ad_Warns ][ p ] = 0; adData[ ad_NumWarns ]--; bRecordUpdated = true; } } //Check if player has played enough hours if ( ( adData[ ad_TimePlayed ] / HOUR_SECONDS ) < GetRequiredTime( szKey ) ) { //Not enough hours, issue warn. // If this warn puts him over limit, remove admin. if ( ++adData[ ad_NumWarns ] >= iMaxWarns ) { RemoveAdmin( szKey ); nvault_remove( g_Vault , szKey ); bRecordUpdated = false; } else { //Add a warn and reset play time for ( new p = 0 ; p < iMaxWarns ; p++ ) { if ( adData[ ad_Warns ][ p ] == 0 ) { adData[ ad_Warns ][ p ] = iSysTime; adData[ ad_TimePlayed ] = 0; bRecordUpdated = true; break; } } } } else { //Player played enough for the cycle. Reset play time. adData[ ad_TimePlayed ] = 0; bRecordUpdated = true; } if ( bRecordUpdated ) nvault_set_array( g_Vault , szKey , adData , sizeof( adData ) ); } nvault_util_close( iVault ); num_to_str( iDay , szDay , charsmax( szDay ) ); nvault_set( g_Vault , "LastCheck" , szDay ); } nvault_close( g_Vault ); } g_Vault = nvault_open( g_szVaultName ); }
public plugin_end() { nvault_close( g_Vault ); }
public client_authorized( id ) { g_Admins |= ( get_user_flags( id ) & AW_ADMIN_FLAG ) ? ( 1 << ( id & 31 ) ) : 0;
if ( IsAdmin( id ) ) { get_user_authid( id , g_szAuthID[ id ] , charsmax( g_szAuthID[] ) ); nvault_get_array( g_Vault , g_szAuthID[ id ] , g_adData[ id ] , sizeof( g_adData[] ) );
g_adData[ id ][ ad_ConnectTime ] = get_systime(); if ( g_adData[ id ][ ad_NumWarns ] ) { set_task( 7.0 , "DelayMsg" , id + TASK_DELAYMSG , g_adData[ id ] , sizeof( g_adData[] ) ); } } }
public client_disconnect( id ) { if ( IsAdmin( id ) ) { g_adData[ id ][ ad_TimePlayed ] = g_adData[ id ][ ad_TimePlayed ] + ( get_systime() - g_adData[ id ][ ad_ConnectTime ] ); nvault_set_array( g_Vault , g_szAuthID[ id ] , g_adData[ id ] , sizeof( g_adData[] ) ); } }
public DelayMsg( const adData[] , iTaskID ) { iTaskID -= TASK_DELAYMSG; new iRequiredTime = GetRequiredTime( g_szAuthID[ iTaskID ] );
client_print( iTaskID , print_chat , "* You currently have %d warns. You must play at least %d hours per day or %d hours per %d day(s)." , adData[ ad_NumWarns ] , iRequiredTime / get_pcvar_num( g_pCheckWarnsEvery ) , iRequiredTime , get_pcvar_num( g_pCheckWarnsEvery ) );
}
public GetRequiredTime( const szAuthID[] ) { new szData[ 42 ] , szParseAuthID[ 34 ] , szParseHours[ 3 ] , iFile , iRequiredTime; if( !( iFile = fopen( g_szConfigFile , "r" ) ) ) return 0; while( !feof( iFile ) ) { fgets( iFile , szData , charsmax( szData ) ); if( szData[ 0 ] == ';' || szData[ 0 ] == '!' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) ) continue; parse( szData , szParseAuthID , charsmax( szParseAuthID ) , szParseHours , charsmax( szParseHours ) );
if ( equali( szParseAuthID , szAuthID ) ) { iRequiredTime = str_to_num( szParseHours ); break; } } fclose( iFile ); return iRequiredTime; }
public RemoveAdmin( const szAuthID[] ) { new szData[ 155 ] , szParseAuthID[ 34 ], szParsePassword[ 32 ], szParseFlags[ 32 ], szParseRFlags[ 32 ], iFile , iLine; if( !( iFile = fopen( g_szUsersFile , "r" ) ) ) return 0;
while( !feof( iFile ) ) { fgets( iFile , szData[ 1 ] , charsmax( szData[] ) - 1 ); iLine++; if( szData[ 1 ] == ';' || szData[ 1 ] == '!' || ( szData[ 1 ] == '/' && szData[ 2 ] == '/' ) ) continue; parse( szData[ 1 ] , szParseAuthID , charsmax( szParseAuthID ) , szParsePassword , charsmax( szParsePassword ) , szParseFlags , charsmax( szParseFlags ) , szParseRFlags , charsmax( szParseRFlags ) ); if( equali( szParseAuthID , szAuthID ) ) { szData[ 0 ] = ';' formatex( szData[ 1 ] , charsmax( szData ) - 1 , " ^"%s^" ^"%s^" ^"%s^" ^"%s^"", szParseAuthID , szParsePassword , szParseFlags , szParseRFlags ); write_file( g_szUsersFile , szData , iLine - 1 ); break; } } fclose( iFile ); return 1; }
__________________
Last edited by Bugsy; 07-25-2015 at 00:56.
|
|