AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   [REQ] Play Time (https://forums.alliedmods.net/showthread.php?t=301888)

khashayar007 10-08-2017 09:23

[REQ] Play Time
 
Hi. I want a plugin when a player played more than 48 hours gets TZ flag(VIP).

Bugsy 10-08-2017 09:43

Re: [REQ] Play Time
 
Untested and I'm not sure what flag you want, so you need to update that part in the code.
PHP Code:


#include <amxmodx>
#include <nvault>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

const FortyEightHours = ( 86400 );

enum PlayerData
{
    
pdAuthID34 ],
    
pdConnectTime,
    
pdPlayTime,
    
pdIgnorePlayer
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Play Time VIP" Version "bugsy" );

    
g_Vault nvault_open"ptvip" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szTime11 ] , iTS szMsg48 ];
    
    if ( !( 
g_pdDataid ][ pdIgnorePlayer ] = ( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
get_user_authidid g_pdDataid ][ pdAuthID ] , charsmaxg_pdData[][ pdAuthID ] ) );
        
        
g_pdDataid ][ pdConnectTime ] = get_systime();
        
        if ( 
nvault_lookupg_Vault g_pdDataid ][ pdAuthID ] , szTime charsmaxszTime ) , iTS ) )
        {
            
g_pdDataid ][ pdPlayTime ] = str_to_numszTime );
            
            if ( 
g_pdDataid ][ pdPlayTime ] >= FortyEightHours )
            {
                
set_user_flagsid ADMIN_LEVEL_F );
                
                
formatexszMsg charsmaxszMsg ) , "You have played for %d seconds and now have VIP" g_pdDataid ][ pdPlayTime ] );
            }
            else
            {
                
formatexszMsg charsmaxszMsg ) , "You have played for %d seconds. Play more to get VIP" g_pdDataid ][ pdPlayTime ] );
            }
        }
        else
        {
            
copyszMsg charsmaxszMsg ) , "This is your first time connecting." );
        }
        
        
set_task8.0 "ShowMessage" id , .parameter=szMsg , .len=sizeofszMsg ) );
    }
}

public 
client_disconnectid )
{
    new 
szTime11 ];
    
    if ( !
g_pdDataid ][ pdIgnorePlayer ] )
    {
        
num_to_strg_pdDataid ][ pdPlayTime ] + ( get_systime() - g_pdDataid ][ pdConnectTime ] ) , szTime charsmaxszTime ) );
        
nvault_setg_Vault g_pdDataid ][ pdAuthID ] , szTime );
        
g_pdDataid ][ pdPlayTime ] = 0;
    }
}

public 
ShowMessageszMsg[] , id )
{
    if ( 
is_user_connectedid ) )
    {
        
client_printid print_chat szMsg );
    }



khashayar007 10-08-2017 10:09

Re: [REQ] Play Time
 
I changed it 10 seconds for testing and It didn't work.

Bugsy 10-08-2017 10:12

Re: [REQ] Play Time
 
Did you disconnect and reconnect. And how do you know it didnt work? The message gets displayed immediately upon connecting so you wouldn't see it, I will need to add a delay.

khashayar007 10-08-2017 10:21

Re: [REQ] Play Time
 
Yes I did. After 10 seconds there was no message and also I checked it via amx_who

Bugsy 10-08-2017 10:37

Re: [REQ] Play Time
 
Try the updated code

khashayar007 10-08-2017 10:47

Re: [REQ] Play Time
 
Not working also no messages shown

Bugsy 10-08-2017 10:49

Re: [REQ] Play Time
 
Are there any errors? Steam?

khashayar007 10-08-2017 10:51

Re: [REQ] Play Time
 
No errors also I have the latest hlds (build 7561)

khashayar007 10-08-2017 11:03

Re: [REQ] Play Time
 
My hlds sometimes crashes after adding this plugin

Bugsy 10-08-2017 11:32

Re: [REQ] Play Time
 
Fixed. I found 2 things that were wrong. Shutdown your server and delete the vault file otherwise you will get a crash.

khashayar007 10-08-2017 14:50

Re: [REQ] Play Time
 
Thanks It's working but It doesn't save VIP in users.ini and when I changed my name I wasn't VIP anymore. I want it to set VIP by steam ID.

Bugsy 10-08-2017 15:11

Re: [REQ] Play Time
 
It will not modify users.ini but the player will get the flag once they connect. Name change will not impact this.

khashayar007 10-08-2017 15:28

Re: [REQ] Play Time
 
Can you make it to modify users.ini? Where does it save now?

Bugsy 10-08-2017 16:33

Re: [REQ] Play Time
 
It doesn't save anywhere, the plugin adds the flag to the player when he connects. As long as the plugin is running he will get the flag.

khashayar007 10-09-2017 09:50

Re: [REQ] Play Time
 
If I want to remove a flag from specific player how can I do this? Cause it's not in users.ini

DjSoftero 10-09-2017 09:52

