Raised This Month: $19 Target: $400
 4% 

DeathRun Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
icimaro1337
Junior Member
Join Date: Jan 2016
Location: Moldova, Chisinau
Old 08-22-2016 , 11:25   DeathRun Timer
Reply With Quote #1

DeathRun Timer

Version: 1.0.0
Author: deniS
Credits: xPaw, Mistrick, Keniski, Klippy
Description:
It's similiar to kz buttons but on deathrun mod, it's automaticly detects buttons on map, if they don't exist you should put it by yourself.

Main Settings:
Code:
//#define COLORCHAT// If you want to use colored messages, uncomment this line

new const g_szPrefix[] = "DeathRun";// Here you can put your tag

const MAX_PLAYERS = 32;// Number of slots of your server

#define ADMIN_ACCESS ADMIN_CVAR// Acces to admin commands, like /timer
CVARS ONLY IF YOU HAVE WEB SERVER:
Code:
dr_timer_web_link "link"// Link to web folder with php files
dr_timer_sql_host "host"// ip adress or dns
dr_timer_sql_user "login"
dr_timer_sql_pass "password"

dr_timer_sql_db "database"

Motd Images:

Spoiler


Browser Images:
Spoiler


Requirements:
  • Steam server
Attached Files
File Type: sma Get Plugin or Get Source (deathrun_timer.sma - 1884 views - 24.2 KB)
File Type: inc colorchat.inc (6.3 KB, 635 views)
File Type: zip models.zip (7.0 KB, 742 views)
File Type: zip web.zip (263.3 KB, 594 views)

Last edited by icimaro1337; 09-17-2016 at 09:41.
icimaro1337 is offline
Send a message via Skype™ to icimaro1337
Adryyy
Member
Join Date: Oct 2011
Old 11-05-2017 , 16:56   Re: DeathRun Timer
Reply With Quote #2

It has some problems .. like:

He does not read that 'formatex' for the vault.
Once I set up and restart the map, it says that 'the timer does not exist', although it is on the map (and vault).

My code -

Code:
/*

+--------------------------------------+
|      DeathRun Timer - 2015-2016      |
|                                      |
| Author:                              |
|         deniS[MD] a.k.a icimaro1337  |
| Credits:                             |
|         xPaw[EE]                     |
|         Mistrick[RU]                 |
|         Keniski[RU]                  |
|         Klippy[RS]                   |
+--------------------------------------+


de pus si city?
de scos de tot authid
*/

#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <nvault>
#include <sqlx>
#include <geoip>
#include <fakemeta_util>
#include <dhudmessage>


//#pragma semicolon 1


// Here you can configure main settings
#define COLORCHAT
#define ADMIN_ACCESS ADMIN_RCON

new const g_szPrefix[] = "TIMER";

const MAX_PLAYERS = 32;
// Here you stop


#if defined COLORCHAT
	#include <colorchat>
#endif


/* Macro */
#define set_bit(%1,%2)	(%1 |= (1<<%2))
#define get_bit(%1,%2)	(%1 & (1<<%2))
#define clr_bit(%1,%2)	(%1 &= ~(1<<%2))
/* Macro */


new const g_szVersion[] = "0.1";


new const g_szTableName[] = "DEATHRUN_STATS";
new g_pWebLink;
new Handle:g_hSqlTuple;
new bool:g_bSqlite;


enum _:eTimer
{
	START,
	STOP
};
new g_szTimerModels[eTimer][] =
{
	"models/deathrun/timer/timer_start.mdl",
	"models/deathrun/timer/timer_stop.mdl"
};
new g_szTimerName[eTimer][] =
{
	"Start",
	"Stop"
};
new Float:g_flTimerAngles[4] =
{
	0.0,
	90.0,
	180.0,
	270.0
};

new g_iPlayerTimer[MAX_PLAYERS + 1],g_bConnected, g_bAlive, g_bStarted,Float:g_flStartTime[MAX_PLAYERS + 1],
Float:g_flFinishTime[MAX_PLAYERS + 1],g_iVault,g_iMsgRoundTime,g_iTimerAngles[eTimer],g_iTimer[eTimer],
Float:g_vTimerOrigin[eTimer][3],g_szMapName[64],Trie:g_tStarts, Trie:g_tStops,bool:g_bTimerFound;

//new g_iHudSyncObj;


public plugin_precache()	for (new i = 0; i < eTimer; i++)	precache_model(g_szTimerModels[i]);

public plugin_init()
{
	register_plugin("DeathRun Timer", g_szVersion, "deniS");


	g_pWebLink = register_cvar("dr_timer_web_link", "http://evils.ro/deathrun_timer_web");// link to web files
	
	register_cvar("dr_timer_sql_host", "sql11.freesqldatabase.com");
	register_cvar("dr_timer_sql_user", "sql11202240");
	register_cvar("dr_timer_sql_pass", "vyS3IeWBCP");
	register_cvar("dr_timer_sql_db", "sql11202240"); /* If you don't have web server, you can use local stats, just add .db like deathrun_stats.db and enable sqlite module! */


	get_mapname(g_szMapName, charsmax(g_szMapName));
	
	g_tStarts	= TrieCreate();
	g_tStops	= TrieCreate();
	
	new i, iSize;
	
	new const szStarts[][] =
	{
		"counter_start", "clockstartbutton", "firsttimerelay", "but_start", "counter_start_button",
		"multi_start", "timer_startbutton", "start_timer_emi", "gogogo"
	};
	iSize = sizeof(szStarts);
	
	for (i = 0; i < iSize; i++)	TrieSetCell(g_tStarts, szStarts[i], 1);
	
	new const szStops[][] =
	{
		"counter_off", "clockstopbutton", "clockstop", "but_stop", "counter_stop_button",
		"multi_stop", "stop_counter", "m_counter_end_emi"
	};
	iSize = sizeof(szStops);
	
	for (i = 0; i < iSize; i++)	TrieSetCell(g_tStops, szStops[i], 1);
	

	new iEntity = -1;//de modificat..
	while ((iEntity = find_ent_by_class(iEntity, "func_button")) != 0)
	{
		new szTargetName[64];
		entity_get_string(iEntity, EV_SZ_targetname, szTargetName, charsmax(szTargetName));
		
		if (TrieKeyExists(g_tStarts, szTargetName) && TrieKeyExists(g_tStops, szTargetName))
		{
			if (!g_bTimerFound)	g_bTimerFound = true;
			//else	g_bTimerFound = false;
			//g_bTimerFound = false	+	!	^x2
			//g_bTimerFound = true;
			
			break;
		}
	}
	

	if (!g_bTimerFound)
	{
		TrieDestroy(g_tStarts);
		TrieDestroy(g_tStops);
		
		/*new szDir[200],szFile[200];
		formatex(szDir, charsmax(szDir), "addons/amxmodx/data/vault/deathrun/timer");
		if(!dir_exists(szDir))	mkdir(szDir)
		formatex(szFile, charsmax(szFile), "%s/%s.vault", szDir,g_szMapName);
		if(!file_exists(szFile))	write_file(szFile,"",-1)*/
		
		g_iVault = nvault_open(g_szMapName);
		
		LoadTimers();
	}
	
	iEntity = create_entity("info_target");
	
	if (iEntity)
	{
		entity_set_float(iEntity, EV_FL_nextthink, get_gametime() + 0.5);
		entity_set_string(iEntity, EV_SZ_classname, "_TimerThink");
		register_think("_TimerThink", "TimerThink");
	}
	
	g_iMsgRoundTime = get_user_msgid("RoundTime");
	
	RegisterHam(Ham_Spawn, "player", "HamSpawnPlayer_Post", true);
	RegisterHam(Ham_Killed, "player", "HamKilledPlayer_Post", true);
	RegisterHam(Ham_Use, "func_button", "HamUseFuncButton_Pre", false);
	
	register_clcmd("say /timer", "ClCmdTimer");
	register_clcmd("say_team /timer", "ClCmdTimer");
	register_clcmd("say /timermenu", "ClCmdTimer");
	register_clcmd("say_team /timermenu", "ClCmdTimer");
	register_clcmd("say /drtimer", "ClCmdTimer");
	register_clcmd("say_team /drtimer", "ClCmdTimer");
	register_clcmd("say /drtimermenu", "ClCmdTimer");
	register_clcmd("say_team /drtimermenu", "ClCmdTimer");
	
	register_clcmd("say /best", "ClCmdBest");
	register_clcmd("say_team /best", "ClCmdBest");
	register_clcmd("say /record", "ClCmdBest");
	register_clcmd("say_team /record", "ClCmdBest");
	
	//g_iHudSyncObj = CreateHudSyncObj();


	//set_msg_block(get_user_msgid("RoundTime"), BLOCK_SET)
}

