Raised This Month: $51 Target: $400
 12% 

Played time, auto slot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 10-15-2011 , 15:28   Played time, auto slot
Reply With Quote #1

I'm having a weird problem, random player steam id-s are writen in slot.ini
after map change
Any idea what's causing this?
Cvar is set to 50 hours.

Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <hamsandwich>
#include <time_length>

#define PRUNE_TIME 2592000

new Trie:g_tSteamIDs;
new g_SlotFile[64], g_TotalTime[33];
new cvar_timer, g_cached_time;
new g_iMsgID_SayText, g_Vault;

public plugin_init() 
{
	register_plugin("Slot Time", "1.0","Alka/OvidiuS");
	register_cvar("slottime" , "1.0" , (FCVAR_SERVER|FCVAR_SPONLY))
	
	register_dictionary("timer.txt")
	
	register_event("HLTV", "NewRound", "a", "1=0", "2=0");
	RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)
	
	register_clcmd("say /online", "TimeOnline")
	cvar_timer = register_cvar("amx_slot_time", "50")
	
	g_iMsgID_SayText = get_user_msgid( "SayText" );
	
	new configsDir[64] 
	get_configsdir(configsDir, charsmax(configsDir))
	formatex(g_SlotFile, charsmax(g_SlotFile), "%s/slot.ini", configsDir) 
	
	g_tSteamIDs = TrieCreate();
	
	if( !file_exists(g_SlotFile) ) 
	{
		new f = fopen(g_SlotFile, "wt" );
		if( f ) 
		{
			fclose( f );
		}
		return;
	}
	
	new f = fopen( g_SlotFile, "rt" );
	if( !f )
		return;
	
	while( !feof( f ) )
	{
		new szData[200];
		fgets( f , szData , charsmax( szData ) );
		
		if( !szData[0] || szData[0] == ';' || szData[0] == '/' && szData[1] == '/' ) 
			continue;
		
		new szParsedName[33], szParsedID[35];
		parse(szData, szParsedID, charsmax(szParsedID), szParsedName, charsmax(szParsedName))

		TrieSetCell( g_tSteamIDs , szParsedID , 1 );
	}
	fclose( f );	
}

public plugin_cfg()
{
	g_Vault = nvault_open("Time_played")
	
	if ( g_Vault == INVALID_HANDLE )
		set_fail_state( "Error opening nVault" );
		
	nvault_prune(g_Vault, 0, get_systime() - PRUNE_TIME);
}

public TimeOnline(id)
{
	new timep, szTotalTime[128];
	timep = get_user_time(id, 1);
	get_time_length(id, timep+g_TotalTime[id], timeunit_seconds, szTotalTime, charsmax(szTotalTime));
	
	set_hudmessage(0, 255, 0, 0.34, 0.50, 0, 6.0, 4.0, 0.1, 0.2, -1);
	show_hudmessage(id, "[PT] %L", id, "TIME_TOTAL_HUD", szTotalTime);
	ChatColor(id, "^4[PT] ^1%L", id, "TIME_TOTAL_HUD", szTotalTime)
}
public fwHamPlayerSpawnPost(id) 
{
	if(!is_user_alive(id) || is_user_admin(id))
		return PLUGIN_HANDLED;
		
	new timep;
	timep = get_user_time(id, 1);
	
	if(timep+g_TotalTime[id] >= g_cached_time)
	{
		new szSteamID[ 35 ];
		get_user_authid( id , szSteamID , charsmax( szSteamID ) );
	
		if(!TrieKeyExists( g_tSteamIDs , szSteamID ))
		{
			new szWriteData[200], szName[33], szTotalTime[128];
			
			get_user_name(id, szName, charsmax(szName))
			get_time_length(id, timep+g_TotalTime[id], timeunit_seconds, szTotalTime, charsmax(szTotalTime));
			
			TrieSetCell( g_tSteamIDs , szSteamID , 1 ); 
			
			ChatColor(id, "^4[PT] ^1%L", id, "TIME_ONLINE", szTotalTime)
			format(szWriteData, charsmax(szWriteData), "^"%s^"	^"^"	^"b^"	^"ce^" // %s", szSteamID, szName)
			write_file(g_SlotFile, szWriteData)
			
			server_cmd("amx_reloadadmins")
		}
	}
	return PLUGIN_CONTINUE;
}