Re: [REQ] Play Time
 
I̶ ̶t̶h̶i̶n̶k̶ ̶y̶o̶u̶ ̶c̶a̶n̶ ̶b̶l̶a̶c̶k̶l̶i̶s̶t̶ ̶t̶h̶e̶ ̶p̶e̶o̶p̶l̶e̶ ̶f̶r̶o̶m̶ ̶u̶s̶i̶n̶g̶ ̶t̶h̶i̶s̶ ̶b̶y̶ ̶s̶i̶m̶p̶l̶y̶ ̶a̶d̶d̶i̶d̶n̶g̶ ̶t̶h̶e̶m̶ ̶t̶o̶ ̶u̶s̶e̶r̶s̶.̶i̶n̶i̶ ̶w̶i̶t̶h̶ ̶f̶l̶a̶g̶ ̶z̶

Bugsy 10-09-2017 11:38

Re: [REQ] Play Time
 
Quote:

Originally Posted by khashayar007 (Post 2553458)
If I want to remove a flag from specific player how can I do this? Cause it's not in users.ini

I can add a blacklist command

khashayar007 10-09-2017 12:14

Re: [REQ] Play Time
 
Can you add mysql to this plugin? I mean the plugin writes playtime and steamID to database and reads it from database.

DjSoftero 10-09-2017 12:19

Re: [REQ] Play Time
 
Quote:

Originally Posted by khashayar007 (Post 2553493)
Can you add mysql to this plugin? I mean the plugin writes playtime and steamID to database and reads it from database.

tell me one good reason why this is necessary.

khashayar007 10-09-2017 12:47

Re: [REQ] Play Time
 
Cause when server shuts down the playtime for all players resets.

Bugsy 10-09-2017 17:29

Re: [REQ] Play Time
 
The play time should never reset.

Bugsy 10-09-2017 21:49

Re: [REQ] Play Time
 
Made a small fix where the previous players play time would be given to the next player if the player has never been to the server before.

khashayar007 10-10-2017 16:15

Re: [REQ] Play Time
 
How to remove a player if it's vip? So the player must play again to be vip.

Bugsy 10-10-2017 17:31

Re: [REQ] Play Time
 
I can add a command for that, too.

khashayar007 10-12-2017 15:47

Re: [REQ] Play Time
 
Ok add it.

Bugsy 10-20-2017 23:21

Re: [REQ] Play Time
 
Added blacklist and remove commands. Untested.

PHP Code:


#include <amxmodx>
#include <amxmisc>
#include <nvault>

new const Version[] = "0.2";

#define MAX_PLAYERS 32

const FortyEightHours = ( 86400 );

enum PlayerData
{
    
pdAuthID34 ],
    
pdConnectTime,
    
pdPlayTime,
    
pdIgnorePlayer
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Play Time VIP" Version "bugsy" );

    
register_clcmd"ptv_blacklist" "Blacklist" );
    
register_clcmd"ptv_removevip" "RemoveVIP" );
    
    
g_Vault nvault_open"ptvip" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szTime11 ] , iTS szMsg48 ];
    
    if ( !( 
g_pdDataid ][ pdIgnorePlayer ] = ( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
get_user_authidid g_pdDataid ][ pdAuthID ] , charsmaxg_pdData[][ pdAuthID ] ) );
        
        
g_pdDataid ][ pdConnectTime ] = get_systime();
        
        if ( 
nvault_lookupg_Vault g_pdDataid ][ pdAuthID ] , szTime charsmaxszTime ) , iTS ) )
        {
            
g_pdDataid ][ pdPlayTime ] = str_to_numszTime );
            
            if ( 
g_pdDataid ][ pdPlayTime ] != -)
            {
                if ( 
g_pdDataid ][ pdPlayTime ] >= FortyEightHours )
                {
                    
set_user_flagsid ADMIN_LEVEL_F );
                    
                    
formatexszMsg charsmaxszMsg ) , "You have played for %d seconds and now have VIP" g_pdDataid ][ pdPlayTime ] );
                }
                else
                {
                    
formatexszMsg charsmaxszMsg ) , "You have played for %d seconds. Play more to get VIP" g_pdDataid ][ pdPlayTime ] );
                }
            }
        }
        else
        {
            
copyszMsg charsmaxszMsg ) , "This is your first time connecting." );
        }
        
        
set_task8.0 "ShowMessage" id , .parameter=szMsg , .len=sizeofszMsg ) );
    }
}

public 
client_disconnectid )
{
    new 
szTime11 ];
    
    if ( !
g_pdDataid ][ pdIgnorePlayer ] && ( g_pdDataid ][ pdPlayTime ] != -) )
    {
        
num_to_strg_pdDataid ][ pdPlayTime ] + ( get_systime() - g_pdDataid ][ pdConnectTime ] ) , szTime charsmaxszTime ) );
        
nvault_setg_Vault g_pdDataid ][ pdAuthID ] , szTime );
        