public plugin_cfg()	set_task(0.5, "DB_Init");
public DB_Init()
{
	state mysql;
	
	new szDB[64];
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	if (contain(szDB, ".") > 0)
	{
		state sqlite;
		
		g_bSqlite = true;
	}
	
	SQL_Init();
}
SQL_Init()<mysql>
{
	new szHost[64], szUser[64], szPass[64], szDB[64];
	get_cvar_string("dr_timer_sql_host", szHost, charsmax(szHost));
	get_cvar_string("dr_timer_sql_user", szUser, charsmax(szUser));
	get_cvar_string("dr_timer_sql_pass", szPass, charsmax(szPass));
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	g_hSqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB);
	
	new szQuery[512];
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"CREATE TABLE IF NOT EXISTS `%s` \
		( \
			`ID`				INT				NOT NULL	AUTO_INCREMENT, \
			 \
			`MAPNAME`			VARCHAR(64)		NOT NULL, \
			`AUTHID`			VARCHAR(32)		NOT NULL, \
			`NICKNAME`			VARCHAR(64)		NOT NULL, \
			`IP`				VARCHAR(45)		NOT NULL, \
			`COUNTRY_FULL`		VARCHAR(45)		NOT NULL, \
			`COUNTRY_SHORT`		VARCHAR(3)		NOT NULL, \
			`TIME`				DOUBLE			NOT NULL, \
			`DATE`				DATETIME		NOT NULL, \
			 \
			PRIMARY KEY(`ID`) \
		)",
		g_szTableName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
}
SQL_Init()<sqlite>
{
	SQL_SetAffinity("sqlite");
	
	new szDataDir[128];
	get_localinfo("amxx_datadir", szDataDir, charsmax(szDataDir));
	
	new szDB[64];
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	new szFile[196];
	formatex(szFile, charsmax(szFile), "%s/%s", szDataDir, szDB);
	
	if (!file_exists(szFile))
	{
		new fp = fopen(szFile, "w");
		
		if (!fp)
		{
			log_amx("[%s] SQL_Init()<sqlite>: File ^"%s^" not found and can't be created!", g_szPrefix, szFile);
			return;
		}
		else	fclose(fp);
	}
	
	g_hSqlTuple = SQL_MakeDbTuple("", "", "", szFile, 0);
	
	new szQuery[512];
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"CREATE TABLE IF NOT EXISTS `%s` \
		( \
			`MAPNAME`				TEXT			NOT NULL, \
			`AUTHID`				TEXT			NOT NULL, \
			`NICKNAME`				TEXT			NOT NULL, \
			`IP`					TEXT			NOT NULL, \
			`COUNTRY_FULL`			TEXT			NOT NULL, \
			`COUNTRY_SHORT`			TEXT			NOT NULL, \
			`TIME`					REAL			NOT NULL, \
			`DATE`					DATETIME		NOT NULL \
		)",
		g_szTableName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
}

public client_putinserver(id)	set_bit(g_bConnected, id);
public client_disconnect(id)
{
	clr_bit(g_bConnected, id);
	if (get_bit(g_bAlive, id))	clr_bit(g_bAlive, id);
	if (get_bit(g_bStarted, id))	clr_bit(g_bStarted, id);
	if (g_flStartTime[id] != 0.0)	g_flStartTime[id] = 0.0;
	if (g_flFinishTime[id] != 0.0)	g_flFinishTime[id] = 0.0;
}

public TimerThink(iEntity)
{
	if (iEntity)	entity_set_float(iEntity, EV_FL_nextthink, get_gametime() + 0.5);
	
	for (new iAlivePlayer = 1; iAlivePlayer <= MAX_PLAYERS; iAlivePlayer++)
	{
		if (get_bit(g_bConnected, iAlivePlayer) && get_bit(g_bAlive, iAlivePlayer) && get_bit(g_bStarted, iAlivePlayer))
		{
			//set_msg_block(get_user_msgid("RoundTime"), BLOCK_NOT)

			new Float:flGameTime = get_gametime();

			//g_flStartTime[iAlivePlayer] / 60, g_flStartTime[iAlivePlayer] % 60
			//new iMinutes = floatround(flGameTime - g_flStartTime[iAlivePlayer] / 60.0);
			//new iSeconds = floatround(flGameTime - g_flStartTime[iAlivePlayer] - iMinutes * 60);
			/*new sSMsg[32];
			format(sSMsg, 31, "Timer: %02d:%02d", iMinutes, iSeconds);
			message_begin(MSG_ONE, StatusText, {0,0,0}, iAlivePlayer);
			write_byte(0);
			write_string(sSMsg);
			message_end();*/
			//client_print(iAlivePlayer,print_center,"Timer: %02d:%02d", iMinutes, iSeconds)


			message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, iAlivePlayer);
			write_short(floatround(flGameTime - g_flStartTime[iAlivePlayer], floatround_floor) + 1);
			message_end();
			
			for (new iDeadPlayer = 1; iDeadPlayer <= MAX_PLAYERS; iDeadPlayer++)//mai jos
			{
				if (get_bit(g_bConnected, iDeadPlayer) && !get_bit(g_bAlive, iDeadPlayer) && entity_get_int(iDeadPlayer, EV_INT_iuser2) == iAlivePlayer && entity_get_int(iDeadPlayer, EV_INT_iuser1) == 4)
				{
					new iMinutesx = floatround(g_flStartTime[iDeadPlayer] / 60.0, floatround_floor);
					new iSecondsx = floatround(g_flStartTime[iDeadPlayer] - iMinutesx * 60, floatround_floor);

					new name[32]
					get_user_name(iDeadPlayer,name,charsmax(name))
					
//					set_hudmessage(0, 255, 0, -1.0, 0.25, 0, _, 0.5, _, _, 1);
//					ShowSyncHudMsg(iDeadPlayer, g_iHudSyncObj, "%02d:%02d", iMinutesx, iSecondsx);
					client_print(iDeadPlayer,print_center,"Timer of %s : %02d:%02d", name, iMinutesx, iSecondsx);
				}
			}
		}
	}
}
public HamSpawnPlayer_Post(id)
{
/*
	if(task_exists(id + TaskID))
		remove_task(id + TaskID);
*/

	set_bit(g_bAlive, id);
	
	if (get_bit(g_bStarted, id))
	{
		clr_bit(g_bStarted, id);
		g_flStartTime[id] = 0.0;
	}


	if(is_user_alive(id))
	{
	message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, id);
	write_short(1);
	message_end();
	}
}

public HamKilledPlayer_Post(id)
{
/*
	if(task_exists(id + TaskID))
		remove_task(id + TaskID);
*/


	clr_bit(g_bAlive, id);
	
	if (get_bit(g_bStarted, id))
	{
		clr_bit(g_bStarted, id);
		g_flStartTime[id] = 0.0;
	}
}

public HamUseFuncButton_Pre(iEntity, id)
{
	if (!get_bit(g_bAlive, id))	return(HAM_IGNORED);
	
	if (g_bTimerFound)
	{
		new szTarget[32];
		entity_get_string(iEntity, EV_SZ_target, szTarget, charsmax(szTarget));
		
		if (TrieKeyExists(g_tStarts, szTarget))	Timer_Start(id);
		else if (TrieKeyExists(g_tStops, szTarget))	Timer_Stop(id);
	}
	else
	{
		if (iEntity == g_iTimer[START])	Timer_Start(id);
		else if (iEntity == g_iTimer[STOP])	Timer_Stop(id);
	}
	
	return(HAM_IGNORED);
}

Timer_Start(id)
{
	if (!get_bit(g_bStarted, id))
	{
		set_bit(g_bStarted, id);
		set_dhudmessage(0, 255, 0, -1.0, 0.80, 0, _, 3.0, _, _, true);
		//ShowSyncHudMsg(id, g_iHudSyncObj, "Timer started!");
		show_dhudmessage(id, "Timer started!");
	}
	else
	{
	set_dhudmessage(255, 0, 0, -1.0, 0.85, 1, _, 3.0, _, _, true);
	show_dhudmessage(id, "Timer re-started!");//ShowSyncHudMsg(id, g_iHudSyncObj, "Timer re-started!");
	}
	
	g_flStartTime[id] = get_gametime();
}

Timer_Stop(id)
{
	if (!get_bit(g_bStarted, id))
	{
		set_dhudmessage(0, 0, 255, -1.0, 0.85, 2, _, 3.0, _, _, true);
		show_dhudmessage(id, "Go back, and Start Timer!");
		return;
	}

	//set_msg_block(get_user_msgid("RoundTime"), BLOCK_SET)
	
	clr_bit(g_bStarted, id);
	g_flFinishTime[id] = get_gametime() - g_flStartTime[id];
	g_flStartTime[id] = 0.0;
	
	message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, id);
	write_short(1);
	message_end();
	
	new szTime[17];
	ClimbtimeToString(g_flFinishTime[id], szTime, charsmax(szTime));
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	
	#if defined COLORCHAT
		//ColorChat(id, RED, "^4[%s]^1 You finished map in^3 %s^1!", g_szPrefix, szTime);
		ColorChat(0, RED, "^4[%s]^3 %s^1 finished map in^3 %s^1!", g_szPrefix, szName, szTime);
	#else
		client_print(id, print_chat, "[%s] You finished map in %s!", g_szPrefix, szTime);
		client_print(0, print_chat, "[%s] %s finished map in %s!", g_szPrefix, szName, szTime);
	#endif
	
	/*new iPlayers[MAX_PLAYERS], iNum;
	get_players(iPlayers, iNum, "ch");
	
	if (iNum)
	{
		new iPlayer;
		
		for (new i = 0; i < iNum; i++)
		{
			iPlayer = iPlayers[i];
			
			if (iPlayer == id)	continue;
			
			#if defined COLORCHAT
				ColorChat(iPlayer, RED, "^4[%s]^3 %s^1 finished map in^3 %s^1!", g_szPrefix, szName, szTime);
			#else
				client_print(iPlayer, print_chat, "[%s] %s finished map in %s!", g_szPrefix, szName, szTime);
			#endif
		}
	}*/
	
	new szQuery[512], cData[1]; cData[0] = id;
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"SELECT \
			`TIME` \
		FROM \
			`%s` \
		WHERE \
			`MAPNAME` = '%s' \
		AND \
			`AUTHID` = '%s'",
		g_szTableName,
		g_szMapName,
		szName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_QueryTop_Handler", szQuery, cData, sizeof(cData));
}

