Raised This Month: $51 Target: $400
 12% 

Solved Expire date


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-16-2018 , 15:45   Expire date
Reply With Quote #1

I made up this stock to check if a player's suspension has expired, but I feel like it won't work, unfortunately I'm unable to test because it uses days as the value and I must wait at least 1 day to find out if it works or not. Basically it compares the date the player was suspended with the current date.

Anyways, anyone has any idea whether it is correct, if not, could you provide a better way? I know about UNIX but I'm not sure on how it works.

PHP Code:
bool:HasSuspendExpired( const szExpireDate[ ] )
{
    new 
szCurrentDate];
    
get_time"%D"szCurrentDatecharsmaxszCurrentDate ) );
    
    new 
szTodayDay], szTodayMonth], szTodayYear];
    
num_to_strstr_to_numszCurrentDate ), szTodayMonthcharsmaxszTodayMonth ) );
    
num_to_strstr_to_numszCurrentDate] ), szTodayDaycharsmaxszTodayDay ) );
    
num_to_strstr_to_numszCurrentDate] ), szTodayYearcharsmaxszTodayYear ) );
    
    new 
szExpireDay], szExpireMonth], szExpireYear];
    
num_to_strstr_to_numszExpireDate ), szExpireMonthcharsmaxszExpireMonth ) );
    
num_to_strstr_to_numszExpireDate] ), szExpireDaycharsmaxszExpireDay ) );
    
num_to_strstr_to_numszExpireDate] ), szExpireYearcharsmaxszExpireYear ) );
    
    new 
iTodayDay str_to_numszTodayDay );
    new 
iTodayMonth str_to_numszTodayMonth );
    new 
iTodayYear str_to_numszTodayYear );
    
    new 
iExpireDay str_to_numszExpireDay );
    new 
iExpireMonth str_to_numszExpireMonth );
    new 
iExpireYear str_to_numszExpireYear );
    
    if( 
iTodayYear iExpireYear ) return true;
    if( 
iTodayMonth iExpireMonth ) return true;
    if( 
iTodayDay iExpireDay ) return true;

__________________

Last edited by edon1337; 08-20-2018 at 15:29.
edon1337 is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-16-2018 , 16:13   Re: Expire date
Reply With Quote #2

No help just this one looks more efficient:

Code:
bool:HasSuspendExpired( const szExpireDate[ ] )
{
    new szCurrentDate[ 9 ];
    get_time( "%D", szCurrentDate, charsmax( szCurrentDate ) );
    
   
    new iTodayDay;
    new iTodayMonth
    new iTodayYear;
    
    new iExpireDay;
    new iExpireMonth;
    new iExpireYear;
    
    new szTodayDay[ 3 ], szTodayMonth[ 3 ], szTodayYear[ 3 ];
    num_to_str( iTodayMonth = str_to_num( szCurrentDate ), szTodayMonth, charsmax( szTodayMonth ) );
    num_to_str( iTodayDay  =  str_to_num( szCurrentDate[ 3 ] ), szTodayDay, charsmax( szTodayDay ) );
    num_to_str( iTodayYear  = str_to_num( szCurrentDate[ 6 ] ), szTodayYear, charsmax( szTodayYear ) );
    
    new szExpireDay[ 3 ], szExpireMonth[ 3 ], szExpireYear[ 3 ];
    num_to_str( iExpireMonth = str_to_num( szExpireDate ), szExpireMonth, charsmax( szExpireMonth ) );
    num_to_str( iExpireDay = str_to_num( szExpireDate[ 3 ] ), szExpireDay, charsmax( szExpireDay ) );
    num_to_str( iExpireYear = str_to_num( szExpireDate[ 6 ] ), szExpireYear, charsmax( szExpireYear ) );
    
    if( iTodayYear > iExpireYear ) return true;
    if( iTodayMonth > iExpireMonth ) return true;
    if( iTodayDay > iExpireDay ) return true;
}
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
shauli
Member
Join Date: Jun 2018
Old 08-16-2018 , 16:38   Re: Expire date
Reply With Quote #3

Wow, this is really complicated. Use Unix.
PHP Code:
bool:HasSuspendExpired( const iExpireTime )
{
    if( 
get_systime( ) > iExpireTime )
        return 
true;
    
    return 
false;
}

/*
    format_time( szDate, iLen, "%d/%m/%Y %H:%M", iTimeStamp );
    result: 16/08/2018 23:34
    
    Suspension for 2 days:

    SECONDS_IN_DAY = 86400;
    iExpireTime = get_systime( ) + ( SECONDS_IN_DAY * 2 );
*/ 
I'd also recommend you to check Bugsy's Unix Time include.
shauli is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 16:39   Re: Expire date
Reply With Quote #4

