#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <time>
#include <colorchat>
new output[64], key[33][32], vault;
public plugin_init() {
register_plugin("Played Time", "9.0", "Hattrick");
register_clcmd("say /orejucate", "getPlayTime");
register_clcmd("amx_playtime", "cmdGetPlayerTime",ADMIN_ADMIN,"<player>");
register_dictionary("time.txt");
vault = nvault_open("playtimes");
if (vault == INVALID_HANDLE)
set_fail_state("Error opening nVault");
}
public cmdGetPlayerTime(id, level, cid) {
if (!cmd_access(id, level, cid, 2)) {
console_print(id,"You don't have acces to this command");
return PLUGIN_HANDLED;
}
new arg[32],reason[32];
read_argv(1, arg, 31);
read_argv(2, reason, 31);
remove_quotes(reason);
new player = cmd_target(id, arg, 31);
if (!player) return PLUGIN_HANDLED;
new name[32];
get_user_name(player,name,31);
get_time_length(player, (get_user_time(player) + nvault_get(vault, key[player])), timeunit_seconds , output, 63);
ColorChat(id,GREY,"[ Info ]^x03 Ore jucate[%s]:^x04 %s",name,output);
console_print(id,"%s are %s ore jucate",name,output);
return PLUGIN_HANDLED;
}
public getPlayTime(id) {
get_time_length(id, (get_user_time(id) + nvault_get(vault, key[id])), timeunit_seconds , output, 63);
ColorChat(id, GREY, "[ InFo ]^x03 Ore jucate:^x04 %s", output);
}
public client_authorized(id) {
get_user_authid(id, key[id], 31);
nvault_touch(vault, key[id]);
}
public client_disconnect(id) {
new value[33], timestamp;
nvault_lookup(vault, key[id], value, 32, timestamp);
formatex(value, 32, "%d", ((time() - timestamp) + nvault_get(vault, key[id])));
nvault_set(vault, key[id], value);
}
public plugin_end() {
nvault_close(vault);
}