public Sql_QueryTop_Handler(iFailState, Handle:hQuery, szError[], iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_IgnoredQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;
	
	new szAuthID[32], szName[64], szIP[32], szCountryFull[45], szCountryShort[3], szDate[32];
	get_user_authid(id, szAuthID, charsmax(szAuthID));
	get_user_name(id, szName, charsmax(szName));
	get_user_ip(id, szIP, charsmax(szIP), 1);
	geoip_country(szIP, szCountryFull, charsmax(szCountryFull));
	geoip_code2(szIP, szCountryShort);
	get_time("%Y%m%d%H%M%S", szDate, charsmax(szDate));
	
	SQL_PrepareString(szName, szName, charsmax(szName));
	
	new szQuery[512];
	
	if (SQL_NumResults(hQuery))
	{
		new Float:flOldTime, Float:flResult, szTime[17];
		
		SQL_ReadResult(hQuery, 0, flOldTime);
		
		if (g_flFinishTime[id] < flOldTime)
		{
			flResult = flOldTime - g_flFinishTime[id];
			ClimbtimeToString(flResult, szTime, charsmax(szTime));
			
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You improved your time for^3 %s^1 msec!", g_szPrefix, szTime);
				ColorChat(0, RED, "^4[%s]^3 %s^1 improved his time for^4 %s^1 msec!", g_szPrefix,szName, szTime);
			#else
				client_print(id, print_chat, "[%s] You improved your time for %s msec!", g_szPrefix, szTime);
			#endif
			
			formatex
			(
				szQuery, charsmax(szQuery),
				"UPDATE `%s` \
				SET \
					`NICKNAME`			= '%s', \
					`IP`				= '%s', \
					`COUNTRY_FULL`		= '%s', \
					`COUNTRY_SHORT`		= '%s', \
					`TIME`				= '%f', \
					`DATE`				= '%s' \
				WHERE \
					`MAPNAME`			= '%s' \
				AND \
					`AUTHID`			= '%s'",
				g_szTableName,
				szName,
				szIP,
				szCountryFull,
				szCountryShort,
				g_flFinishTime[id],
				szDate,
				g_szMapName,
				szName
			);
			
			SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
			
			formatex
			(
				szQuery, charsmax(szQuery),
				"SELECT \
					`AUTHID` \
				FROM \
					`%s` \
				WHERE \
					MAPNAME='%s' \
				ORDER BY \
					`TIME` \
				LIMIT 15",
				g_szTableName,
				g_szMapName
			);
			
			SQL_ThreadQuery(g_hSqlTuple, "Sql_GetPlaceQuery_Handler", szQuery, cData, sizeof(cData[]));
		}
		else
		{
			flResult = g_flFinishTime[id] - flOldTime;
			ClimbtimeToString(flResult, szTime, charsmax(szTime));
			
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You failed your time for^3 %s^1 msec!", g_szPrefix, szTime);
				ColorChat(0, RED, "^4[%s]^3 %s^1 failed his time for^4 %s^1 msec!", g_szPrefix,szName, szTime);
				//ColorChat(0, RED, "^4[%s]^1 It seems he failed to beat the record^3 %s^1 msec, owned by^4 %s", g_szPrefix, szTime);
			#else
				client_print(id, print_chat, "[%s] You failed your time for %s msec!", g_szPrefix, szTime);
			#endif
		}
	}
	else
	{
		formatex
		(
			szQuery, charsmax(szQuery),
			"INSERT INTO `%s` \
			( \
				`MAPNAME`, \
				`AUTHID`, \
				`NICKNAME`, \
				`IP`, \
				`COUNTRY_FULL`, \
				`COUNTRY_SHORT`, \
				`TIME`, \
				`DATE` \
			) \
			 \
			VALUES \
			( \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%f', \
				'%s' \
			)",
			g_szTableName,
			g_szMapName,
			szName,
			szName,
			szIP,
			szCountryFull,
			szCountryShort,
			g_flFinishTime[id],
			szDate
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
		
		formatex
		(
			szQuery, charsmax(szQuery),
			"SELECT \
				`AUTHID` \
			FROM \
				`%s` \
			WHERE \
				MAPNAME='%s' \
			ORDER BY \
				`TIME` \
			LIMIT 15",
			g_szTableName,
			g_szMapName
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_GetPlaceQuery_Handler", szQuery, cData, sizeof(cData[]));
	}
	
	g_flFinishTime[id] = 0.0;
}

public Sql_GetPlaceQuery_Handler(iFailState, Handle:hQuery, szError, iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_GetPlaceQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;
	
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	
	new i, szAuthID_SQL[32];
	
	while(SQL_MoreResults(hQuery))
	{
		i++;
		
		SQL_ReadResult(hQuery, 0, szAuthID_SQL, charsmax(szAuthID_SQL));
		
		if (equali(szName, szAuthID_SQL))//de pus la finish, fara equal asta..
		{
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You are now on^3 %d^1 place in map top!", g_szPrefix, i);
				ColorChat(0, RED, "^4[%s]^3 %s^1 are now on^4 %d^1 place in map top!", g_szPrefix,szName, i);
			#else
				client_print(id, print_chat, "[%s] You are now on %d place in map top!", g_szPrefix, i);
			#endif
			
			/*new iPlayers[MAX_PLAYERS], iNum;
			get_players(iPlayers, iNum, "ch");
			
			if (iNum)
			{
				new iPlayer;
				
				for (new i = 0; i < iNum; i++)
				{
					iPlayer = iPlayers[i];
					
					if (iPlayer == id)	continue;
					
					#if defined COLORCHAT
						ColorChat(iPlayer, RED, "^4[%s]^3 %s^1 is now on^3 %d^1 place in map top!", g_szPrefix, szName, i);
					#else
						client_print(iPlayer, print_chat, "[%s] %s is now on %d place in map top!", g_szPrefix, szName, i);
					#endif
				}
			}*/
			break;
		}
		SQL_NextRow(hQuery);
	}
}

public Sql_IgnoredQuery_Handler(iFailState, Handle:hQuery, szError[], iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_IgnoredQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
}
public ClCmdBest(id)
{
	/*if (!g_bTimerFound)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 This map does not have timer yet!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] This map does not have timer yet!", g_szPrefix);
		#endif
		return;
	}*/

	if (!g_bSqlite)
	{
		new szWebLink[128];
		get_pcvar_string(g_pWebLink, szWebLink, charsmax(szWebLink));
		
		new szMotd[256];
		formatex(szMotd, charsmax(szMotd), "<META HTTP-EQUIV=^"REFRESH^" CONTENT=^"0;URL=%s/maptop.php?mapname=%s^">", szWebLink, g_szMapName);
		
		show_motd(id, szMotd, "DRTIMER - Map Top");
	}
	else
	{
		new szQuery[512], cData[1]; cData[0] = id;
		
		formatex
		(
			szQuery, charsmax(szQuery),
			"SELECT \
				`NICKNAME`, \
				`TIME` \
			FROM \
				`%s` \
			WHERE \
				`MAPNAME` = '%s' \
			ORDER BY \
				`TIME` \
			LIMIT 15",
			g_szTableName,
			g_szMapName
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_LoadTopQuery_Handler", szQuery, cData, sizeof(cData));
	}
}

public Sql_LoadTopQuery_Handler(iFailState, Handle:hQuery, szError, iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_GetPlaceQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;

	if(SQL_NumResults(hQuery)!=1)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 It seems that nobody has finished this map yet. Be that!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] It seems that nobody has finished this map yet. Be that!", g_szPrefix);
		#endif
		
		return;
	}
	
	new szMotd[1536], iSize = charsmax(szMotd);
	
	new iLen = formatex
	(
		szMotd, iSize,
		"<!DOCTYPE HTML> \
		<html> \
		<head> \
			<style type=^"text/css^"> \
				body \
				{ \
					background: #000; \
					margin: 8px; \
					color: #FFB000; \
					font: normal 16px/20px Verdana, Tahoma, sans-serif; \
					text-align: center; \
				} \
				th:nth-child(2){ text-align: left; } \
				td:nth-child(2){ text-align: left; } \
			</style> \
		</head> \
		<body>"
	);
	
	iLen += formatex
	(
		szMotd[iLen], iSize - iLen,
		"<table align=^"center^" width=^"90%%^"> \
			<tr> \
				<th width=^"5%%^">#</th>\
				<th width=^"40%%^">Player</th>\
				<th width=^"20%%^">Time</th>\
			</tr> \
		"
	);
	
	new i = 1;
	new Float:flTime, szName[32], szTime[32];
	
	while (SQL_MoreResults(hQuery))
	{
		SQL_ReadResult(hQuery, 0, szName, 31);
		SQL_ReadResult(hQuery, 1, flTime);
		
		ClimbtimeToString(flTime, szTime, 16);
		
		iLen += formatex
		(
			szMotd[iLen], iSize - iLen,
			"<tr> \
				<td>%d</td> \
				<td>%s</td> \
				<td>%s</td> \
			</tr>",
			i,
			szName,
			szTime
		);
		
		i++;
		SQL_NextRow(hQuery);
	}
	
	formatex
	(
		szMotd[iLen], iSize - iLen,
		"</table> \
		</body> \
		</html>"
	);
	
	show_motd(id, szMotd, "DRTIMER - Map Top");
}

stock SQL_PrepareString(const szQuery[], szOutPut[], iSize)
{
	copy(szOutPut, iSize, szQuery);
	replace_all(szOutPut, iSize, "'", "\'");
	replace_all(szOutPut, iSize, "`", "\`");
	replace_all(szOutPut, iSize, "\\", "\\\\");
}

ClimbtimeToString(Float:flClimbTime, szOutPut[], iLen)
{
	new iMinutes = floatround(flClimbTime / 60.0, floatround_floor);
	new iSeconds = floatround(flClimbTime - iMinutes * 60, floatround_floor);
	new iMiliSeconds = floatround((flClimbTime - (iMinutes * 60 + iSeconds)) * 100, floatround_floor);
	
	formatex(szOutPut, iLen, "%02i:%02i.%02i", iMinutes, iSeconds, iMiliSeconds);
}

public ClCmdTimer(id)
{
	if (~get_user_flags(id) & ADMIN_ACCESS)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 You don't have enought access!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] You don't have enought access!", g_szPrefix);
		#endif
		
		return(PLUGIN_HANDLED);
	}
	if (g_bTimerFound)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 This map already have timers!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] This map already have timers!", g_szPrefix);
		#endif
		return(PLUGIN_HANDLED);
	}
	if (!get_bit(g_bAlive, id))
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 You should be alive!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] You should be alive!", g_szPrefix);
		#endif
		return(PLUGIN_HANDLED);
	}
	
	TimerMenu(id);
	
	return(PLUGIN_HANDLED);
}

