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

How to set time tutorial


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 05-25-2023 , 17:11   How to set time tutorial
Reply With Quote #1

Hello, Every one QuickDroLLL here so basicly iam loking for tutorial that help you how to set time in plugins for example i want to create ban system that bans player from cts for example by typing
amx_banct "Name of Player" "Time" the time will be in minutes so when typing amx_banct "QuickDroLLL" "300" he will be banned for 300 mins after 300 mins his banned will expired and the time will be saved so when he exit/crashed his ban time will not expire

Last edited by QuickDroLLL; 05-25-2023 at 17:12.
QuickDroLLL is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-25-2023 , 23:42   Re: How to set time tutorial
Reply With Quote #2

Basically, you can simply calculate the time/date that the person should be unbanned and store that in a file/database. If the current time is less than the stored time then disallow the function for that player otherwise allow it.

When you read the unban date/time in when the plugin starts, you should store it in a Trie with the key being the SteamID. This will make it much more efficient to check if the player is banned. When you add the ban, make sure to update the Trie and write it to the file.

That should get you the basic functionality.
__________________
fysiks is offline
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 05-26-2023 , 08:05   Re: How to set time tutorial
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Basically, you can simply calculate the time/date that the person should be unbanned and store that in a file/database. If the current time is less than the stored time then disallow the function for that player otherwise allow it.

When you read the unban date/time in when the plugin starts, you should store it in a Trie with the key being the SteamID. This will make it much more efficient to check if the player is banned. When you add the ban, make sure to update the Trie and write it to the file.

That should get you the basic functionality.
Can you give me example bcz iam new
QuickDroLLL is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-26-2023 , 08:13   Re: How to set time tutorial
Reply With Quote #4

i give you a tutorial

PHP Code:
new whencan[id] = get_systime(86400// 86400 in seconds = 1 day


//how to check
if(whencan[id] <= get_systime())
{
      
//user can
}
else
{
      
//user can't


Last edited by lexzor; 05-26-2023 at 08:13.
lexzor is offline
QuickDroLLL
Senior Member
Join Date: Dec 2021
Location: AMX Mod X Land
Old 05-26-2023 , 08:20   Re: How to set time tutorial
Reply With Quote #5

Quote:
Originally Posted by lexzor View Post
i give you a tutorial

PHP Code:
new whencan[id] = get_systime(86400// 86400 in seconds = 1 day


//how to check
if(whencan[id] <= get_systime())
{
      
//user can
}
else
{
      
//user can't

so when user can he is unbanned and when user can't he is banned?

Last edited by QuickDroLLL; 05-26-2023 at 08:21.
QuickDroLLL is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-26-2023 , 08:44   Re: How to set time tutorial
Reply With Quote #6

Quote:
Originally Posted by QuickDroLLL View Post
so when user can he is unbanned and when user can't he is banned?
get_systime -> https://www.amxmodx.org/api/amxmodx/get_systime


PHP Code:
#include <amxmodx>

public plugin_init()
{
    
register_clcmd("ban""banCmd")
}

public 
banCmd(id)
{
    new 
szTargetName[MAX_NAME_LENGTH], iTarget

    read_argv
(1szTargetNamecharsmax(szTargetName)) //reading target name from the command

    
if(!(iTarget find_player("b")))
    {
        
client_print(idprint_console"User is not connected!")
        return 
PLUGIN_CONTINUE;
    }

    new 
iTime read_argv_int(2) * 60 // reading ban time. we are expecting here are time in minutes, so we transform it in seconds

    
new iUnbanTime get_systime(iTime// when player can be unbanned (in seconds)

    /*
        code for ban with saving the user name or ip or whatever in nvault/mysql 
    */ 

    //kick player from the server
    
server_cmd("kick #%i ^"You have been banned from this server^""get_user_index(iTarget))
    
server_exec()
}

public 
client_connect(id)
{
    
//checking if player is banned (in this case by name)
    
static szName[MAX_NAME_LENGTH]
    
get_user_name(idszNamecharsmax(szName))

    if(
is_user_banned(szName))
    {
        
server_cmd("kick #%i ^"You are banned from this server^"")
        
server_exec()
    }
}

stock bool:is_user_banned(const name)
{
    
//check if player is banned true or false


    //case user has been found in the banned list
    
    
if(iUnbanTime <= get_systime())
    {
        return 
false //user is not banned because ban time is lower than current timestamp
    


    return 
true


Last edited by lexzor; 05-26-2023 at 08:46.
lexzor 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 09:12.


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