AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question about undefined symbols (https://forums.alliedmods.net/showthread.php?t=140425)

puttsmobiles 10-12-2010 01:43

Question about undefined symbols
 
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.

fysiks 10-12-2010 02:01

Re: Question about undefined symbols
 
Quote:

Originally Posted by puttsmobiles (Post 1322691)
Anything we can do about this? I see in the code that it seems to be defined. but it claims it's not.

Look again. It's not defined. Maybe look harder this time (Hint: use a program to search for the variable iNextTime)

puttsmobiles 10-12-2010 02:05

Re: Question about undefined symbols
 
Well does it really need to be defined? If I was to take it out would it still function properly?

I'm trying to learn but it's a slow going for me. :[

fysiks 10-12-2010 02:20

Re: Question about undefined symbols
 
Quote:

Originally Posted by puttsmobiles (Post 1322697)
Well does it really need to be defined? If I was to take it out would it still function properly?

I'm trying to learn but it's a slow going for me. :[

Did you modify this code after Exolent posted a working version?

You usually you can't just remove something if it is undefined. As is the case here.

puttsmobiles 10-12-2010 02:23

Re: Question about undefined symbols
 
I just copy pasted the code from his box.

Tried to compile failed.

I wouldn't know what to modify lol

fysiks 10-12-2010 02:37

Re: Question about undefined symbols
 
Change iNextTime to g_iNextTime.

(If you didn't modify the code you should have posted in the thread where Exolent posted it)


All times are GMT -4. The time now is 10:17.

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