Raised This Month: $ Target: $400
 0% 

[Solved?] Player activity


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 10-14-2015 , 18:18   [Solved?] Player activity
Reply With Quote #1

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?

Last edited by redivcram; 10-15-2015 at 07:58.
redivcram is offline
 



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 22:06.


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