public TimerMenu(id)
{
	new iMenu = menu_create("\r[DeathRun]\y Timer Menu", "TimerMenu_Handler");
	
	menu_additem(iMenu, "Create");
	menu_additem(iMenu, "Rotate^n");
	
	menu_additem(iMenu, "Save^n");
	
	new szMenuItem[64];
	formatex(szMenuItem, charsmax(szMenuItem), "Timer - (\y%s\w)", g_szTimerName[g_iPlayerTimer[id]]);
	menu_additem(iMenu, szMenuItem);
	
	menu_display(id, iMenu);
}

public TimerMenu_Handler(id, iMenu, iItem)
{
	if (iItem == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return(PLUGIN_HANDLED);
	}
	
	switch (iItem)
	{
		case 0: create_timer(id, g_iPlayerTimer[id]);
		case 1:
		{
			if (is_valid_ent(g_iTimer[g_iPlayerTimer[id]]))
			{
				switch (g_iTimerAngles[g_iPlayerTimer[id]])
				{
					case 3: g_iTimerAngles[g_iPlayerTimer[id]] = 0;
					case 0, 1, 2: g_iTimerAngles[g_iPlayerTimer[id]]++;
				}
				
				new Float:vAngles[3];
				vAngles[1] = g_flTimerAngles[g_iTimerAngles[g_iPlayerTimer[id]]];
				
				entity_set_vector(g_iTimer[g_iPlayerTimer[id]], EV_VEC_angles, vAngles);
			}
		}
		case 2:
		{
			if (is_valid_ent(g_iTimer[g_iPlayerTimer[id]]))
			{
				if (g_iVault == INVALID_HANDLE)	return(PLUGIN_HANDLED);
				
				new szData[128], iTimestamp;
				
				if (nvault_lookup(g_iVault, g_szTimerName[g_iPlayerTimer[id]], szData, charsmax(szData), iTimestamp))	nvault_remove(g_iVault, g_szTimerName[g_iPlayerTimer[id]]);
				
				formatex(szData, charsmax(szData), "^"%.1f^" ^"%.1f^" ^"%.1f^" ^"%d^"", g_vTimerOrigin[g_iPlayerTimer[id]][0], g_vTimerOrigin[g_iPlayerTimer[id]][1], g_vTimerOrigin[g_iPlayerTimer[id]][2], g_iTimerAngles[g_iPlayerTimer[id]]);
				
				nvault_set(g_iVault, g_szTimerName[g_iPlayerTimer[id]], szData);
				
				#if defined COLORCHAT
					ColorChat(id, RED, "^4[%s]^1 Timer (^3%s^1) saved!", g_szPrefix, g_szTimerName[g_iPlayerTimer[id]]);
				#else
					client_print(id, print_chat, "[%s] Timer (%s) saved!", g_szPrefix, g_szTimerName[g_iPlayerTimer[id]]);
				#endif
			}
		}
		case 3:
		{
			switch (g_iPlayerTimer[id])
			{
				case START: g_iPlayerTimer[id] = STOP;
				case STOP: g_iPlayerTimer[id] = START;
			}
		}
	}
	
	ClCmdTimer(id);
	return(PLUGIN_HANDLED);
}

LoadTimers()
{
	if (g_iVault == INVALID_HANDLE)	return;
	
	for (new i = 0; i < 2; i++)
	{
		new szData[128], iTimestamp;
		if (nvault_lookup(g_iVault, g_szTimerName[i], szData, charsmax(szData), iTimestamp))
		{
			new szOrigin[3][17], szAngles[2];
			parse(szData, szOrigin[0], charsmax(szOrigin[]), szOrigin[1], charsmax(szOrigin[]), szOrigin[2], charsmax(szOrigin[]), szAngles, charsmax(szAngles));
			
			for (new x = 0; x < 3; x++)	g_vTimerOrigin[i][x] = str_to_float(szOrigin[x]);
			
			g_iTimerAngles[i] = str_to_num(szAngles);
			
			create_timer(0, i, g_vTimerOrigin[i]);
		}
		else	continue;
	}
}

stock create_timer(id, iType, Float:vOrigin[3] = {0.0, 0.0, 0.0})
{
	if (!g_iTimer[iType])
	{
		new iEntity = create_entity("func_button");
		
		if (!is_valid_ent(iEntity))	return;
		
		new szClassName[32];
		formatex(szClassName, charsmax(szClassName), "Timer_%s", g_szTimerName[iType]);
		
		entity_set_string(iEntity, EV_SZ_classname, szClassName);
		entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
		entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
		//set_pev(ent, pev_target, iType ? "timer_end" : "timer_start");	STOP/START?
		entity_set_model(iEntity, g_szTimerModels[iType]);
		entity_set_size(iEntity, Float:{-16.0, -16.0, 0.0}, Float:{16.0, 16.0, 60.0});
		
		g_iTimer[iType] = iEntity;
	}

	if (id)
	{
		new vOriginI[3];
		get_user_origin(id, vOriginI, 3);
		
		new Float:vOriginF[3];
		IVecFVec(vOriginI, vOriginF);
		
		entity_set_origin(g_iTimer[iType], vOriginF);
		
		for (new i = 0; i < 3; i++)	g_vTimerOrigin[iType][i] = vOriginF[i];
	}
	else	entity_set_origin(g_iTimer[iType], vOrigin);
	
	new Float:vAngles[3];
	vAngles[1] = g_flTimerAngles[g_iTimerAngles[iType]];
	
	entity_set_vector(g_iTimer[iType], EV_VEC_angles, vAngles);
	
	drop_to_floor(g_iTimer[iType]);

	switch(iType)
	{
		case 0: fm_set_rendering(g_iTimer[iType], kRenderFxGlowShell, 0, 255, 0, kRenderNormal, 100);
		case 1:	fm_set_rendering(g_iTimer[iType], kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 100);
	}
}