g_pdDataid ][ pdPlayTime ] = 0;
    }
}

public 
ShowMessageszMsg[] , id )
{
    if ( 
is_user_connectedid ) )
    {
        
client_printid print_chat szMsg );
    }
}

public 
Blacklistid )
{
    new 
szPlayer32 ] , iPlayer szBlacklist[] = "-1";
    
    
read_argvszPlayer charsmaxszPlayer ) );
    
    if ( ( 
iPlayer cmd_targetid szPlayer ) ) )
    {
        
nvault_psetg_Vault g_pdDataiPlayer ][ pdAuthID ] , szBlacklist );
        
remove_user_flagsiPlayer ADMIN_LEVEL_F );
        
client_printiPlayer print_chat "* You have been blacklisted from getting VIP." );
    }
    
    return 
PLUGIN_HANDLED;
}

public 
RemoveVIPid )
{
    new 
szPlayer32 ] , iPlayer;
    
    
read_argvszPlayer charsmaxszPlayer ) );
    
    if ( ( 
iPlayer cmd_targetid szPlayer ) ) )
    {
        
nvault_removeg_Vault g_pdDataiPlayer ][ pdAuthID ] );
        
remove_user_flagsiPlayer ADMIN_LEVEL_F );
        
client_printiPlayer print_chat "* Your VIP status has been removed." );
    } 
    
    return 
PLUGIN_HANDLED;



khashayar007 10-24-2017 11:46

Re: [REQ] Play Time
 
Thank you so much It's working. But I need to see who is in vip list so that I can remove it. Can you make a menu for ptv_removevip that shows all vips thus I can delete the vip I want.

khashayar007 01-06-2018 14:41

Re: [REQ] Play Time
 
Bugsy can you please add a feature when a player becomes vip after 48 hours remove it's vip.

Bugsy 01-07-2018 14:30

Re: [REQ] Play Time
 
Quote:

Originally Posted by khashayar007 (Post 2556510)
Thank you so much It's working. But I need to see who is in vip list so that I can remove it. Can you make a menu for ptv_removevip that shows all vips thus I can delete the vip I want.

This will require that you use the nvault_array include which requires that all servers running this have either a amxmodx dev build running or have the fixed nvault module installed.

Quote:

Originally Posted by khashayar007 (Post 2570220)
Bugsy can you please add a feature when a player becomes vip after 48 hours remove it's vip.

I don't understand this request.

khashayar007 01-07-2018 16:10

Re: [REQ] Play Time
 
Quote:

Originally Posted by Bugsy (Post 2570446)
This will require that you use the nvault_array include which requires that all servers running this have either a amxmodx dev build running or have the fixed nvault module installed.

I have the dev version. Can you make it?

edon1337 01-07-2018 16:35

Re: [REQ] Play Time
 
@Bugsy
Sorry for jumping in, but, do you have any idea why sometimes nVault plugins crash the server and don't start until you remove the vault file? Didn't wanna create a thread just for this problem.

OciXCrom 01-07-2018 16:54

Re: [REQ] Play Time
 
Check if the key isn't empty before saving the data. I can confirm this is happening.

Bugsy 01-07-2018 18:14

Re: [REQ] Play Time
 
Usually a corrupt vault file. Easiest fix is to delete the vault file and start fresh and make sure you are properly closing the vault when the map changes @ plugin_end(). I suppose a server crash could cause this to happen since the vault is not getting a graceful close.

I was testing something else today and accidentally saved a vault record with a blank key and it did not give me any errors.

OciXCrom 01-07-2018 18:44

Re: [REQ] Play Time
 
Not sure why and when it happens, but adding a blank check definitely prevents it. I did some testing a while ago.

edon1337 01-07-2018 18:46

Re: [REQ] Play Time
 
It happened to me without setting a blank key, I was saving my Levels & XP on SteamID. After I closed the vault in plugin_end it didn't crash anymore but I'm not sure how to reproduce it.

OciXCrom 01-07-2018 19:28

Re: [REQ] Play Time
 
Not closing in plugin_end(), saving data for bots and possibly blank keys - I have experienced corrputing in these cases.

klippy 01-07-2018 19:39

Re: [REQ] Play Time
 
Having a stack trace from say GDB would help a lot in solving that problem if it's true.

Bugsy 01-07-2018 20:22

Re: [REQ] Play Time
 
Added menu for removing VIP and blacklisted, including both online and offline players. I have only done basic testing since I do not run a server and only have access to bots.

The plugin now requires nVault Utility and nVault Array. Those not running a dev build of AMX-X must use a fixed version of the nVault module.

Spoiler

khashayar007 01-09-2018 01:54

Re: [REQ] Play Time
 
There are two errors in compiling
PHP Code:

nvault_array.inc(42) : error 021symbol already defined"nvault_set_array"
nvault_array.inc(80) : error 021symbol already defined"nvault_get_array" 



All times are GMT -4. The time now is 11:21.

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