AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved?] Player activity (https://forums.alliedmods.net/showthread.php?t=273194)

redivcram 10-14-2015 18:18

[Solved?] Player activity
 
So I've made a plugin that will count player's time on the server in seconds...
In seconds because the time wont be shown to them (They can use gametracker so don't ask)

I'm just wondering, will there be an overflow?

Let me first show you the plugin

PHP Code:

#include <amxmodx>
#include <nvault>

#define TASK_COUNT 13817
#define TASK_CHECK 10398

new gVault
new timespent[33]

public 
plugin_init()
{
    
register_plugin("Activity Blah Test""1.0""redivcram")
    
gVault nvault_open("activity")
}

public 
client_authorized(id)
{
    
timespent[id] = loadvalue(id)
}

public 
client_putinserver(id)
{
    
set_task(1.0"CountTime"id TASK_COUNT__"b")
    
set_task(1.0"CheckTime"id TASK_CHECK__"b")
}

public 
client_disconnect(id)
{
    
savevalue(id)
    
remove_task(id TASK_COUNT)
    
remove_task(id TASK_CHECK)
}

public 
plugin_end()
{
    
nvault_close(gVault)
}

public 
CountTime(id)
{
        
id -= TASK_COUNT
    timespent
[id]++
}

public 
CheckTime(id)
{
        
id -= TASK_CHECK
    
if(timespent[id] == 60)
    {
        
client_print(idprint_chat"Congrats, you spent 1 minute on this server")
    }
    else if(
timespent[id] == 3600)
    {
        
client_print(idprint_chat"Congrats!! You spend 1 hour on this server!")
    }
    return 
PLUGIN_HANDLED
}

public 
loadvalue(id)
{
    new 
authid[33]
    new 
vaultkey[64], vaultdata[64]

    
get_user_authid(idauthidsizeof(authid) - 1)

    
format(vaultkeysizeof(vaultkey) - 1"%s_value"authid)

    
nvault_get(gVaultvaultkeyvaultdata63)

    return 
str_to_num(vaultdata)
}

public 
savevalue(idtimespent)
{
    if(
gVault == INVALID_HANDLE)
        
set_fail_state("nVault error: Invalid Handle")

    new 
authid[32]
    new 
vaultkey[64], vaultdata[64]

    
get_user_authid(idauthidsizeof(authid) - 1)

    
format(vaultkeysizeof(vaultkey) - 1"%s_timespent"authid)
    
format(vaultdatasizeof(vaultdata) - 1"%d^n"valuename)

    
nvault_pset(gVaultvaultkeyvaultdata)


So this basically adds up a player's time spent every second (obviously) and stores it in nVault when he disconnects, when he connects, the time continues. When he reaches 1 minute (60 seconds) he will be notified, as well as when he reaches one hour... Does this even work without problems? Will this last forever? Even on global restart? Will the time be reset?

OciXCrom 10-15-2015 06:25

Re: [Question] Player activity
 
Instead of doing all those stuff, you can simply use get_user_time(id), which will give you the time spent on the server for the current session.

redivcram 10-15-2015 07:56

Re: [Question] Player activity
 
Edit: Nevermind, didn't even know that native exists lol


All times are GMT -4. The time now is 22:06.

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