This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Solved help with sys_time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-10-2023 , 13:48   help with sys_time
Reply With Quote #1

hello i want to make timer using thinking entity but i need also a way to use sys_time


problem solved
here is my solution:
https://forums.alliedmods.net/showpo...57&postcount=8
__________________

Last edited by xDrugz; 11-12-2023 at 13:44.
xDrugz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-10-2023 , 23:51   Re: help with sys_time
Reply With Quote #2

Ok, what is your question/problem? get_systime() is the native to get sys_time.
__________________
Bugsy is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-11-2023 , 04:46   Re: help with sys_time
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Ok, what is your question/problem? get_systime() is the native to get sys_time.
i want to create timer by using get_systime
i'm working on a ban plugin so i want to create an entity thinker so the ban will get lifted within the time the player has been banned for. in the past i knew how to do it but i just returned to amxx coding and i forgot everything
__________________

Last edited by xDrugz; 11-11-2023 at 05:06.
xDrugz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-11-2023 , 16:30   Re: help with sys_time
Reply With Quote #4

Ok, so you can use a set_task() w/ flag "b" or a thinking entity, with set_task being the easier option. When you apply a ban, record the get_systime() value in an array for that player. At each interval of your task/thinking entity, check if (get_systime() - PlayerBanTime[ id ]) >= BanDurationSeconds, if that is true, remove the ban.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-11-2023 , 16:47   Re: help with sys_time
Reply With Quote #5

A timer is completely unnecessary for something like this and will likely have issues. All you need to do is store the timestamp for when the ban expires and then simply check to see if it's before or after that timestamp when they join the server. If they join before the timestamp, they are still banned. If they join after the timestamp then they are not banned.

If you're trying to ban something else (something in-game and not joining the server itself), you do the same thing except when they try to use this banned function, you check to see if they are prohibited in the same manner.
__________________

Last edited by fysiks; 11-11-2023 at 16:48.
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-11-2023 , 21:13   Re: help with sys_time
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
A timer is completely unnecessary for something like this and will likely have issues. All you need to do is store the timestamp for when the ban expires and then simply check to see if it's before or after that timestamp when they join the server. If they join before the timestamp, they are still banned. If they join after the timestamp then they are not banned.

If you're trying to ban something else (something in-game and not joining the server itself), you do the same thing except when they try to use this banned function, you check to see if they are prohibited in the same manner.
Agreed, for whatever reason I was thinking along the lines of the player being on the server and restricting(banning) stuff in-game and lifting it in real-time when a ban expires. This would support telling a player when they become unbanned from an item/function opposed to allowing it when/if the player attempts to use what was banned.

As fysiks said, from a server connection ban perspective, when a connection attempt is made just do your check there and un-ban if expired/allow connection.
__________________
Bugsy is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-12-2023 , 05:30   Re: help with sys_time
Reply With Quote #7

thank you for the idea! i will try it now
__________________
xDrugz is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-12-2023 , 13:42   Re: help with sys_time
Reply With Quote #8

gr8 thank you all, here what i did

Code:
public ABThinker_FUNC( iEnt )
{
	new szArrayData[ MAX_LENGTH ], szParseData[ 3 ][ 64 ];
	
	new arrSize = ArraySize( g_aBannedList ), iCurrentTime, iPassedTime, iBannedTime;
	
	if( arrSize )
	{
		for( new i = 0; i < arrSize; i++ )
		{
			ArrayGetString( g_aBannedList, i, szArrayData, charsmax( szArrayData ) );
			
			parse( szArrayData, szParseData[ 0 ], charsmax( szParseData[] ), szParseData[ 1 ], charsmax( szParseData[] ), szParseData[ 2 ], charsmax( szParseData[] ) );
			
			if( strcmp( szParseData[ 1 ], "PERM" ) )
			{
				iCurrentTime = get_systime();
				iBannedTime = ( str_to_num( szParseData[ 1 ] ) );
				iPassedTime = ( iCurrentTime - str_to_num( szParseData[ 2 ] ) );
				
				if( iPassedTime >= iBannedTime )
				{
					ArrayDeleteItem( g_aBannedList, i );
					SaveBannedToFile( g_aBannedList, g_szBannedList );
				}
			}
		}
	}
	
	entity_set_float( g_iABEnt, EV_FL_nextthink, get_gametime() + AB_FLOAT );
}
it is now working!
__________________
xDrugz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-12-2023 , 13:57   Re: help with sys_time
Reply With Quote #9

It works, but it's excess for this purpose. You can simply use this logic at client_authorized().

Use the AddBan function to test it yourself for a 30 second ban.
PHP Code:
#include <amxmodx>
#include <nvault>

new g_Vault;

public 
plugin_init() 
{
    
g_Vault nvault_open"BanVault" );
    
    
register_clcmd"say ban" "AddBan" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szAuthID34 ] , iTimestamp szDuration11 ];
    
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    if ( 
nvault_lookupg_Vault szAuthID szDuration charsmaxszDuration ) , iTimestamp ) )
    {
        if ( ( 
iTimestamp str_to_numszDuration ) ) < get_systime() )
        {
            
server_print"allow connection, ban expired" );
            
nvault_removeg_Vault szAuthID );
        }
        else
        {
            
server_print"still banned" );
        }
    }
    else
    {
        
server_print"not banned" );
    }
}

public 
AddBanid )
{
    new 
szAuthID34 ] ;
    
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    
nvault_setg_Vault szAuthID "30" );

__________________
Bugsy is offline
xDrugz
Senior Member
Join Date: Jul 2011
Location: return 4;
Old 11-12-2023 , 14:03   Re: help with sys_time
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
It works, but it's excess for this purpose. You can simply use this logic at client_authorized().

Use the AddBan function to test it yourself for a 30 second ban.
PHP Code:
#include <amxmodx>
#include <nvault>

new g_Vault;

public 
plugin_init() 
{
    
g_Vault nvault_open"BanVault" );
    
    
register_clcmd"say ban" "AddBan" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szAuthID34 ] , iTimestamp szDuration11 ];
    
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    if ( 
nvault_lookupg_Vault szAuthID szDuration charsmaxszDuration ) , iTimestamp ) )
    {
        if ( ( 
iTimestamp str_to_numszDuration ) ) < get_systime() )
        {
            
server_print"allow connection, ban expired" );
            
nvault_removeg_Vault szAuthID );
        }
        else
        {
            
server_print"still banned" );
        }
    }
    else
    {
        
server_print"not banned" );
    }
}

public 
AddBanid )
{
    new 
szAuthID34 ] ;
    
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    
nvault_setg_Vault szAuthID "30" );

thank you
__________________
xDrugz 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 19:08.


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