AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hours is not saved (https://forums.alliedmods.net/showthread.php?t=230196)

smiley92 11-21-2013 14:49

Hours is not saved
 
Hi allied.I have one plugin and is not work, save hours maybe is the big problem here.I don't know what is the fix problem, because I don't know to script...
This plugin have a lot problem I say, just say.Plugin is for remove admins inactive, admins who which not respect the program maked me in admini.ini, when write hours in the right of what admin I want to respect program.This plugin don't save hours corectly, I say corect is to be when the day is end, 24:00 to be program, now him give warn if I connect and disconnect from server.And minute I want to be saved, to be compensed to hours.

Example: I put in admini.ini Smiley "5", I must to stay five hours to server in one day, is not I received 1 warn of x, x to be a cvar in plugin 1/7, 7 to be day.

Code:

#include < amxmodx >
#include < amxmisc >
#include < nvault >

#define PLUGIN "Admins activity"
#define VERSION "0.1"


#define MAX_WARN    5

new g_szFile[ 64 ];
new const g_szFileName[ ] = "admini.ini"        /* Numele la fisierul de unde sunt incarcate datele fiecarui admin */

new g_iPlayerStats[ 33 ];
new g_iPlayerMinutes[ 33 ];
new g_iPlayerWarn[ 33 ];

new g_iHourPlayer[ 33 ];


public plugin_init( )
{
    register_plugin( PLUGIN, VERSION, "falcao" );
   
    /* Verificare fisier */
   
    get_configsdir( g_szFile, sizeof( g_szFile ) -1 );
    format( g_szFile, sizeof( g_szFile ) -1, "%s/%s", g_szFile, g_szFileName );
   
    if( !file_exists( g_szFile ) )
    {
        write_file( g_szFile, "; Activitate admini", -1 );
    }
   
    /* Clcmd */
   
    register_clcmd( "say /warn", "cmdWarn" );
    register_clcmd( "say /program", "cmdProgram" );
}

public client_putinserver( id )
{
    new iHour, iMinute;
    time( iHour, iMinute, _ );

   
        LoadHours( id );
       
        set_task( 60.0, "adaugareMinut", id, _, _, "b", _ );
       
        static szName[ 32 ];
        get_user_name( id, szName, sizeof( szName ) -1 );
       
        set_task( 3.0, "verifyPlayer", id );
       
        if( g_iPlayerWarn[ id ] >= MAX_WARN )
        {
            new szFile = fopen( "addons/amxmodx/configs/users.ini", "r" );
           
            if( !szFile )
                return 1;
           
            new szData[ 512 ], szParseName[ 32 ], szParsePassword[ 32 ], szParseFlags[ 32 ], szParseRFlags[ 32 ], iLine;
           
            while( !feof( szFile ) )
            {
                fgets( szFile, szData, sizeof( szData ) -1 );
               
                if( szData[ 0 ] == ';' || szData[ 0 ] == '!' || szData[ 0 ] == '/' && szData[ 1 ] == '/' )
                    continue;
                   
                parse( szData, szParseName, sizeof( szParseName ) -1, szParsePassword, sizeof( szParsePassword ) -1, szParseFlags, sizeof( szParseFlags ) -1, szParseRFlags, sizeof( szParseRFlags ) -1 );
               
                if( equali( szParseName, szName ) )
                {
                    new szPlayerInfo[ 256 ];
                    format( szPlayerInfo, sizeof( szPlayerInfo ) -1, "; ^"%s^" ^"%s^" ^"%s^" ^"%s^"", szParseName, szParsePassword, szParseFlags, szParseRFlags );
                   
                    write_file( "addons/amxmodx/configs/users.ini", szPlayerInfo, iLine );
                   
                    g_iPlayerWarn[ id ] = 0;
                   
                    set_task( 3.0, "mesajWarn", id );
                }
               
                iLine++;
            }
           
            fclose( szFile );
        }
   
    return 1;
}

public mesajWarn( id )
{
    C_PrintChat( id, "Ai facut !v5!c/!v5!c warn-uri. Adminul tau a fost oprit." );
}

public cmdWarn( id )
{
    new szFile = fopen( g_szFile, "r" );
   
    if( !szFile )
        return 1;
   
    new szData[ 512 ], szParseName[ 32 ], szParseHours[ 32 ];
   
    while( !feof( szFile ) )
    {
        fgets( szFile, szData, sizeof( szData ) -1 );
       
        if( szData[ 0 ] == ';' || szData[ 0 ] == '!' || szData[ 0 ] == '/' && szData[ 1 ] == '/' )
            continue;
       
        parse( szData,\
            szParseName, sizeof( szParseName ),\
            szParseHours, sizeof( szParseHours ) );
       
        static szName[ 32 ];
        get_user_name( id, szName, sizeof( szName ) -1 );
       
        if( equali( szParseName, szName ) )
        {
            C_PrintChat( id, "Ai !v%i!c/!v%i!c warn-uri, respectati programul zilnic sau primesti remove.", g_iPlayerWarn[ id ], MAX_WARN );
        }
    }
   
    fclose( szFile );
   
    return 1;
}

public cmdProgram( id )
{
    if( get_user_flags( id ) & ADMIN_SLAY )
    {
        new szFile = fopen( g_szFile, "r" );
       
        if( !szFile )
            return 1;
       
        new szData[ 512 ], szParseName[ 32 ], szParseHours[ 32 ];
       
        while( !feof( szFile ) )
        {
            fgets( szFile, szData, sizeof( szData ) -1 );
           
            if( szData[ 0 ] == ';' || szData[ 0 ] == '!' || szData[ 0 ] == '/' && szData[ 1 ] == '/' )
                continue;
           
            parse( szData, szParseName, sizeof( szParseName ), szParseHours, sizeof( szParseHours ) );
           
            static szName[ 32 ];
            get_user_name( id, szName, sizeof( szName ) -1 );

            if( equali( szParseName, szName ) )
            {
                C_PrintChat( id, "Mai ai !v%i!c ore pana iti termini programul de azi.", g_iHourPlayer[ id ] );
            }
        }
       
        fclose( szFile );
    }
   
    else
    {
        C_PrintChat( id, "Ne pare rau, dar nu ai admin pe server." );
    }
   
    return 1;
}

public client_disconnect( id )
{
    new iHour, iMinute;
    time( iHour, iMinute, _ );

   
        SaveHours( id );
   
}

public adaugareMinut( id )
{
    if( is_user_connected( id ) && !is_user_bot( id ) )
    {
        g_iPlayerStats[ id ] += 1;
       
        if( g_iPlayerMinutes[ id ] >= 60 )
        {
            g_iHourPlayer[ id ] -= 1;
            g_iPlayerStats[ id ] += 1;
            g_iPlayerMinutes[ id ] -= 60;
        }
    }
}

public verifyPlayer( id )
{
    new szFile = fopen( g_szFile, "r" );
   
    if( !szFile )
        return 1;
   
    new szData[ 512 ], szParseName[ 32 ], szParseHours[ 32 ];
   
    static szName[ 32 ];
    get_user_name( id, szName, sizeof( szName ) -1 );
   
    while( !feof( szFile ) )
    {
        fgets( szFile, szData, sizeof( szData ) -1 );
       
        if( szData[ 0 ] == ';' || szData[ 0 ] == '!' || szData[ 0 ] == '/' && szData[ 1 ] == '/' )
            continue;
       
        parse( szData, szParseName, sizeof( szParseName ), szParseHours, sizeof( szParseHours ) );
       
        if( equali( szParseName, szName ) )
        {
            if( g_iPlayerStats[ id ] >= str_to_num( szParseHours ) )
            {
                log_to_file( "activity_admins.log", "%s si-a respectat programul cu %i/%i ore.", szName, g_iPlayerStats[ id ], str_to_num( szParseHours ) );   
            }
           
            else
            {
                log_to_file( "activity_admins.log", "%s a stat doar %i minute pe server. A primit 1 warn.", szName, g_iPlayerStats[ id ], str_to_num( szParseHours ), g_iPlayerMinutes[ id ] );
               
                C_PrintChat( id, "Atentie ! Azi ai facut !v%i!c minute. Trebuie sa stai minim !v%i!c ore.", g_iPlayerMinutes[ id ], str_to_num( szParseHours ), str_to_num( szParseHours ) );
                C_PrintChat( id, "Ai primit !v1!c warn, pentru ca nu ai stat !v%i!c ore. (!v%i!c/!v%i!c)", str_to_num( szParseHours ), g_iPlayerStats[ id ], str_to_num( szParseHours ) );
               
                g_iPlayerWarn[ id ] += 1;
            }
           
            g_iHourPlayer[ id ] =  str_to_num( szParseHours );
        }
    }
   
    fclose( szFile );
   
    return 1;
}
       
public LoadHours( id )
{
    new szVaultData[ 256 ], szVaultKey[ 32 ];
   
    static szName[ 32 ];
    get_user_name( id, szName, sizeof( szName ) -1 );
   
    format( szVaultKey, sizeof( szVaultKey ) -1, "%s", szName );
    format( szVaultData, sizeof( szVaultData ) -1, "%i#%i#%i", g_iPlayerStats[ id ], g_iPlayerMinutes[ id ], g_iPlayerWarn[ id ] );   
   
    new szVaultFile = nvault_open( "_file_activity_adm" );
    nvault_get( szVaultFile, szVaultKey, szVaultData, sizeof( szVaultData ) -1 );
   
    replace_all( szVaultData, sizeof( szVaultData ), "#", " " );
   
    new iHours[ 32 ], iWarn[ 33 ], iMinutes[ 33 ];
    parse( szVaultData,\
        iHours, sizeof( iHours ) -1,\
        iWarn, sizeof( iWarn ) -1,\
        iMinutes, sizeof( iMinutes ) -1 );
   
    g_iPlayerStats[ id ] = str_to_num( iHours );
    g_iPlayerWarn[ id ] = str_to_num( iWarn );
    g_iPlayerMinutes[ id ] = str_to_num( iMinutes );
}

public SaveHours( id )
{
    new szVaultData[ 256 ], szVaultKey[ 32 ];
   
    static szName[ 32 ];
    get_user_name( id, szName, sizeof( szName ) -1 );
   
    format( szVaultKey, sizeof( szVaultKey ) -1, "%s", szName );
    format( szVaultData, sizeof( szVaultData ) -1, "%i#%i#%i", g_iPlayerStats[ id ], g_iPlayerMinutes[ id ], g_iPlayerWarn[ id ] );
   
    new szVaultFile = nvault_open( "_file_activity_adm" );
    nvault_set( szVaultFile, szVaultKey, szVaultData );
}

stock C_PrintChat( const id, const szInput[ ], any:... )
{
    new iPlayers[ 32 ], iNum = 1;
   
    static szMsg[ 320 ], szMsg2[ 320 ];
   
    vformat( szMsg, sizeof( szMsg ) -130, szInput, 3 );
    format( szMsg2, sizeof( szMsg2 ) -130, "!c[!vHNS!c] %s", szMsg );
   
    replace_all( szMsg2, sizeof( szMsg ) -130, "!v", "^x04" );
    replace_all( szMsg2, sizeof( szMsg ) -130, "!c", "^x01" );
    replace_all( szMsg2, sizeof( szMsg ) -130, "!e", "^x03" );
   
    if( id )
    {
        iPlayers[ 0 ] = id;
    }
   
    else
    {
        get_players( iPlayers, iNum, "c" );
    }
   
    for( new i = 0; i < iNum; i++ )
    {
        if( is_user_connected( iPlayers[ i ] ) )
        {
            message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, iPlayers[ i ] );
           
            write_byte( iPlayers[ i ] );
            write_string( szMsg2 );
           
            message_end( );
        }
    }
}