public plugin_end()
{
	if (g_bTimerFound)
	{
		TrieDestroy(g_tStarts);
		TrieDestroy(g_tStops);
	}
	else	if (g_iVault != INVALID_HANDLE)	nvault_close(g_iVault);
	
	SQL_FreeHandle(g_hSqlTuple);
}
Adryyy is offline
Send a message via Yahoo to Adryyy Send a message via Skype™ to Adryyy
D3XT3R
AlliedModders Donor
Join Date: Nov 2016
Location: Lithuania, Bomb A (Kauna
Old 11-06-2017 , 01:29   Re: DeathRun Timer
Reply With Quote #3

ther is an other version for surf ?
__________________
D3XT3R is offline
Send a message via Skype™ to D3XT3R
Old 11-08-2017, 12:33
ZEDD_Intensity
This message has been deleted by ZEDD_Intensity.
Old 04-27-2018, 19:13
PyPKjE20
This message has been deleted by PyPKjE20. Reason: I fix problem...
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 06-25-2018 , 18:52   Re: DeathRun Timer
Reply With Quote #4

Won't compile!!

amx 183 5154

//// deathrun_timer183-5090.sma
//
// C:\Users\GERMAN\Desktop\SCRIPTING\scripting18 3-5154\deathrun_timer183-5090.sma(32) : error 020: invalid symbol name ""
//
// 1 Error.
// Could not locate output file compiled\deathrun_timer183-5090.amx (compile failed).
//
// Compilation Time: 0,34 sec
// ----------------------------------------
sigerman is offline
Snake.
Senior Member
Join Date: Jul 2017
Location: Istanbul
Old 08-30-2018 , 15:44   Re: DeathRun Timer
Reply With Quote #5

This plugin does not save the buttons. Can anyone fix it and can add "delete the buttons" option to menu ?

Last edited by Snake.; 08-30-2018 at 16:04.
Snake. is offline
Send a message via Skype™ to Snake.
foxsay
AlliedModders Donor
Join Date: Sep 2013
Old 07-14-2019 , 07:25   Re: DeathRun Timer
Reply With Quote #6

yep same here doesnt save buttons but records work. maybe there is an alternative?
foxsay is offline
Snake.
Senior Member
Join Date: Jul 2017
Location: Istanbul
Old 07-14-2019 , 21:53   Re: DeathRun Timer
Reply With Quote #7

Quote:
Originally Posted by foxsay View Post
yep same here doesnt save buttons but records work. maybe there is an alternative?
You need to create deathrun/timer in configs to make it save.
Snake. is offline
Send a message via Skype™ to Snake.
foxsay
AlliedModders Donor
Join Date: Sep 2013
Old 07-15-2019 , 05:46   Re: DeathRun Timer
Reply With Quote #8

Quote:
Originally Posted by Snake. View Post
You need to create deathrun/timer in configs to make it save.
Sorry i'm totally new to amxx. Can you explain bit more i would like really to use this plugin?

If you mean folder configs/deathrun/timer nothing happened.

Last edited by foxsay; 07-15-2019 at 06:08.
foxsay is offline
Snake.
Senior Member
Join Date: Jul 2017
Location: Istanbul
Old 07-16-2019 , 08:46   Re: DeathRun Timer
Reply With Quote #9

Try to create deathrun/timer in data folder
Snake. is offline
Send a message via Skype™ to Snake.
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 04-12-2021 , 11:23   Re: DeathRun Timer
Reply With Quote #10

Seems this version works but only with mysql, so well, now you know

Quote:
Originally Posted by Adryyy View Post
It has some problems .. like:

He does not read that 'formatex' for the vault.
Once I set up and restart the map, it says that 'the timer does not exist', although it is on the map (and vault).

My code -

Code:
/*

+--------------------------------------+
|      DeathRun Timer - 2015-2016      |
|                                      |
| Author:                              |
|         deniS[MD] a.k.a icimaro1337  |
| Credits:                             |
|         xPaw[EE]                     |
|         Mistrick[RU]                 |
|         Keniski[RU]                  |
|         Klippy[RS]                   |
+--------------------------------------+


de pus si city?
de scos de tot authid
*/

#include <amxmodx>
#include <engine>
#include <hamsandwich>
#include <nvault>
#include <sqlx>
#include <geoip>
#include <fakemeta_util>
#include <dhudmessage>


//#pragma semicolon 1


// Here you can configure main settings
#define COLORCHAT
#define ADMIN_ACCESS ADMIN_RCON

new const g_szPrefix[] = "TIMER";

const MAX_PLAYERS = 32;
// Here you stop


#if defined COLORCHAT
	#include <colorchat>
#endif


/* Macro */
#define set_bit(%1,%2)	(%1 |= (1<<%2))
#define get_bit(%1,%2)	(%1 & (1<<%2))
#define clr_bit(%1,%2)	(%1 &= ~(1<<%2))
/* Macro */


new const g_szVersion[] = "0.1";


new const g_szTableName[] = "DEATHRUN_STATS";
new g_pWebLink;
new Handle:g_hSqlTuple;
new bool:g_bSqlite;


enum _:eTimer
{
	START,
	STOP
};
new g_szTimerModels[eTimer][] =
{
	"models/deathrun/timer/timer_start.mdl",
	"models/deathrun/timer/timer_stop.mdl"
};
new g_szTimerName[eTimer][] =
{
	"Start",
	"Stop"
};
new Float:g_flTimerAngles[4] =
{
	0.0,
	90.0,
	180.0,
	270.0
};

new g_iPlayerTimer[MAX_PLAYERS + 1],g_bConnected, g_bAlive, g_bStarted,Float:g_flStartTime[MAX_PLAYERS + 1],
Float:g_flFinishTime[MAX_PLAYERS + 1],g_iVault,g_iMsgRoundTime,g_iTimerAngles[eTimer],g_iTimer[eTimer],
Float:g_vTimerOrigin[eTimer][3],g_szMapName[64],Trie:g_tStarts, Trie:g_tStops,bool:g_bTimerFound;

//new g_iHudSyncObj;


public plugin_precache()	for (new i = 0; i < eTimer; i++)	precache_model(g_szTimerModels[i]);

public plugin_init()
{
	register_plugin("DeathRun Timer", g_szVersion, "deniS");


	g_pWebLink = register_cvar("dr_timer_web_link", "http://evils.ro/deathrun_timer_web");// link to web files
	
	register_cvar("dr_timer_sql_host", "sql11.freesqldatabase.com");
	register_cvar("dr_timer_sql_user", "sql11202240");
	register_cvar("dr_timer_sql_pass", "vyS3IeWBCP");
	register_cvar("dr_timer_sql_db", "sql11202240"); /* If you don't have web server, you can use local stats, just add .db like deathrun_stats.db and enable sqlite module! */


	get_mapname(g_szMapName, charsmax(g_szMapName));
	
	g_tStarts	= TrieCreate();
	g_tStops	= TrieCreate();
	
	new i, iSize;
	
	new const szStarts[][] =
	{
		"counter_start", "clockstartbutton", "firsttimerelay", "but_start", "counter_start_button",
		"multi_start", "timer_startbutton", "start_timer_emi", "gogogo"
	};
	iSize = sizeof(szStarts);
	
	for (i = 0; i < iSize; i++)	TrieSetCell(g_tStarts, szStarts[i], 1);
	
	new const szStops[][] =
	{
		"counter_off", "clockstopbutton", "clockstop", "but_stop", "counter_stop_button",
		"multi_stop", "stop_counter", "m_counter_end_emi"
	};
	iSize = sizeof(szStops);
	
	for (i = 0; i < iSize; i++)	TrieSetCell(g_tStops, szStops[i], 1);
	

	new iEntity = -1;//de modificat..
	while ((iEntity = find_ent_by_class(iEntity, "func_button")) != 0)
	{
		new szTargetName[64];
		entity_get_string(iEntity, EV_SZ_targetname, szTargetName, charsmax(szTargetName));
		
		if (TrieKeyExists(g_tStarts, szTargetName) && TrieKeyExists(g_tStops, szTargetName))
		{
			if (!g_bTimerFound)	g_bTimerFound = true;
			//else	g_bTimerFound = false;
			//g_bTimerFound = false	+	!	^x2
			//g_bTimerFound = true;
			
			break;
		}
	}
	

	if (!g_bTimerFound)
	{
		TrieDestroy(g_tStarts);
		TrieDestroy(g_tStops);
		
		/*new szDir[200],szFile[200];
		formatex(szDir, charsmax(szDir), "addons/amxmodx/data/vault/deathrun/timer");
		if(!dir_exists(szDir))	mkdir(szDir)
		formatex(szFile, charsmax(szFile), "%s/%s.vault", szDir,g_szMapName);
		if(!file_exists(szFile))	write_file(szFile,"",-1)*/
		
		g_iVault = nvault_open(g_szMapName);
		
		LoadTimers();
	}
	
	iEntity = create_entity("info_target");
	
	if (iEntity)
	{
		entity_set_float(iEntity, EV_FL_nextthink, get_gametime() + 0.5);
		entity_set_string(iEntity, EV_SZ_classname, "_TimerThink");
		register_think("_TimerThink", "TimerThink");
	}
	
	g_iMsgRoundTime = get_user_msgid("RoundTime");
	
	RegisterHam(Ham_Spawn, "player", "HamSpawnPlayer_Post", true);
	RegisterHam(Ham_Killed, "player", "HamKilledPlayer_Post", true);
	RegisterHam(Ham_Use, "func_button", "HamUseFuncButton_Pre", false);
	
	register_clcmd("say /timer", "ClCmdTimer");
	register_clcmd("say_team /timer", "ClCmdTimer");
	register_clcmd("say /timermenu", "ClCmdTimer");
	register_clcmd("say_team /timermenu", "ClCmdTimer");
	register_clcmd("say /drtimer", "ClCmdTimer");
	register_clcmd("say_team /drtimer", "ClCmdTimer");
	register_clcmd("say /drtimermenu", "ClCmdTimer");
	register_clcmd("say_team /drtimermenu", "ClCmdTimer");
	
	register_clcmd("say /best", "ClCmdBest");
	register_clcmd("say_team /best", "ClCmdBest");
	register_clcmd("say /record", "ClCmdBest");
	register_clcmd("say_team /record", "ClCmdBest");
	
	//g_iHudSyncObj = CreateHudSyncObj();


	//set_msg_block(get_user_msgid("RoundTime"), BLOCK_SET)
}

public plugin_cfg()	set_task(0.5, "DB_Init");
public DB_Init()
{
	state mysql;
	
	new szDB[64];
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	if (contain(szDB, ".") > 0)
	{
		state sqlite;
		
		g_bSqlite = true;
	}
	
	SQL_Init();
}
SQL_Init()<mysql>
{
	new szHost[64], szUser[64], szPass[64], szDB[64];
	get_cvar_string("dr_timer_sql_host", szHost, charsmax(szHost));
	get_cvar_string("dr_timer_sql_user", szUser, charsmax(szUser));
	get_cvar_string("dr_timer_sql_pass", szPass, charsmax(szPass));
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	g_hSqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDB);
	
	new szQuery[512];
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"CREATE TABLE IF NOT EXISTS `%s` \
		( \
			`ID`				INT				NOT NULL	AUTO_INCREMENT, \
			 \
			`MAPNAME`			VARCHAR(64)		NOT NULL, \
			`AUTHID`			VARCHAR(32)		NOT NULL, \
			`NICKNAME`			VARCHAR(64)		NOT NULL, \
			`IP`				VARCHAR(45)		NOT NULL, \
			`COUNTRY_FULL`		VARCHAR(45)		NOT NULL, \
			`COUNTRY_SHORT`		VARCHAR(3)		NOT NULL, \
			`TIME`				DOUBLE			NOT NULL, \
			`DATE`				DATETIME		NOT NULL, \
			 \
			PRIMARY KEY(`ID`) \
		)",
		g_szTableName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
}
SQL_Init()<sqlite>
{
	SQL_SetAffinity("sqlite");
	
	new szDataDir[128];
	get_localinfo("amxx_datadir", szDataDir, charsmax(szDataDir));
	
	new szDB[64];
	get_cvar_string("dr_timer_sql_db", szDB, charsmax(szDB));
	
	new szFile[196];
	formatex(szFile, charsmax(szFile), "%s/%s", szDataDir, szDB);
	
	if (!file_exists(szFile))
	{
		new fp = fopen(szFile, "w");
		
		if (!fp)
		{
			log_amx("[%s] SQL_Init()<sqlite>: File ^"%s^" not found and can't be created!", g_szPrefix, szFile);
			return;
		}
		else	fclose(fp);
	}
	
	g_hSqlTuple = SQL_MakeDbTuple("", "", "", szFile, 0);
	
	new szQuery[512];
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"CREATE TABLE IF NOT EXISTS `%s` \
		( \
			`MAPNAME`				TEXT			NOT NULL, \
			`AUTHID`				TEXT			NOT NULL, \
			`NICKNAME`				TEXT			NOT NULL, \
			`IP`					TEXT			NOT NULL, \
			`COUNTRY_FULL`			TEXT			NOT NULL, \
			`COUNTRY_SHORT`			TEXT			NOT NULL, \
			`TIME`					REAL			NOT NULL, \
			`DATE`					DATETIME		NOT NULL \
		)",
		g_szTableName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
}