public NewRound()
	g_cached_time = get_pcvar_num(cvar_timer)*60*60

public client_disconnect(id)
{
	g_TotalTime[id] = g_TotalTime[id] + get_user_time(id);
	SaveTime(id, g_TotalTime[id]);
}

public client_putinserver(id)
	g_TotalTime[id] = LoadTime(id);

public LoadTime( id ) 
{
	new szSteamID[35];
	new vaultkey[128], vaultdata[128];
	
	get_user_authid(id, szSteamID, charsmax( szSteamID ));
	
	formatex(vaultkey, charsmax(vaultkey), "TIMEPLAYED%s", szSteamID);
	
	nvault_get(g_Vault, vaultkey, vaultdata, charsmax(vaultdata));
	
	return str_to_num(vaultdata);
}

public SaveTime(id,PlayedTime)
{
	new szSteamID[35];
	new vaultkey[128], vaultdata[128];
	formatex(vaultdata, charsmax(vaultdata), "%d", PlayedTime); 
	
	get_user_authid(id, szSteamID, charsmax( szSteamID ));
	
	formatex(vaultkey, charsmax(vaultkey), "TIMEPLAYED%s", szSteamID); 
	
	nvault_set(g_Vault, vaultkey, vaultdata);
}

public plugin_end()
{
	nvault_close(g_Vault);
	TrieDestroy(g_tSteamIDs)
}

stock ChatColor(const id, const input[], any:...)
{
	new count = 1, players[32]
	static msg[191]
	vformat(msg, 190, input, 3)
	
	replace_all(msg, 190, "!g", "^4") // Green Color
	replace_all(msg, 190, "!y", "^1") // Default Color
	replace_all(msg, 190, "!t", "^3") // Team Color
	
	if (id) players[0] = id; else get_players(players, count, "ch")
	{
		for (new i = 0; i < count; i++)
		{
			if (is_user_connected(players[i]))
			{
				message_begin(MSG_ONE_UNRELIABLE, g_iMsgID_SayText, _, players[i])
				write_byte(players[i]);
				write_string(msg);
				message_end();
			}
		}
	}
}
i already edited admin.amxx
OvidiuS is offline
Send a message via Skype™ to OvidiuS
FoxueR
Senior Member
Join Date: Jun 2011
Old 10-15-2011 , 18:53   Re: Played time, auto slot
Reply With Quote #2

I don't understand the problem. Explain exactly what's happening and exactly what you expect. Give an example.
__________________
¯\_(ツ)_/¯
FoxueR is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 10-15-2011 , 18:59   Re: Played time, auto slot
Reply With Quote #3

Plugin should add player acess flag b if player was online for more than 50 hours.
I already edited admin.amxx file, so i have users.ini and slot.ini and they have the same function.
This plugin adds player in slot.ini after mapchange, even if they don't have more than 50 hours. Weird thing is that, it adds kind-a random players, but not everyone on the server.

Sorry for bad english.

Last edited by OvidiuS; 10-15-2011 at 19:04.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 10-15-2011 , 19:14   Re: Played time, auto slot
Reply With Quote #4

I would do it this way:
- on client_authorized load time played from sql database, if time played > 50h set_user_flags(id, get_user_flags(id)|ADMIN_RESERVATION)
- on client_disconnect save current time played in sql database
__________________
Impossible is Nothing
Sylwester is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 10-15-2011 , 19:17   Re: Played time, auto slot
Reply With Quote #5

1. I don't want to use sql and users.ini
2. I save to nvault

Timer is good, it shows right vaules, but something is adding players to slot.ini after mapchange :S
I used HamSpawn to check if time > 50 h and print it to player, but i guess somewhere in there is mistake.
Thanks for advice.

Last edited by OvidiuS; 10-15-2011 at 19:23.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-15-2011 , 20:23   Re: Played time, auto slot
Reply With Quote #6

You can do what Sylwester suggested using nvault. If your goal is just giving admin flag(s) based on play time then it would be easiest this way.
__________________
Bugsy is offline
Reply



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 16:37.


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