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(id, print_chat, "Congrats, you spent 1 minute on this server")
}
else if(timespent[id] == 3600)
{
client_print(id, print_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(id, authid, sizeof(authid) - 1)
format(vaultkey, sizeof(vaultkey) - 1, "%s_value", authid)
nvault_get(gVault, vaultkey, vaultdata, 63)
return str_to_num(vaultdata)
}
public savevalue(id, timespent)
{
if(gVault == INVALID_HANDLE)
set_fail_state("nVault error: Invalid Handle")
new authid[32]
new vaultkey[64], vaultdata[64]
get_user_authid(id, authid, sizeof(authid) - 1)
format(vaultkey, sizeof(vaultkey) - 1, "%s_timespent", authid)
format(vaultdata, sizeof(vaultdata) - 1, "%d^n", valuename)
nvault_pset(gVault, vaultkey, vaultdata)
}
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?