public client_putinserver(id)	set_bit(g_bConnected, id);
public client_disconnect(id)
{
	clr_bit(g_bConnected, id);
	if (get_bit(g_bAlive, id))	clr_bit(g_bAlive, id);
	if (get_bit(g_bStarted, id))	clr_bit(g_bStarted, id);
	if (g_flStartTime[id] != 0.0)	g_flStartTime[id] = 0.0;
	if (g_flFinishTime[id] != 0.0)	g_flFinishTime[id] = 0.0;
}

public TimerThink(iEntity)
{
	if (iEntity)	entity_set_float(iEntity, EV_FL_nextthink, get_gametime() + 0.5);
	
	for (new iAlivePlayer = 1; iAlivePlayer <= MAX_PLAYERS; iAlivePlayer++)
	{
		if (get_bit(g_bConnected, iAlivePlayer) && get_bit(g_bAlive, iAlivePlayer) && get_bit(g_bStarted, iAlivePlayer))
		{
			//set_msg_block(get_user_msgid("RoundTime"), BLOCK_NOT)

			new Float:flGameTime = get_gametime();

			//g_flStartTime[iAlivePlayer] / 60, g_flStartTime[iAlivePlayer] % 60
			//new iMinutes = floatround(flGameTime - g_flStartTime[iAlivePlayer] / 60.0);
			//new iSeconds = floatround(flGameTime - g_flStartTime[iAlivePlayer] - iMinutes * 60);
			/*new sSMsg[32];
			format(sSMsg, 31, "Timer: %02d:%02d", iMinutes, iSeconds);
			message_begin(MSG_ONE, StatusText, {0,0,0}, iAlivePlayer);
			write_byte(0);
			write_string(sSMsg);
			message_end();*/
			//client_print(iAlivePlayer,print_center,"Timer: %02d:%02d", iMinutes, iSeconds)


			message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, iAlivePlayer);
			write_short(floatround(flGameTime - g_flStartTime[iAlivePlayer], floatround_floor) + 1);
			message_end();
			
			for (new iDeadPlayer = 1; iDeadPlayer <= MAX_PLAYERS; iDeadPlayer++)//mai jos
			{
				if (get_bit(g_bConnected, iDeadPlayer) && !get_bit(g_bAlive, iDeadPlayer) && entity_get_int(iDeadPlayer, EV_INT_iuser2) == iAlivePlayer && entity_get_int(iDeadPlayer, EV_INT_iuser1) == 4)
				{
					new iMinutesx = floatround(g_flStartTime[iDeadPlayer] / 60.0, floatround_floor);
					new iSecondsx = floatround(g_flStartTime[iDeadPlayer] - iMinutesx * 60, floatround_floor);

					new name[32]
					get_user_name(iDeadPlayer,name,charsmax(name))
					
//					set_hudmessage(0, 255, 0, -1.0, 0.25, 0, _, 0.5, _, _, 1);
//					ShowSyncHudMsg(iDeadPlayer, g_iHudSyncObj, "%02d:%02d", iMinutesx, iSecondsx);
					client_print(iDeadPlayer,print_center,"Timer of %s : %02d:%02d", name, iMinutesx, iSecondsx);
				}
			}
		}
	}
}
public HamSpawnPlayer_Post(id)
{
/*
	if(task_exists(id + TaskID))
		remove_task(id + TaskID);
*/

	set_bit(g_bAlive, id);
	
	if (get_bit(g_bStarted, id))
	{
		clr_bit(g_bStarted, id);
		g_flStartTime[id] = 0.0;
	}


	if(is_user_alive(id))
	{
	message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, id);
	write_short(1);
	message_end();
	}
}

public HamKilledPlayer_Post(id)
{
/*
	if(task_exists(id + TaskID))
		remove_task(id + TaskID);
*/


	clr_bit(g_bAlive, id);
	
	if (get_bit(g_bStarted, id))
	{
		clr_bit(g_bStarted, id);
		g_flStartTime[id] = 0.0;
	}
}

public HamUseFuncButton_Pre(iEntity, id)
{
	if (!get_bit(g_bAlive, id))	return(HAM_IGNORED);
	
	if (g_bTimerFound)
	{
		new szTarget[32];
		entity_get_string(iEntity, EV_SZ_target, szTarget, charsmax(szTarget));
		
		if (TrieKeyExists(g_tStarts, szTarget))	Timer_Start(id);
		else if (TrieKeyExists(g_tStops, szTarget))	Timer_Stop(id);
	}
	else
	{
		if (iEntity == g_iTimer[START])	Timer_Start(id);
		else if (iEntity == g_iTimer[STOP])	Timer_Stop(id);
	}
	
	return(HAM_IGNORED);
}

Timer_Start(id)
{
	if (!get_bit(g_bStarted, id))
	{
		set_bit(g_bStarted, id);
		set_dhudmessage(0, 255, 0, -1.0, 0.80, 0, _, 3.0, _, _, true);
		//ShowSyncHudMsg(id, g_iHudSyncObj, "Timer started!");
		show_dhudmessage(id, "Timer started!");
	}
	else
	{
	set_dhudmessage(255, 0, 0, -1.0, 0.85, 1, _, 3.0, _, _, true);
	show_dhudmessage(id, "Timer re-started!");//ShowSyncHudMsg(id, g_iHudSyncObj, "Timer re-started!");
	}
	
	g_flStartTime[id] = get_gametime();
}

Timer_Stop(id)
{
	if (!get_bit(g_bStarted, id))
	{
		set_dhudmessage(0, 0, 255, -1.0, 0.85, 2, _, 3.0, _, _, true);
		show_dhudmessage(id, "Go back, and Start Timer!");
		return;
	}

	//set_msg_block(get_user_msgid("RoundTime"), BLOCK_SET)
	
	clr_bit(g_bStarted, id);
	g_flFinishTime[id] = get_gametime() - g_flStartTime[id];
	g_flStartTime[id] = 0.0;
	
	message_begin(MSG_ONE_UNRELIABLE, g_iMsgRoundTime, _, id);
	write_short(1);
	message_end();
	
	new szTime[17];
	ClimbtimeToString(g_flFinishTime[id], szTime, charsmax(szTime));
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	
	#if defined COLORCHAT
		//ColorChat(id, RED, "^4[%s]^1 You finished map in^3 %s^1!", g_szPrefix, szTime);
		ColorChat(0, RED, "^4[%s]^3 %s^1 finished map in^3 %s^1!", g_szPrefix, szName, szTime);
	#else
		client_print(id, print_chat, "[%s] You finished map in %s!", g_szPrefix, szTime);
		client_print(0, print_chat, "[%s] %s finished map in %s!", g_szPrefix, szName, szTime);
	#endif
	
	/*new iPlayers[MAX_PLAYERS], iNum;
	get_players(iPlayers, iNum, "ch");
	
	if (iNum)
	{
		new iPlayer;
		
		for (new i = 0; i < iNum; i++)
		{
			iPlayer = iPlayers[i];
			
			if (iPlayer == id)	continue;
			
			#if defined COLORCHAT
				ColorChat(iPlayer, RED, "^4[%s]^3 %s^1 finished map in^3 %s^1!", g_szPrefix, szName, szTime);
			#else
				client_print(iPlayer, print_chat, "[%s] %s finished map in %s!", g_szPrefix, szName, szTime);
			#endif
		}
	}*/
	
	new szQuery[512], cData[1]; cData[0] = id;
	
	formatex
	(
		szQuery, charsmax(szQuery),
		"SELECT \
			`TIME` \
		FROM \
			`%s` \
		WHERE \
			`MAPNAME` = '%s' \
		AND \
			`AUTHID` = '%s'",
		g_szTableName,
		g_szMapName,
		szName
	);
	
	SQL_ThreadQuery(g_hSqlTuple, "Sql_QueryTop_Handler", szQuery, cData, sizeof(cData));
}