alan_el_more 11-21-2013 18:14

Re: Plugin don't work
 
Use a descriptive title

smiley92 11-22-2013 09:35

Re: Plugin don't work
 
Quote:

Originally Posted by alan_el_more (Post 2063745)
Use a descriptive title

For what?Name description is OK I say.
Can help me?

LordOfNothing 11-22-2013 11:29

Re: Plugin don't work
 
@smiley please forgive alan_el_more he like to make useles post , so use this

smiley92 11-23-2013 03:03

Re: Plugin don't work
 
Quote:

Originally Posted by LordOfNothing (Post 2064037)
@smiley please forgive alan_el_more he like to make useles post , so use this

I don't know how to change code of hours to be saved good, can help me please? xD

fysiks 11-23-2013 05:41

Re: Plugin don't work
 
Quote:

Originally Posted by smiley92 (Post 2063985)
For what?Name description is OK I say.
Can help me?

The thread title must be descriptive (it's a forum rule and extremely annoying when you don't follow it).

Quote:

Originally Posted by smiley92 (Post 2064296)
I don't know how to change code of hours to be saved good, can help me please? xD

You need to describe what your problem is. Describe what is happening and what you want to happen.

smiley92 11-23-2013 07:03

Re: Plugin don't work
 
Quote:

Originally Posted by fysiks (Post 2064353)
The thread title must be descriptive (it's a forum rule and extremely annoying when you don't follow it).



You need to describe what your problem is. Describe what is happening and what you want to happen.

Now is better?Some can help me? :shock:

fysiks 11-23-2013 15:45

Re: Plugin don't work
 
Quote:

Originally Posted by fysiks (Post 2064353)
You need to describe what your problem is. Describe what is happening and what you want to happen.


smiley92 11-23-2013 16:13

Re: Plugin don't work
 
You view what I edited?

fysiks 11-23-2013 20:43

Re: Plugin don't work
 
Quote:

Originally Posted by smiley92 (Post 2064586)
You view what I edited?

I just tried to read it but I'm having trouble since it's not really in comprehensible English.


All times are GMT -4. The time now is 23:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.