Raised This Month: $ Target: $400
 0% 

Question about undefined symbols


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
puttsmobiles
Senior Member
Join Date: Mar 2009
Location: Chicago
Old 10-12-2010 , 01:43   Question about undefined symbols
Reply With Quote #1

Code:
#include < amxmodx >
#include < amxmisc >
#include < engine >

new const g_szVaultKey[ ] = "last_restart";

new g_iEntity;
new g_iNextTime;

public plugin_init( ) {
    register_plugin( "Restart At X Hour", "0.0.1", "Exolent" );
    
    new const szClassname[ ] = "restart_entity";
    g_iEntity = create_entity( "info_target" );
    entity_set_string( g_iEntity, EV_SZ_classname, szClassname );
    register_think( szClassname, "FwdRestart" );
    
    new iRestartHour = get_pcvar_num( register_cvar( "amx_restart_hour", "5" ) );
    
    new iLastTime;
    if( !vaultdata_exists( g_szVaultKey ) ) {
        new szHour[ 3 ], szDay[ 3 ], szMonth[ 3 ], szYear[ 5 ];
        format_time( szHour, 2, "%H" );
        format_time( szDay, 2, "%d" );
        format_time( szMonth, 2, "%m" );
        format_time( szYear, 4, "%Y" );
        
        new iCurHour = str_to_num( szHour );
        new iCurDay = str_to_num( szDay );
        new iCurMonth = str_to_num( szMonth );
        new iCurYear = str_to_num( szYear );
        
        if( iCurHour < iRestartHour ) {
            if( --iCurDay == 0 ) {
                if( --iCurMonth == 0 ) {
                    iCurDay = 31;
                    iCurMonth = 12;
                    iCurYear--;
                } else {
                    switch( iCurMonth ) {
                        case 1, 3, 5, 7, 8, 10, 12: {
                            iCurDay = 31;
                        }
                        case 4, 6, 9, 11: {
                            iCurDay = 30;
                        }
                        case 2: {
                            iCurDay = IsLeapYear( iCurYear ) ? 29 : 28;
                        }
                    }
                }
            }
        }
        
        iLastTime = TimeToUnix( iCurYear, iCurMonth, iCurDay, iRestartHour, 0, 0 );
        
        new szTime[ 32 ];
        num_to_str( iLastTime, szTime, 31 );
        set_vaultdata( g_szVaultKey, szTime );
    } else {
        iLastTime = get_vaultdata( g_szVaultKey );
        
        new iYear, iMonth, iDay, iHour, iMinute, iSecond;
        UnixToTime( iLastTime, iYear, iMonth, iDay, iHour, iMinute, iSecond );
        
        // if plugin was recompiled with a different hour,
        // this makes sure the new hour is used instead of continuing with 24-hour interval from the first hour used
        if( iHour != iRestartHour ) {
            iHour = iRestartHour;
            iLastTime = TimeToUnix( iYear, iMonth, iDay, iHour, iMinute, iSecond );
        }
    }
    
    g_iNextTime = iLastTime + ( 60 * 60 * 24 ); // 60 * 60 * 24 = 24 hours in seconds
    new iCurTime = get_systime( );
    if( g_iNextTime <= iCurTime ) {
        FwdRestart( g_iEntity );
    } else {
        entity_set_float( g_iEntity, EV_FL_nextthink, get_gametime( ) + float( iNextTime - iCurTime ) );
    }
}

public FwdRestart( iEntity ) {
    if( iEntity == g_iEntity ) {
        static szTime[ 32 ];
        num_to_str( g_iNextTime, szTime, 31 );
        set_vaultdata( g_szVaultKey, szTime );
        
        client_print( 0, print_chat, "[ RESTART ] Sorry, everyone. The server is scheduled to restart in 5 seconds..." );
        
        set_task( 5.0, "TaskRestart" );
    }
}

public TaskRestart( ) {
    server_cmd( "restart" );
}

// Unix Time Conversion by Bugsy
stock const YearSeconds[2] = 
{ 
    31536000,    //Normal year
    31622400     //Leap year
};

stock const MonthSeconds[12] = 
{ 
    2678400, //January    31 
    2419200, //February    28
    2678400, //March    31
    2592000, //April    30
    2678400, //May        31
    2592000, //June        30
    2678400, //July        31
    2678400, //August    31
    2592000, //September    30
    2678400, //October    31
    2592000, //November    30
    2678400  //December    31
};

stock const DaySeconds = 86400;
stock const HourSeconds = 3600;
stock const MinuteSeconds = 60;

stock UnixToTime( iTimeStamp , &iYear , &iMonth , &iDay , &iHour , &iMinute , &iSecond )
{
    new iNewTimeStamp = iTimeStamp;
    
    new iTemp;
    
    iYear = 1970;
    iMonth = 1;
    iDay = 1;
    iHour = 0;

    while ( iNewTimeStamp > 0 )
    {
        iTemp = IsLeapYear(iYear);

        if ( ( iNewTimeStamp - YearSeconds[iTemp] ) >= 0 )
        {
            iNewTimeStamp -= YearSeconds[iTemp];
            iYear++;
        }
        else
        {
            break;
        }
    }

    while ( iNewTimeStamp > 0 )
    {
        iTemp = SecondsInMonth( iYear , iMonth );

        if ( ( iNewTimeStamp - iTemp ) >= 0 ) 
        {
            iNewTimeStamp -= iTemp;
            iMonth++;
        }
        else
        {
            break;
        }
    }

    while ( iNewTimeStamp > 0)
    {
        if ( ( iNewTimeStamp - DaySeconds ) >= 0 )
        {
            iNewTimeStamp -= DaySeconds;
            iDay++;
        }
        else
        {
            break;
        }
    }
    
    while ( iNewTimeStamp > 0 )
    {
        if ( ( iNewTimeStamp - HourSeconds ) >= 0 )
        {
            iNewTimeStamp -= HourSeconds;
            iHour++;
        }
        else
        {
            break;
        }
    }
    
    iMinute = ( iNewTimeStamp / 60 );
    iSecond = ( iNewTimeStamp % 60 );
}

stock TimeToUnix( const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond )
{
    new i;
    new iTimeStamp;

    for ( i = 1970 ; i < iYear ; i++ )
        iTimeStamp += YearSeconds[ IsLeapYear(i) ];

    for ( i = 1 ; i < iMonth ; i++ )
        iTimeStamp += SecondsInMonth( iYear , i );

    iTimeStamp += ( ( iDay - 1 ) * DaySeconds );
    iTimeStamp += ( iHour * HourSeconds );
    iTimeStamp += ( iMinute * MinuteSeconds );
    iTimeStamp += iSecond;

    return iTimeStamp;
}

stock SecondsInMonth( const iYear , const iMonth ) 
{
    return ( ( IsLeapYear( iYear ) && ( iMonth == 2 ) ) ? ( MonthSeconds[iMonth - 1] + DaySeconds ) : MonthSeconds[iMonth - 1] );
}

stock IsLeapYear( const iYear ) 
{
    return ( ( (iYear % 4) == 0) && ( ( (iYear % 100) != 0) || ( (iYear % 400) == 0 ) ) );
}

One problem.

When I try to compile I get this error. "error 017: undefined symbol "iNextTime""

Anything we can do about this? I see in the code that it seems to be defined. but it claims it's not.
__________________
Dan Hiorns - www.danhiorns.us
puttsmobiles is offline
Send a message via AIM to puttsmobiles Send a message via MSN to puttsmobiles Send a message via Yahoo to puttsmobiles Send a message via Skype™ to puttsmobiles
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:41.


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