public Sql_QueryTop_Handler(iFailState, Handle:hQuery, szError[], iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_IgnoredQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;
	
	new szAuthID[32], szName[64], szIP[32], szCountryFull[45], szCountryShort[3], szDate[32];
	get_user_authid(id, szAuthID, charsmax(szAuthID));
	get_user_name(id, szName, charsmax(szName));
	get_user_ip(id, szIP, charsmax(szIP), 1);
	geoip_country(szIP, szCountryFull, charsmax(szCountryFull));
	geoip_code2(szIP, szCountryShort);
	get_time("%Y%m%d%H%M%S", szDate, charsmax(szDate));
	
	SQL_PrepareString(szName, szName, charsmax(szName));
	
	new szQuery[512];
	
	if (SQL_NumResults(hQuery))
	{
		new Float:flOldTime, Float:flResult, szTime[17];
		
		SQL_ReadResult(hQuery, 0, flOldTime);
		
		if (g_flFinishTime[id] < flOldTime)
		{
			flResult = flOldTime - g_flFinishTime[id];
			ClimbtimeToString(flResult, szTime, charsmax(szTime));
			
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You improved your time for^3 %s^1 msec!", g_szPrefix, szTime);
				ColorChat(0, RED, "^4[%s]^3 %s^1 improved his time for^4 %s^1 msec!", g_szPrefix,szName, szTime);
			#else
				client_print(id, print_chat, "[%s] You improved your time for %s msec!", g_szPrefix, szTime);
			#endif
			
			formatex
			(
				szQuery, charsmax(szQuery),
				"UPDATE `%s` \
				SET \
					`NICKNAME`			= '%s', \
					`IP`				= '%s', \
					`COUNTRY_FULL`		= '%s', \
					`COUNTRY_SHORT`		= '%s', \
					`TIME`				= '%f', \
					`DATE`				= '%s' \
				WHERE \
					`MAPNAME`			= '%s' \
				AND \
					`AUTHID`			= '%s'",
				g_szTableName,
				szName,
				szIP,
				szCountryFull,
				szCountryShort,
				g_flFinishTime[id],
				szDate,
				g_szMapName,
				szName
			);
			
			SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
			
			formatex
			(
				szQuery, charsmax(szQuery),
				"SELECT \
					`AUTHID` \
				FROM \
					`%s` \
				WHERE \
					MAPNAME='%s' \
				ORDER BY \
					`TIME` \
				LIMIT 15",
				g_szTableName,
				g_szMapName
			);
			
			SQL_ThreadQuery(g_hSqlTuple, "Sql_GetPlaceQuery_Handler", szQuery, cData, sizeof(cData[]));
		}
		else
		{
			flResult = g_flFinishTime[id] - flOldTime;
			ClimbtimeToString(flResult, szTime, charsmax(szTime));
			
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You failed your time for^3 %s^1 msec!", g_szPrefix, szTime);
				ColorChat(0, RED, "^4[%s]^3 %s^1 failed his time for^4 %s^1 msec!", g_szPrefix,szName, szTime);
				//ColorChat(0, RED, "^4[%s]^1 It seems he failed to beat the record^3 %s^1 msec, owned by^4 %s", g_szPrefix, szTime);
			#else
				client_print(id, print_chat, "[%s] You failed your time for %s msec!", g_szPrefix, szTime);
			#endif
		}
	}
	else
	{
		formatex
		(
			szQuery, charsmax(szQuery),
			"INSERT INTO `%s` \
			( \
				`MAPNAME`, \
				`AUTHID`, \
				`NICKNAME`, \
				`IP`, \
				`COUNTRY_FULL`, \
				`COUNTRY_SHORT`, \
				`TIME`, \
				`DATE` \
			) \
			 \
			VALUES \
			( \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%s', \
				'%f', \
				'%s' \
			)",
			g_szTableName,
			g_szMapName,
			szName,
			szName,
			szIP,
			szCountryFull,
			szCountryShort,
			g_flFinishTime[id],
			szDate
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_IgnoredQuery_Handler", szQuery);
		
		formatex
		(
			szQuery, charsmax(szQuery),
			"SELECT \
				`AUTHID` \
			FROM \
				`%s` \
			WHERE \
				MAPNAME='%s' \
			ORDER BY \
				`TIME` \
			LIMIT 15",
			g_szTableName,
			g_szMapName
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_GetPlaceQuery_Handler", szQuery, cData, sizeof(cData[]));
	}
	
	g_flFinishTime[id] = 0.0;
}

public Sql_GetPlaceQuery_Handler(iFailState, Handle:hQuery, szError, iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_GetPlaceQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;
	
	new szName[32];
	get_user_name(id, szName, charsmax(szName));
	
	new i, szAuthID_SQL[32];
	
	while(SQL_MoreResults(hQuery))
	{
		i++;
		
		SQL_ReadResult(hQuery, 0, szAuthID_SQL, charsmax(szAuthID_SQL));
		
		if (equali(szName, szAuthID_SQL))//de pus la finish, fara equal asta..
		{
			#if defined COLORCHAT
				//ColorChat(id, RED, "^4[%s]^1 You are now on^3 %d^1 place in map top!", g_szPrefix, i);
				ColorChat(0, RED, "^4[%s]^3 %s^1 are now on^4 %d^1 place in map top!", g_szPrefix,szName, i);
			#else
				client_print(id, print_chat, "[%s] You are now on %d place in map top!", g_szPrefix, i);
			#endif
			
			/*new iPlayers[MAX_PLAYERS], iNum;
			get_players(iPlayers, iNum, "ch");
			
			if (iNum)
			{
				new iPlayer;
				
				for (new i = 0; i < iNum; i++)
				{
					iPlayer = iPlayers[i];
					
					if (iPlayer == id)	continue;
					
					#if defined COLORCHAT
						ColorChat(iPlayer, RED, "^4[%s]^3 %s^1 is now on^3 %d^1 place in map top!", g_szPrefix, szName, i);
					#else
						client_print(iPlayer, print_chat, "[%s] %s is now on %d place in map top!", g_szPrefix, szName, i);
					#endif
				}
			}*/
			break;
		}
		SQL_NextRow(hQuery);
	}
}

public Sql_IgnoredQuery_Handler(iFailState, Handle:hQuery, szError[], iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_IgnoredQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
}
public ClCmdBest(id)
{
	/*if (!g_bTimerFound)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 This map does not have timer yet!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] This map does not have timer yet!", g_szPrefix);
		#endif
		return;
	}*/

	if (!g_bSqlite)
	{
		new szWebLink[128];
		get_pcvar_string(g_pWebLink, szWebLink, charsmax(szWebLink));
		
		new szMotd[256];
		formatex(szMotd, charsmax(szMotd), "<META HTTP-EQUIV=^"REFRESH^" CONTENT=^"0;URL=%s/maptop.php?mapname=%s^">", szWebLink, g_szMapName);
		
		show_motd(id, szMotd, "DRTIMER - Map Top");
	}
	else
	{
		new szQuery[512], cData[1]; cData[0] = id;
		
		formatex
		(
			szQuery, charsmax(szQuery),
			"SELECT \
				`NICKNAME`, \
				`TIME` \
			FROM \
				`%s` \
			WHERE \
				`MAPNAME` = '%s' \
			ORDER BY \
				`TIME` \
			LIMIT 15",
			g_szTableName,
			g_szMapName
		);
		
		SQL_ThreadQuery(g_hSqlTuple, "Sql_LoadTopQuery_Handler", szQuery, cData, sizeof(cData));
	}
}

public Sql_LoadTopQuery_Handler(iFailState, Handle:hQuery, szError, iError, cData[], iSize)
{
	if (iFailState != TQUERY_SUCCESS)
	{
		log_amx("[%s] Sql_GetPlaceQuery_Handler(): SQL_Error #%d - %s", g_szPrefix, iError, szError);
		return;
	}
	
	new id = cData[0];
	
	if (!get_bit(g_bConnected, id))	return;

	if(SQL_NumResults(hQuery)!=1)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 It seems that nobody has finished this map yet. Be that!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] It seems that nobody has finished this map yet. Be that!", g_szPrefix);
		#endif
		
		return;
	}
	
	new szMotd[1536], iSize = charsmax(szMotd);
	
	new iLen = formatex
	(
		szMotd, iSize,
		"<!DOCTYPE HTML> \
		<html> \
		<head> \
			<style type=^"text/css^"> \
				body \
				{ \
					background: #000; \
					margin: 8px; \
					color: #FFB000; \
					font: normal 16px/20px Verdana, Tahoma, sans-serif; \
					text-align: center; \
				} \
				th:nth-child(2){ text-align: left; } \
				td:nth-child(2){ text-align: left; } \
			</style> \
		</head> \
		<body>"
	);
	
	iLen += formatex
	(
		szMotd[iLen], iSize - iLen,
		"<table align=^"center^" width=^"90%%^"> \
			<tr> \
				<th width=^"5%%^">#</th>\
				<th width=^"40%%^">Player</th>\
				<th width=^"20%%^">Time</th>\
			</tr> \
		"
	);
	
	new i = 1;
	new Float:flTime, szName[32], szTime[32];
	
	while (SQL_MoreResults(hQuery))
	{
		SQL_ReadResult(hQuery, 0, szName, 31);
		SQL_ReadResult(hQuery, 1, flTime);
		
		ClimbtimeToString(flTime, szTime, 16);
		
		iLen += formatex
		(
			szMotd[iLen], iSize - iLen,
			"<tr> \
				<td>%d</td> \
				<td>%s</td> \
				<td>%s</td> \
			</tr>",
			i,
			szName,
			szTime
		);
		
		i++;
		SQL_NextRow(hQuery);
	}
	
	formatex
	(
		szMotd[iLen], iSize - iLen,
		"</table> \
		</body> \
		</html>"
	);
	
	show_motd(id, szMotd, "DRTIMER - Map Top");
}