wtf

PHP Code:
bool:HasSuspendExpired(const szInput[])
    return 
get_systime() > parse_time(szInput"%D"); 
__________________

Last edited by OciXCrom; 08-16-2018 at 16:41.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-16-2018 , 16:54   Re: Expire date
Reply With Quote #5

Code:
bool:HasSuspendExpired(){}
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM
Ghosted is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-16-2018 , 17:19   Re: Expire date
Reply With Quote #6

Quote:
Originally Posted by shauli View Post
Wow, this is really complicated. Use Unix.
PHP Code:
bool:HasSuspendExpired( const iExpireTime )
{
    if( 
get_systime( ) > iExpireTime )
        return 
true;
    
    return 
false;
}

/*
    format_time( szDate, iLen, "%d/%m/%Y %H:%M", iTimeStamp );
    result: 16/08/2018 23:34
    
    Suspension for 2 days:

    SECONDS_IN_DAY = 86400;
    iExpireTime = get_systime( ) + ( SECONDS_IN_DAY * 2 );
*/ 
I'd also recommend you to check Bugsy's Unix Time include.
Sorry but, I already mentioned it, I know nothing about Unix..

PHP Code:
const SECONDS_IN_DAY 86400;

public 
plugin_init( )
{
    
RegisterHamHam_Spawn"player""@Spawn");
    
    
g_iVault nvault_open"suspend_system" );
    
    
register_clcmd"say /suspend""OnSuspendPlayer" );
}

@
Spawnid )
{
    
CheckSuspendedid );
    
client_print_coloridDontChange"^4[Suspend System] ^3Your suspension has expired" );
}

public 
OnSuspendPlayerid )
{
    
SuspendSaveDataid"DoNii");
}

SuspendSaveData( const id, const szName[ ], const iDays )
{
    if( ! 
is_user_connectedid ) || is_user_botid ) )
    return 
0;

    
nvault_closeg_iVault );
    
g_iVault nvault_open"suspend_system" );
    
    new 
szDate18 ], iTimeStamp;
    
format_timeszDateiLen"%d/%m/%Y %H:%M"iTimeStamp );
    
    
nvault_setg_iVaultszNameszDate );
    
    return 
1;
}

CheckSuspendedid )
{
    if( ! 
is_user_connectedid ) || is_user_botid ) )
    return 
0;

    new 
szName32 ], szExpireTime18 ];
    
get_user_nameidszNamecharsmaxszName ) );
    
    
nvault_getg_iVaultszNameszExpireTimecharsmaxszExpireTime ) );
    
    new 
iExpireTime str_to_numszExpireTime );
    if( 
HasSuspendExpirediExpireTime ) )
    {
        
UnSuspendPlayerid );
        
nvault_removeg_iVaultszName );
    }
    
    return 
1;
}

bool:HasSuspendExpired( const iExpireTime 

    if( 
get_systime( ) > iExpireTime 
    return 
true
    
    return 
false

__________________

Last edited by edon1337; 08-16-2018 at 17:25.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 17:31   Re: Expire date
Reply With Quote #7

Use my variant if you want to pass the date as a string, otherwise take a look at the parse_time and format_time functions.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-16-2018 , 17:39   Re: Expire date
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
Use my variant if you want to pass the date as a string, otherwise take a look at the parse_time and format_time functions.
What do I need to do when using your stock if I want to save the expire date in nVault?
__________________
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 08-16-2018 , 18:44   Re: Expire date
Reply With Quote #9

Save the date in %D format.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Old 08-16-2018, 19:11
edon1337
This message has been deleted by edon1337.
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-18-2018 , 13:00   Re: Expire date
Reply With Quote #10

When I use this stock (notice the >=)
PHP Code:
bool:HasSuspendExpired(const szInput[])
    return 
get_systime() >= parse_time(szInput"%D"); 
it always returns true, even if I set an expire date of 10 days, why does this happen? I added = so it would return true when I set 0 days.

Using that instead of this
Quote:
Originally Posted by OciXCrom View Post
PHP Code:
bool:HasSuspendExpired(const szInput[])
    return 
get_systime() > parse_time(szInput"%D"); 
because with this I'm supposed to wait at least 1 day to find out whether it works
__________________

Last edited by edon1337; 08-18-2018 at 13:36.
edon1337 is offline
Reply



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:04.


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