stock SQL_PrepareString(const szQuery[], szOutPut[], iSize)
{
	copy(szOutPut, iSize, szQuery);
	replace_all(szOutPut, iSize, "'", "\'");
	replace_all(szOutPut, iSize, "`", "\`");
	replace_all(szOutPut, iSize, "\\", "\\\\");
}

ClimbtimeToString(Float:flClimbTime, szOutPut[], iLen)
{
	new iMinutes = floatround(flClimbTime / 60.0, floatround_floor);
	new iSeconds = floatround(flClimbTime - iMinutes * 60, floatround_floor);
	new iMiliSeconds = floatround((flClimbTime - (iMinutes * 60 + iSeconds)) * 100, floatround_floor);
	
	formatex(szOutPut, iLen, "%02i:%02i.%02i", iMinutes, iSeconds, iMiliSeconds);
}

public ClCmdTimer(id)
{
	if (~get_user_flags(id) & ADMIN_ACCESS)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 You don't have enought access!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] You don't have enought access!", g_szPrefix);
		#endif
		
		return(PLUGIN_HANDLED);
	}
	if (g_bTimerFound)
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 This map already have timers!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] This map already have timers!", g_szPrefix);
		#endif
		return(PLUGIN_HANDLED);
	}
	if (!get_bit(g_bAlive, id))
	{
		#if defined COLORCHAT
			ColorChat(id, NORMAL, "^4[%s]^1 You should be alive!", g_szPrefix);
		#else
			client_print(id, print_chat, "[%s] You should be alive!", g_szPrefix);
		#endif
		return(PLUGIN_HANDLED);
	}
	
	TimerMenu(id);
	
	return(PLUGIN_HANDLED);
}

public TimerMenu(id)
{
	new iMenu = menu_create("\r[DeathRun]\y Timer Menu", "TimerMenu_Handler");
	
	menu_additem(iMenu, "Create");
	menu_additem(iMenu, "Rotate^n");
	
	menu_additem(iMenu, "Save^n");
	
	new szMenuItem[64];
	formatex(szMenuItem, charsmax(szMenuItem), "Timer - (\y%s\w)", g_szTimerName[g_iPlayerTimer[id]]);
	menu_additem(iMenu, szMenuItem);
	
	menu_display(id, iMenu);
}

public TimerMenu_Handler(id, iMenu, iItem)
{
	if (iItem == MENU_EXIT)
	{
		menu_destroy(iMenu);
		return(PLUGIN_HANDLED);
	}
	
	switch (iItem)
	{
		case 0: create_timer(id, g_iPlayerTimer[id]);
		case 1:
		{
			if (is_valid_ent(g_iTimer[g_iPlayerTimer[id]]))
			{
				switch (g_iTimerAngles[g_iPlayerTimer[id]])
				{
					case 3: g_iTimerAngles[g_iPlayerTimer[id]] = 0;
					case 0, 1, 2: g_iTimerAngles[g_iPlayerTimer[id]]++;
				}
				
				new Float:vAngles[3];
				vAngles[1] = g_flTimerAngles[g_iTimerAngles[g_iPlayerTimer[id]]];
				
				entity_set_vector(g_iTimer[g_iPlayerTimer[id]], EV_VEC_angles, vAngles);
			}
		}
		case 2:
		{
			if (is_valid_ent(g_iTimer[g_iPlayerTimer[id]]))
			{
				if (g_iVault == INVALID_HANDLE)	return(PLUGIN_HANDLED);
				
				new szData[128], iTimestamp;
				
				if (nvault_lookup(g_iVault, g_szTimerName[g_iPlayerTimer[id]], szData, charsmax(szData), iTimestamp))	nvault_remove(g_iVault, g_szTimerName[g_iPlayerTimer[id]]);
				
				formatex(szData, charsmax(szData), "^"%.1f^" ^"%.1f^" ^"%.1f^" ^"%d^"", g_vTimerOrigin[g_iPlayerTimer[id]][0], g_vTimerOrigin[g_iPlayerTimer[id]][1], g_vTimerOrigin[g_iPlayerTimer[id]][2], g_iTimerAngles[g_iPlayerTimer[id]]);
				
				nvault_set(g_iVault, g_szTimerName[g_iPlayerTimer[id]], szData);
				
				#if defined COLORCHAT
					ColorChat(id, RED, "^4[%s]^1 Timer (^3%s^1) saved!", g_szPrefix, g_szTimerName[g_iPlayerTimer[id]]);
				#else
					client_print(id, print_chat, "[%s] Timer (%s) saved!", g_szPrefix, g_szTimerName[g_iPlayerTimer[id]]);
				#endif
			}
		}
		case 3:
		{
			switch (g_iPlayerTimer[id])
			{
				case START: g_iPlayerTimer[id] = STOP;
				case STOP: g_iPlayerTimer[id] = START;
			}
		}
	}
	
	ClCmdTimer(id);
	return(PLUGIN_HANDLED);
}

LoadTimers()
{
	if (g_iVault == INVALID_HANDLE)	return;
	
	for (new i = 0; i < 2; i++)
	{
		new szData[128], iTimestamp;
		if (nvault_lookup(g_iVault, g_szTimerName[i], szData, charsmax(szData), iTimestamp))
		{
			new szOrigin[3][17], szAngles[2];
			parse(szData, szOrigin[0], charsmax(szOrigin[]), szOrigin[1], charsmax(szOrigin[]), szOrigin[2], charsmax(szOrigin[]), szAngles, charsmax(szAngles));
			
			for (new x = 0; x < 3; x++)	g_vTimerOrigin[i][x] = str_to_float(szOrigin[x]);
			
			g_iTimerAngles[i] = str_to_num(szAngles);
			
			create_timer(0, i, g_vTimerOrigin[i]);
		}
		else	continue;
	}
}

stock create_timer(id, iType, Float:vOrigin[3] = {0.0, 0.0, 0.0})
{
	if (!g_iTimer[iType])
	{
		new iEntity = create_entity("func_button");
		
		if (!is_valid_ent(iEntity))	return;
		
		new szClassName[32];
		formatex(szClassName, charsmax(szClassName), "Timer_%s", g_szTimerName[iType]);
		
		entity_set_string(iEntity, EV_SZ_classname, szClassName);
		entity_set_int(iEntity, EV_INT_solid, SOLID_BBOX);
		entity_set_int(iEntity, EV_INT_movetype, MOVETYPE_NONE);
		//set_pev(ent, pev_target, iType ? "timer_end" : "timer_start");	STOP/START?
		entity_set_model(iEntity, g_szTimerModels[iType]);
		entity_set_size(iEntity, Float:{-16.0, -16.0, 0.0}, Float:{16.0, 16.0, 60.0});
		
		g_iTimer[iType] = iEntity;
	}

	if (id)
	{
		new vOriginI[3];
		get_user_origin(id, vOriginI, 3);
		
		new Float:vOriginF[3];
		IVecFVec(vOriginI, vOriginF);
		
		entity_set_origin(g_iTimer[iType], vOriginF);
		
		for (new i = 0; i < 3; i++)	g_vTimerOrigin[iType][i] = vOriginF[i];
	}
	else	entity_set_origin(g_iTimer[iType], vOrigin);
	
	new Float:vAngles[3];
	vAngles[1] = g_flTimerAngles[g_iTimerAngles[iType]];
	
	entity_set_vector(g_iTimer[iType], EV_VEC_angles, vAngles);
	
	drop_to_floor(g_iTimer[iType]);

	switch(iType)
	{
		case 0: fm_set_rendering(g_iTimer[iType], kRenderFxGlowShell, 0, 255, 0, kRenderNormal, 100);
		case 1:	fm_set_rendering(g_iTimer[iType], kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 100);
	}
}

public plugin_end()
{
	if (g_bTimerFound)
	{
		TrieDestroy(g_tStarts);
		TrieDestroy(g_tStops);
	}
	else	if (g_iVault != INVALID_HANDLE)	nvault_close(g_iVault);
	
	SQL_FreeHandle(g_hSqlTuple);
}
sigerman is offline
Reply


Thread Tools
Display Modes

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 15:32.


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