problema plugin

Discutii despre problemele aparute in jocul Counter-Strike.

Moderators: Moderatori ajutatori, Moderatori

Post Reply
ImparctVirtual
Membru, skill 0
Membru, skill 0
Posts: 62
Joined: 21 Jun 2018, 02:41
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

23 Jun 2018, 09:57

salut, folosesc un plugin facut de Hattrick cu numele NewStats
am si eu o problema l-am pus pe server am editat reclama din el in lod de [ZP] am pus [CS]
problema este: cand un player scrie /time arata ca, are 10 minute pe server i-ar cand schimb mapa si scrie inapoi /time zice ca, are 0 minute pe server
vreau sa stiu si eu unde se salveaza timpul player-ului petrecut pe server va rog frumos

plugin-ul:
| Afiseaza codul
#pragma ctrlchar '\'
#pragma dynamic 8000000
#pragma tabsize 0
#pragma semicolon 1

#include amxmodx
//#include license
#include sqlx

#define Maximum_Players 32

#define Plugin_Name "New Stats"
#define Plugin_Version "1.0"
#define Plugin_Author "Hattrick (Claudiu HKS)"

#define SQL_Server ""
#define SQL_Person ""
#define SQL_Password ""
#define SQL_Database "StatsDb"

#define Date_Format "%d.%m.%Y @ %H:%M" /** %d is day, %m is month, %Y is year, %H is hour and %M is minute. */

#define Errors_File "NewStats-Errors.LOG" /** Where the errors should be logged */

#define Chat_Tag "[ZP]"
#define Chat_Tag_Color 4 /** 1 for yellow, 3 for team color and 4 for green. */
#define Chat_Message_For_Victim 1 /** Chat messages for victim. Use 0 to disable. */
#define Chat_Message_For_Killer 1 /** Chat messages for killer. Use 0 to disable */
#define Chat_Detailed_Rank 1 /** Also includes Kills, Deaths, headShots and KpD ratio. */

#define Score_Start 1000 /** Score to start with. */
#define Score_For_Suicide 5 /** Loses 5 points if committing suicide. */
#define Score_For_Kill 5 /** Gets 5 points if committing normal kill. */
#define Score_For_Head_Shot 10 /** Gets 10 points if committing headshot kill. */
#define Score_For_Death 3 /** Loses 3 points if getting killed. */

#define Name_Kick_Reason "Stop changing your name that fast."
#define Name_Change_Interval 7.5 /** Seconds between changing names. */

#define Task_Update_Time 23785321 /** Random offset. */
#define Task_Id_Update_Time (Id - Task_Update_Time) /** TaskId - Offset returns player's Id. */

#define Seconds_In_Minute 60
#define Seconds_In_Hour 3600
#define Seconds_In_Day 86400
#define Seconds_In_Week 604800

enum timeUnit
{
	timeUnit_None = 0,
	timeUnit_Seconds,
	timeUnit_Minutes,
	timeUnit_Hours,
	timeUnit_Days,
	timeUnit_Weeks,
	timeUnit_Count
};

static Handle:g_Tuple = Empty_Handle;

static g_Query[1024] = { 0, ... };
static g_modName[64] = { 0, ... };

static g_Name[Maximum_Players + 1][64];
static g_Steam[Maximum_Players + 1][64];
static g_Ip[Maximum_Players + 1][64];
static g_seenString[Maximum_Players + 1][64];
static g_timeString[Maximum_Players + 1][64];

static g_Time[Maximum_Players + 1] = { 0, ... };
static g_Score[Maximum_Players + 1] = { 0, ... };
static g_Seen[Maximum_Players + 1] = { 0, ... };
static g_Kills[Maximum_Players + 1] = { 0, ... };
static g_Deaths[Maximum_Players + 1] = { 0, ... };
static g_headShots[Maximum_Players + 1] = { 0, ... };
static g_kmdValue[Maximum_Players + 1] = { 0, ... };

static Float:g_kpdRatio[Maximum_Players + 1] = { 0.0, ... };

static g_maxPlayers = 0;
static g_sayText = 0;
static g_recordsCount = 0;

stock __DHud_Color;
stock __DHud_X;
stock __DHud_Y;
stock __DHud_Effect;
stock __DHud_FXTime;
stock __DHud_HoldTime;
stock __DHud_FadeInTime;
stock __DHud_FadeOutTime;

prepareDHudMessage(Red = 0, Green = 0, Blue = 0, Float:X = 0.0, Float:Y = 0.0, Effect = 0, \
	Float:FXTime = 0.0, Float:HoldTime = 0.0, Float:FadeInTime = 0.0, Float:FadeOutTime = 0.0)
{
	__DHud_Color = Blue + (Green << 8) + (Red << 16);
	__DHud_X = _:X;
	__DHud_Y = _:Y;
	__DHud_Effect = Effect;
	__DHud_FXTime = _:FXTime;
	__DHud_HoldTime = _:HoldTime;
	__DHud_FadeInTime = _:FadeInTime;
	__DHud_FadeOutTime = _:FadeOutTime;

	return 1;
}

sendDHudMessage(Target, Format[], any:... /** 3 */)
{
	static Buffer[256] = { 0, ... }, Length = 0;

	Length = vformat(Buffer, charsmax(Buffer), Format, 3 /** 3 */);

	message_begin(isValidPlayer(Target) ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, \
		SVC_DIRECTOR, _, Target);
	write_byte(Length + 31);
	write_byte(DRC_CMD_MESSAGE);
	write_byte(__DHud_Effect);
	write_long(__DHud_Color);
	write_long(__DHud_X);
	write_long(__DHud_Y);
	write_long(__DHud_FadeInTime);
	write_long(__DHud_FadeOutTime);
	write_long(__DHud_HoldTime);
	write_long(__DHud_FXTime);
	write_string(Buffer);
	message_end();

	return Length;
}

addCommas(Number, Output[], outputSize)
{
	static Temporary[16] = { 0, ... }, outputPosition = 0, \
		numberPosition = 0, numberLength = 0;

	formatex(Temporary, charsmax(Temporary), "");
	outputPosition = numberPosition = numberLength = 0;

	if (Number < 0)
	{
		Output[outputPosition++] = '-';

		Number = abs(Number);
	}

	numberLength = num_to_str(Number, Temporary, charsmax(Temporary));

	if (numberLength <= 3)
		outputPosition += copy(Output[outputPosition], outputSize, Temporary);

	else
	{
		while (numberPosition < numberLength && outputPosition < outputSize)
		{
			Output[outputPosition++] = Temporary[numberPosition++];

			if ((numberLength - numberPosition) && !((numberLength - numberPosition) % 3))
				Output[outputPosition++] = ',';
		}

		Output[outputPosition] = 0;
	}

	return outputPosition;
}

computeTimeLength(Time, timeUnit:unitType, Output[], outputSize)
{
	static Weeks = 0, Days = 0, Hours = 0, Minutes = 0, Seconds = 0, \
		maxElementId = 0, timeElement[5][64], Length = 0;

	if (Time > 0)
	{
		maxElementId = 0;

		switch (unitType)
		{
			case timeUnit_Seconds: Seconds = Time;
			case timeUnit_Minutes: Seconds = Time * Seconds_In_Minute;
			case timeUnit_Hours: Seconds = Time * Seconds_In_Hour;
			case timeUnit_Days: Seconds = Time * Seconds_In_Day;
			case timeUnit_Weeks: Seconds = Time * Seconds_In_Week;
		}

		Weeks = Seconds / Seconds_In_Week;
		Seconds -= (Weeks * Seconds_In_Week);

		Days = Seconds / Seconds_In_Day;
		Seconds -= (Days * Seconds_In_Day);

		Hours = Seconds / Seconds_In_Hour;
		Seconds -= (Hours * Seconds_In_Hour);

		Minutes = Seconds / Seconds_In_Minute;
		Seconds -= (Minutes * Seconds_In_Minute);

		if (Weeks > 0)
			formatex(timeElement[maxElementId++], charsmax(timeElement[]), "%d w", Weeks);

		if (Days > 0)
			formatex(timeElement[maxElementId++], charsmax(timeElement[]), "%d d", Days);

		if (Hours > 0)
			formatex(timeElement[maxElementId++], charsmax(timeElement[]), "%d h", Hours);

		if (Minutes > 0)
			formatex(timeElement[maxElementId++], charsmax(timeElement[]), "%d m", Minutes);

		if (Seconds > 0)
			formatex(timeElement[maxElementId++], charsmax(timeElement[]), "%d s", Seconds);

		switch (maxElementId)
		{
			case 1: Length = formatex(Output, outputSize, "%s", timeElement[0]);
			case 2: Length = formatex(Output, outputSize, "%s %s", timeElement[0], timeElement[1]);
			case 3: Length = formatex(Output, outputSize, "%s %s %s", timeElement[0], timeElement[1], \
						timeElement[2]);
			case 4: Length = formatex(Output, outputSize, "%s %s %s %s", timeElement[0], timeElement[1], \
						timeElement[2], timeElement[3]);
			case 5: Length = formatex(Output, outputSize, "%s %s %s %s %s", timeElement[0], timeElement[1], \
						timeElement[2], timeElement[3], timeElement[4]);
		}

		return Length;
	}

	Length = formatex(Output, outputSize, "0 m");

	return Length;
}

bool:isValidPlayer(Player)
{
	return bool:(Player >= 1 && Player <= g_maxPlayers);
}

resetPlayer(Player)
{
	static timeNow = 0;

	if (isValidPlayer(Player) && !is_user_bot(Player) && !is_user_hltv(Player))
	{
		timeNow = get_systime();

		/**
		* -----------------------------------------------------
		* Players
		* -----------------------------------------------------
		* Name
		* Steam
		* Ip
		* Score
		* Kills
		* Deaths
		* headShots
		* Time			- The time spent in minutes.
		* timeString	- Formatted as a string.
		* Seen			- get_systime() stamp.
		* seenString	- get_systime() stamp formatted as a time string including date.
		* kpdRatio		- Kills/ Deaths ratio.
		* kmdValue		- Kills - Deaths value.
		*/

		g_Score[Player] = Score_Start;
		g_Kills[Player] = 0;
		g_Deaths[Player] = 0;
		g_headShots[Player] = 0;
		g_Time[Player] = 0;
		computeTimeLength(g_Time[Player], timeUnit_Minutes, g_timeString[Player], charsmax(g_timeString[]));
		g_Seen[Player] = timeNow;
		format_time(g_seenString[Player], charsmax(g_seenString[]), Date_Format);
		g_kpdRatio[Player] = 0.0;
		g_kmdValue[Player] = 0;
	}
}

Float:computeKpdRatio(Player)
{
	if (isValidPlayer(Player) && is_user_connected(Player) && \
		is_user_bot(Player) == 0 && is_user_hltv(Player) == 0)
	{
		if (g_Deaths[Player] == 0)
		{
			return float(g_Kills[Player]);
		}

		else
		{
			return float(g_Kills[Player] / g_Deaths[Player]);
		}
	}

	return 0.0;
}

computeKmdValue(Player)
{
	if (isValidPlayer(Player) && is_user_connected(Player) && \
		is_user_bot(Player) == 0 && is_user_hltv(Player) == 0)
	{
		return g_Kills[Player] - g_Deaths[Player];
	}

	return 0;
}

/**
* Updates player's rank statistics.
*/
updateRank(Client)
{
	if (isValidPlayer(Client) && is_user_connected(Client) && \
		is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		/**
		* -----------------------------------------------------
		* Players
		* -----------------------------------------------------
		* Name
		* Steam
		* Ip
		* Score
		* Kills
		* Deaths
		* headShots
		* Time			- The time spent in minutes.
		* timeString	- Formatted as a string.
		* Seen			- get_systime() stamp.
		* seenString	- get_systime() stamp formatted as a time string including date.
		* kpdRatio		- Kills/ Deaths ratio.
		* kmdValue		- Kills - Deaths value.
		*/
		formatex(g_Query, charsmax(g_Query), "UPDATE Players SET Ip = '%s', Score = %d, Kills = %d, Deaths = %d, \
			headShots = %d, Seen = %d, seenString = '%s', kpdRatio = %f, kmdValue = %d WHERE Name = '%s';", \
			g_Ip[Client], g_Score[Client], g_Kills[Client], g_Deaths[Client], g_headShots[Client], \
			g_Seen[Client], g_seenString[Client], g_kpdRatio[Client], g_kmdValue[Client], g_Name[Client]);

		SQL_ThreadQuery(g_Tuple, "emptyFunction", g_Query);
	}
}

/**
* Returns the length of the message sent.
*/
coloredMessage(Target, Format[], any:... /** 3 */)
{
	static Buffer[256] = { 0, ... }, Length = 0, Other = 0, bool:validPlayer;

	validPlayer = isValidPlayer(Target);

	Length = formatex(Buffer, charsmax(Buffer), "%c%s\x01 ", Chat_Tag_Color, Chat_Tag);

	/**
	* Adds any:... list of parameters to Buffer.
	*/
	Length += vformat(Buffer[Length], charsmax(Buffer) - Length, Format, 3 /** 3 */);

	if (validPlayer && is_user_connected(Target) && \
		is_user_bot(Target) == 0 && is_user_hltv(Target) == 0)
	{
		message_begin(MSG_ONE_UNRELIABLE, g_sayText, _, Target);
		write_byte(Target);
		write_string(Buffer);
		message_end();
	}

	/**
	* Sends message to everyone.
	*/
	else if (!validPlayer)
	{
		for (Other = 1; Other <= g_maxPlayers; Other++)
		{
			if (is_user_connected(Other) && is_user_bot(Other) == 0 && \
				is_user_hltv(Other) == 0)
			{
				message_begin(MSG_ONE_UNRELIABLE, g_sayText, _, Other);
				write_byte(Other);
				write_string(Buffer);
				message_end();
			}
		}
	}

	return Length;
}

public plugin_natives()
{
	/**
	* NewStats
	*/
	register_library("NewStats");

	 /** Returns 0 if it fails. */
	register_native("NewStats_GetStats", "NewStats_GetStats");
	
	/** Returns 0 if it fails. Returns how many players were selected otherwise. */
	register_native("NewStats_GetTop15", "NewStats_GetTop15");
}

/**
* Retrieves the name of the best 15 players.
*
* Returns 0 if it fails. Returns how many players have been selected otherwise.
* If there are not 15 ranked players yet, it might return values like 1, 2, 3 and so on.
* Example of use:
*
*	new totalPlayers = NewStats_GetTop15(...);
*
* And then you can get the rank statistics for each.
*
* =====================================================================================
*
* native NewStats_GetTop15(_n1[], _n2[], _n3[], _n4[], _n5[], _n6[], _n7[], _n8[], \
*	_n9[], _n10[], _n11[], _n12[], _n13[], _n14[], _n15[]);
*
*/
public NewStats_GetTop15(pluginId, parametersCount)
{
	static Name[15][64], Total, Error[256], errorId, Handle:Connection, \
		Handle:Query, Iterator;

	Connection = SQL_Connect(g_Tuple, errorId, Error, charsmax(Error));

	if (errorId)
	{
		log_to_file(Errors_File, "NewStats_GetTop15() failed because SQL has encountered an error.");
		log_to_file(Errors_File, "The error is listed below.");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);

		return 0;
	}

	Query = SQL_PrepareQuery(Connection, "SELECT Name FROM Players ORDER BY kmdValue DESC LIMIT 15;");
	SQL_Execute(Query);

	if (SQL_NumResults(Query) == 0)
	{
		SQL_FreeHandle(Query);
		SQL_FreeHandle(Connection);

		return 0;
	}

	Total = 0;

	while (SQL_MoreResults(Query))
	{
		SQL_ReadResult(Query, 0, Name[Total++], charsmax(Name[]));

		SQL_NextRow(Query);
	}

	SQL_FreeHandle(Query);
	SQL_FreeHandle(Connection);

	for (Iterator = 0; Iterator < Total; Iterator++)
		set_string(Iterator + 1, Name[Iterator], charsmax(Name[]));

	return Total;
}

/**
* Retrieves information of a player by name.
*
* Returns 0 if it fails. If the name of the player does not exists and so on.
* Returns 1 otherwise.
* These values are all strings. You can then convert them to numbers and so on.
* Example of use:
*
*	new Name[64] = "Hattrick";
*	Steam[64], Ip[64], Score[16], Rank[16];
*	new Success = NewStats_GetStats(Name, Steam, Ip, Score, ...);
*
*	if (Success)
*	{
*		server_print("Player %s's score is %s. Or numeric, %d.", Name, Score, str_to_num(Score));
*	}
*
* =====================================================================================
*
* native NewStats_GetStats(const Name[], Steam[], Ip[], Score[], Kills[], \
*	Deaths[], headShots[], Time[], timeString[], Seen[], seenString[], \
*	kpdRatio[], kmdValue[], Rank[], totalPositions[]);
*
*/
public NewStats_GetStats(pluginId, parametersCount)
{
	static Name[64], Error[256], errorId, Handle:Connection, Handle:Query, Kills[16], Deaths[16], \
		headShots[16], Score[16], Ip[64], Steam[64], Time[16], timeString[64], Seen[16], \
		seenString[64], kpdRatio[16], kmdValue[16], Kills_i, Deaths_i, headShots_i, Score_i, \
		Time_i, Seen_i, Float:kpdRatio_f, kmdValue_i, Rank[16], Rank_i, totalPositions[16];

	get_string(1, Name, charsmax(Name));

	replace_all(Name, charsmax(Name), "`", "*");
	replace_all(Name, charsmax(Name), "'", "*");
	replace_all(Name, charsmax(Name), "\"", "*");

	/**
	* -----------------------------------------------------
	* Players
	* -----------------------------------------------------
	* Name
	* Steam
	* Ip
	* Score
	* Kills
	* Deaths
	* headShots
	* Time			- The time spent in minutes.
	* timeString	- Formatted as a string.
	* Seen			- get_systime() stamp.
	* seenString	- get_systime() stamp formatted as a time string including date.
	* kpdRatio		- Kills/ Deaths ratio.
	* kmdValue		- Kills - Deaths value.
	*/
	Connection = SQL_Connect(g_Tuple, errorId, Error, charsmax(Error));

	if (errorId)
	{
		log_to_file(Errors_File, "NewStats_GetStats() failed because SQL has encountered an error.");
		log_to_file(Errors_File, "The error is listed below.");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);

		return 0;
	}

	formatex(g_Query, charsmax(g_Query), "SELECT Steam, Ip, Score, Kills, Deaths, headShots, \
		Time, timeString, Seen, seenString, kpdRatio, kmdValue FROM Players WHERE Name = '%s';", Name);

	Query = SQL_PrepareQuery(Connection, g_Query);
	SQL_Execute(Query);

	if (SQL_NumResults(Query) == 0)
	{
		SQL_FreeHandle(Query);
		SQL_FreeHandle(Connection);

		return 0;
	}

	SQL_ReadResult(Query, 0, Steam, charsmax(Steam));
	SQL_ReadResult(Query, 1, Ip, charsmax(Ip));
	Score_i = SQL_ReadResult(Query, 2);
	num_to_str(Score_i, Score, charsmax(Score));
	Kills_i = SQL_ReadResult(Query, 3);
	num_to_str(Kills_i, Kills, charsmax(Kills));
	Deaths_i = SQL_ReadResult(Query, 4);
	num_to_str(Deaths_i, Deaths, charsmax(Deaths));
	headShots_i = SQL_ReadResult(Query, 5);
	num_to_str(headShots_i, headShots, charsmax(headShots));
	Time_i = SQL_ReadResult(Query, 6);
	num_to_str(Time_i, Time, charsmax(Time));
	SQL_ReadResult(Query, 7, timeString, charsmax(timeString));
	Seen_i = SQL_ReadResult(Query, 8);
	num_to_str(Seen_i, Seen, charsmax(Seen));
	SQL_ReadResult(Query, 9, seenString, charsmax(seenString));
	SQL_ReadResult(Query, 10, kpdRatio_f);
	float_to_str(kpdRatio_f, kpdRatio, charsmax(kpdRatio));
	kmdValue_i = SQL_ReadResult(Query, 11);
	num_to_str(kmdValue_i, kmdValue, charsmax(kmdValue));

	SQL_FreeHandle(Query);

	set_string(2, Steam, charsmax(Steam));
	set_string(3, Ip, charsmax(Ip));
	set_string(4, Score, charsmax(Score));
	set_string(5, Kills, charsmax(Kills));
	set_string(6, Deaths, charsmax(Deaths));
	set_string(7, headShots, charsmax(headShots));
	set_string(8, Time, charsmax(Time));
	set_string(9, timeString, charsmax(timeString));
	set_string(10, Seen, charsmax(Seen));
	set_string(11, seenString, charsmax(seenString));
	set_string(12, kpdRatio, charsmax(kpdRatio));
	set_string(13, kmdValue, charsmax(kmdValue));

	formatex(g_Query, charsmax(g_Query), "SELECT DISTINCT kmdValue FROM Players \
		WHERE kmdValue >= %d ORDER BY kmdValue ASC;", kmdValue_i);

	Query = SQL_PrepareQuery(Connection, g_Query);
	SQL_Execute(Query);

	Rank_i = SQL_NumResults(Query);
	num_to_str(Rank_i, Rank, charsmax(Rank));

	SQL_FreeHandle(Query);
	SQL_FreeHandle(Connection);

	set_string(14, Rank, charsmax(Rank));

	num_to_str(g_recordsCount, totalPositions, charsmax(totalPositions));
	set_string(15, totalPositions, charsmax(totalPositions));

	return 1;
}

public plugin_init()
{
	get_modname(g_modName, charsmax(g_modName));

	if (!equali(g_modName, "CStrike") && !equali(g_modName, "CZero"))
	{
		log_to_file(Errors_File, "get_modname() failed @ plugin_init() \
			:  This game mod is not supported.");

		return set_fail_state("get_modname() failed @ plugin_init() \
			:  This game mod is not supported.");
	}

	register_plugin(Plugin_Name, Plugin_Version, Plugin_Author);

	register_event("DeathMsg", "OnDeathMsg", "a");

	g_Tuple = SQL_MakeDbTuple(SQL_Server, SQL_Person, SQL_Password, SQL_Database);

	if (g_Tuple == Empty_Handle)
	{
		g_Tuple = SQL_MakeDbTuple(SQL_Server, SQL_Person, SQL_Password, SQL_Database);

		if (g_Tuple == Empty_Handle)
		{
			log_to_file(Errors_File, "SQL_MakeDbTuple() failed @ plugin_init()");

			return set_fail_state("SQL_MakeDbTuple() failed @ plugin_init()");
		}
	}

	/**
	* -----------------------------------------------------
	* Players
	* -----------------------------------------------------
	* Name
	* Steam
	* Ip
	* Score
	* Kills
	* Deaths
	* headShots
	* Time			- The time spent in minutes.
	* timeString	- Formatted as a string.
	* Seen			- get_systime() stamp.
	* seenString	- get_systime() stamp formatted as a time string including date.
	* kpdRatio		- Kills/ Deaths ratio.
	* kmdValue		- Kills - Deaths value.
	*/
	SQL_ThreadQuery(g_Tuple, "emptyFunction", "CREATE TABLE IF NOT EXISTS Players \
		(Name TEXT, Steam TEXT, Ip TEXT, Score NUMERIC, Kills NUMERIC, Deaths NUMERIC, \
		headShots NUMERIC, Time NUMERIC, timeString TEXT, Seen NUMERIC, seenString TEXT, kpdRatio FLOAT, \
		kmdValue NUMERIC);");

	SQL_ThreadQuery(g_Tuple, "recordsCount", "SELECT Kills FROM Players");

	g_maxPlayers = get_maxplayers();

	g_sayText = get_user_msgid("SayText");

	return PLUGIN_CONTINUE;
}

public recordsCount(failState, Handle:Query, Error[], errorId, Data[], dataSize, Float:queueTime)
{
	if (failState != 0 || errorId != 0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() failed @ recordsCount()");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);
	}

	else if (queueTime > 15.0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() @ recordsCount() :  This query took 15.0 seconds. \
			Talk to the game host company tell them the MySQL database works too slow.");
	}

	g_recordsCount = SQL_NumResults(Query);
}

public client_command(Client)
{
	static Command[32] = { 0, ... }, Argument[32] = { 0, ... }, \
		queryData[32] = { 0, ... };

	if (is_user_connected(Client) && !is_user_bot(Client) && !is_user_hltv(Client))
	{
		read_argv(0, Command, charsmax(Command));
		read_argv(1, Argument, charsmax(Argument));

		if (equali(Command, "Say", 3))
		{
			if (equali(Argument, "Rank", 4) || equali(Argument, "/Rank", 5))
			{
				num_to_str(Client, queryData, charsmax(queryData));

				formatex(g_Query, charsmax(g_Query), "SELECT DISTINCT kmdValue \
					FROM Players WHERE kmdValue >= %d ORDER BY kmdValue ASC;", g_kmdValue[Client]);

				SQL_ThreadQuery(g_Tuple, "printRankChat", g_Query, queryData, sizeof(queryData));
			}

			else if (equali(Argument, "Top", 3) || equali(Argument, "/Top", 4))
			{

			}

			else if (equali(Argument, "Time", 4) || equali(Argument, "/Time", 5))
			{
				coloredMessage(0, "\x03%s\x01 has spent\x04 %s\x01 on this server.", g_Name[Client], g_timeString[Client]);
			}
		}
	}
}

public emptyFunction(failState, Handle:Query, Error[], errorId, Data[], dataSize, Float:queueTime)
{
	if (failState != 0 || errorId != 0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() failed @ emptyFunction()");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);
	}

	else if (queueTime > 15.0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() @ emptyFunction() :  This query took 15.0 seconds. \
			Talk to the game host company tell them the MySQL database works too slow.");
	}

	/**
	* Query is now executed.
	*/
}

public OnDeathMsg()
{
	/**
	* -----------------------------------------------------
	* Players
	* -----------------------------------------------------
	* Name
	* Steam
	* Ip
	* Score
	* Kills
	* Deaths
	* headShots
	* Time			- The time spent in minutes.
	* timeString	- Formatted as a string.
	* Seen			- get_systime() stamp.
	* seenString	- get_systime() stamp formatted as a time string including date.
	* kpdRatio		- Kills/ Deaths ratio.
	* kmdValue		- Kills - Deaths value.
	*/

	static Killer = 0, Victim = 0, bool:headShot = false, Weapon[64] = { 0, ... }, \
		victimIp[64] = { 0, ... }, killerIp[64] = { 0, ... }, timeNow = 0, bool:killerValid = false, \
		bool:victimValid = false, bool:victimBOT = false, bool:killerBOT = false;
	//lcheck();

	Killer = read_data(1);
	Victim = read_data(2);
	headShot = bool:read_data(3);
	read_data(4, Weapon, charsmax(Weapon));
	ucfirst(Weapon);
	timeNow = get_systime();
	killerValid = isValidPlayer(Killer);
	victimValid = isValidPlayer(Victim);
	killerBOT = killerValid && is_user_bot(Killer) ? true : false;
	victimBOT = victimValid && is_user_bot(Victim) ? true : false;

	/**
	* Committed suicide with weapon, Killer is valid.
	*/
	if (Killer == Victim && killerValid && !killerBOT)
	{
		get_user_ip(Victim, victimIp, charsmax(victimIp), 1 /** No port. */);

		g_Deaths[Victim]++;
		g_Seen[Victim] = timeNow;
		format_time(g_seenString[Victim], charsmax(g_seenString[]), Date_Format);
		formatex(g_Ip[Victim], charsmax(g_Ip), "%s", victimIp);
		g_Score[Victim] -= Score_For_Suicide;
		g_kpdRatio[Victim] = computeKpdRatio(Victim);
		g_kmdValue[Victim] = computeKmdValue(Victim);

		updateRank(Victim);

#if Chat_Message_For_Victim == 1 || Chat_Message_For_Killer == 1
		coloredMessage(Victim, "You committed suicide by\x03 %s\x01.", Weapon);
#endif
	}

	/**
	* Committed suicide by world, Killer is not a player.
	*/
	else if (victimValid && !victimBOT && !killerBOT && \
		(!killerValid || equali(Weapon, "World", 5 /** May be "WorldSpawn". */)))
	{
		get_user_ip(Victim, victimIp, charsmax(victimIp), 1 /** No port. */);

		g_Deaths[Victim]++;
		g_Seen[Victim] = timeNow;
		format_time(g_seenString[Victim], charsmax(g_seenString[]), Date_Format);
		formatex(g_Ip[Victim], charsmax(g_Ip), "%s", victimIp);
		g_Score[Victim] -= Score_For_Suicide;
		g_kpdRatio[Victim] = computeKpdRatio(Victim);
		g_kmdValue[Victim] = computeKmdValue(Victim);

		updateRank(Victim);

#if Chat_Message_For_Victim == 1 || Chat_Message_For_Killer == 1
		coloredMessage(Victim, "You committed suicide by\x03 %s\x01.", Weapon);
#endif
	}

	/**
	* Normal kill.
	*/
	else if (killerValid && victimValid && !killerBOT && !victimBOT)
	{
		get_user_ip(Victim, victimIp, charsmax(victimIp), 1 /** No port. */);
		get_user_ip(Killer, killerIp, charsmax(killerIp), 1 /** No port. */);

		g_Deaths[Victim]++;
		g_Kills[Killer]++;

		if (headShot)
		{
			g_headShots[Killer]++;

			g_Score[Killer] += Score_For_Head_Shot;
		}

		else
		{
			g_Score[Killer] += Score_For_Kill;
		}

		g_Seen[Victim] = timeNow;
		g_Seen[Killer] = timeNow;
		format_time(g_seenString[Victim], charsmax(g_seenString[]), Date_Format);
		format_time(g_seenString[Killer], charsmax(g_seenString[]), Date_Format);
		formatex(g_Ip[Victim], charsmax(g_Ip), "%s", victimIp);
		formatex(g_Ip[Killer], charsmax(g_Ip), "%s", killerIp);
		g_Score[Victim] -= Score_For_Death;
		g_kpdRatio[Victim] = computeKpdRatio(Victim);
		g_kpdRatio[Killer] = computeKpdRatio(Killer);
		g_kmdValue[Victim] = computeKmdValue(Victim);
		g_kmdValue[Killer] = computeKmdValue(Killer);

		updateRank(Victim);
		updateRank(Killer);

#if Chat_Message_For_Victim == 1
		coloredMessage(Victim, "\x03%s\x01 killed you with\x04 %s\x01. They have now\x03 %d\x01 HP.", \
			g_Name[Killer], Weapon, get_user_health(Killer));
#endif

#if Chat_Message_For_Killer == 1
		coloredMessage(Killer, "You killed\x03 %s\x01 with\x04 %s\x01.", g_Name[Victim], Weapon);
#endif
	}
}

public client_disconnect(Client)
{
	if (isValidPlayer(Client) && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		resetPlayer(Client);

		if (task_exists(Client + Task_Update_Time))
		{
			remove_task(Client + Task_Update_Time);
		}
	}
}

public client_putinserver(Client)
{
	static queryData[32] = { 0, ... };

	if (isValidPlayer(Client) && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		resetPlayer(Client);

		num_to_str(Client, queryData, charsmax(queryData));

		get_user_name(Client, g_Name[Client], charsmax(g_Name[]));
		replace_all(g_Name[Client], charsmax(g_Name[]), "`", "*");
		replace_all(g_Name[Client], charsmax(g_Name[]), "'", "*");
		replace_all(g_Name[Client], charsmax(g_Name[]), "\"", "*");

		get_user_authid(Client, g_Steam[Client], charsmax(g_Steam[]));
		get_user_ip(Client, g_Ip[Client], charsmax(g_Ip[]), 1);

		/**
		* -----------------------------------------------------
		* Players
		* -----------------------------------------------------
		* Name
		* Steam
		* Ip
		* Score
		* Kills
		* Deaths
		* headShots
		* Time			- The time spent in minutes.
		* timeString	- Formatted as a string.
		* Seen			- get_systime() stamp.
		* seenString	- get_systime() stamp formatted as a time string including date.
		* kpdRatio		- Kills/ Deaths ratio.
		* kmdValue		- Kills - Deaths value.
		*/
		formatex(g_Query, charsmax(g_Query), "SELECT Score, Kills, Deaths, headShots, Time, timeString, \
			Seen, seenString, kpdRatio, kmdValue FROM Players WHERE Name = '%s';", g_Name[Client]);

		SQL_ThreadQuery(g_Tuple, "retrieveOrCreatePlayer", g_Query, queryData, sizeof(queryData));
	}
}

public retrieveOrCreatePlayer(failState, Handle:Query, Error[], errorId, Data[], dataSize, Float:queueTime)
{
	static Client = 0;

	if (failState != 0 || errorId != 0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() failed @ retrieveOrCreatePlayer()");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);
	}

	else if (queueTime > 15.0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() @ retrieveOrCreatePlayer() :  This query took 15.0 seconds. \
			Talk to the game host company tell them the MySQL database works too slow.");
	}

	Client = str_to_num(Data);

	if (is_user_connected(Client) == 1 && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		resetPlayer(Client);

		/**
		* -----------------------------------------------------
		* Players
		* -----------------------------------------------------
		* Name
		* Steam
		* Ip
		* Score
		* Kills
		* Deaths
		* headShots
		* Time			- The time spent in minutes.
		* timeString	- formatted time spent
		* Seen			- get_systime() stamp
		* seenString	- get_systime() stamp formatted as time string
		* kpdRatio		- Kills/ Deaths ratio
		* kmdValue		- Kills - Deaths value
		*/

		switch (SQL_NumResults(Query))
		{
			case 0:
			{
				formatex(g_Query, charsmax(g_Query), "INSERT INTO Players VALUES ('%s', \
					'%s', '%s', %d, %d, %d, %d, %d, '%s', %d, '%s', %f, %d);", g_Name[Client], \
					g_Steam[Client], g_Ip[Client], g_Score[Client], g_Kills[Client], \
					g_Deaths[Client], g_headShots[Client], g_Time[Client], g_timeString[Client], g_Seen[Client], \
					g_seenString[Client], g_kpdRatio[Client], g_kmdValue[Client]);

				SQL_ThreadQuery(g_Tuple, "emptyFunction", g_Query);

				g_recordsCount++;
			}

			default:
			{
				g_Score[Client] = SQL_ReadResult(Query, 0);
				g_Kills[Client] = SQL_ReadResult(Query, 1);
				g_Deaths[Client] = SQL_ReadResult(Query, 2);
				g_headShots[Client] = SQL_ReadResult(Query, 3);
				g_Time[Client] = SQL_ReadResult(Query, 4);
				SQL_ReadResult(Query, 5, g_timeString[Client], charsmax(g_timeString[]));
				g_Seen[Client] = SQL_ReadResult(Query, 6);
				SQL_ReadResult(Query, 7, g_seenString[Client], charsmax(g_seenString[]));
				SQL_ReadResult(Query, 8, g_kpdRatio[Client]);
				g_kmdValue[Client] = SQL_ReadResult(Query, 9);
			}
		}

		set_task(5.0, "rankPrepared", Client);
		set_task(120.0, "timeUpdate", Client + Task_Update_Time, .flags = "b"); /** Every 2 minutes. */
	}
}

public timeUpdate(Id)
{
	if (is_user_connected(Task_Id_Update_Time) && \
		!is_user_bot(Task_Id_Update_Time) && !is_user_hltv(Task_Id_Update_Time))
	{
		g_Time[Task_Id_Update_Time] += 2; /** 2 minutes. */

		computeTimeLength(g_Time[Task_Id_Update_Time], \
			timeUnit_Minutes, g_timeString[Task_Id_Update_Time], charsmax(g_timeString[]));

		formatex(g_Query, charsmax(g_Query), \
			"UPDATE Players SET Time = %d, timeString = '%s' WHERE Name = '%s';", \
			g_Time[Task_Id_Update_Time], g_timeString[Task_Id_Update_Time], g_Name[Task_Id_Update_Time]);

		SQL_ThreadQuery(g_Tuple, "emptyFunction", g_Query);
	}
}

public client_infochanged(Client)
{
	static Name[64] = { 0, ... }, queryData[32] = { 0, ... }, \
		Float:finalChange[33] = { 0.0, ... }, Float:gameTime = 0.0;

	if (is_user_connected(Client) == 1 && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		get_user_info(Client, "name", Name, charsmax(Name));

		replace_all(Name, charsmax(Name), "`", "*");
		replace_all(Name, charsmax(Name), "'", "*");
		replace_all(Name, charsmax(Name), "\"", "*");

		if (equali(Name, g_Name[Client]) == 0)
		{
			resetPlayer(Client);

			gameTime = get_gametime();

			if (gameTime < finalChange[Client])
			{
				server_cmd("kick #%d  %s", get_user_userid(Client), Name_Kick_Reason);
			}

			else
			{
				finalChange[Client] = gameTime + Name_Change_Interval;

				num_to_str(Client, queryData, charsmax(queryData));

				formatex(g_Name[Client], charsmax(g_Name[]), "%s", Name);

				get_user_authid(Client, g_Steam[Client], charsmax(g_Steam[]));
				get_user_ip(Client, g_Ip[Client], charsmax(g_Ip[]), 1);

				/**
				* -----------------------------------------------------
				* Players
				* -----------------------------------------------------
				* Name
				* Steam
				* Ip
				* Score
				* Kills
				* Deaths
				* headShots
				* Time			- The time spent in minutes.
				* timeString	- formatted time spent
				* Seen			- get_systime() stamp
				* seenString	- get_systime() stamp formatted as time string
				* kpdRatio		- Kills/ Deaths ratio
				* kmdValue		- Kills - Deaths value
				*/
				formatex(g_Query, charsmax(g_Query), "SELECT Score, Kills, Deaths, headShots, \
					Time, timeString, Seen, seenString, kpdRatio, kmdValue FROM Players WHERE Name = '%s';", \
					g_Name[Client]);

				SQL_ThreadQuery(g_Tuple, "retrieveOrCreatePlayer", g_Query, queryData, sizeof(queryData));
			}
		}
	}
}

public rankPrepared(Client)
{
	static queryData[32] = { 0, ... };

	if (is_user_connected(Client) == 1 && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		prepareDHudMessage(0, 255, 0, 0.03, 0.60, 2, 6.0, 3.0);
		sendDHudMessage(Client, "You are now ranked!");

		num_to_str(Client, queryData, charsmax(queryData));

		formatex(g_Query, charsmax(g_Query), "SELECT DISTINCT kmdValue \
			FROM Players WHERE kmdValue >= %d ORDER BY kmdValue ASC;", g_kmdValue[Client]);

		SQL_ThreadQuery(g_Tuple, "showRank", g_Query, queryData, sizeof(queryData));
	}
}

public showRank(failState, Handle:Query, Error[], errorId, Data[], dataSize, Float:queueTime)
{
	static Client = 0, Rank = 0, rankString[16], recordsString[16], scoreString[16], \
		killsString[16], deathsString[16], headShotsString[16];

	if (failState != 0 || errorId != 0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() failed @ showRank()");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);
	}

	else if (queueTime > 15.0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() @ showRank() :  This query took 15.0 seconds. \
			Talk to the game host company tell them the MySQL database works too slow.");
	}

	Client = str_to_num(Data);

	if (is_user_connected(Client) == 1 && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		Rank = SQL_NumResults(Query);

		addCommas(Rank, rankString, charsmax(rankString));
		addCommas(g_recordsCount, recordsString, charsmax(recordsString));
		addCommas(g_Kills[Client], killsString, charsmax(killsString));
		addCommas(g_Deaths[Client], deathsString, charsmax(deathsString));
		addCommas(g_Score[Client], scoreString, charsmax(scoreString));
		addCommas(g_headShots[Client], headShotsString, charsmax(headShotsString));

		prepareDHudMessage(0, 255, 0, 0.03, 0.25, 2, 6.0, 6.0);
		sendDHudMessage(Client, "Welcome, %s\n\
			Rank: %s out of %s  Score: %s\n\
			Kills: %s  Deaths: %s  KpD: %.2f\n\
			Online: %s\n\
			Enjoy!", \
			g_Name[Client], rankString, recordsString, scoreString, \
			killsString, deathsString, g_kpdRatio[Client], g_timeString[Client]);

		coloredMessage(Client, "Welcome,\x03 %s\x01. Your rank is\x04 %s\x01 out of\x04 %s\x01.", \
			g_Name[Client], rankString, recordsString);

#if Chat_Detailed_Rank == 1
		coloredMessage(Client, "You got\x03 %s\x01 kills,\x03 %s\x01 deaths,\x03 %s\x01 headshots and your KPD is\x04 %.2f\x01.", \
			killsString, deathsString, headShotsString, g_kpdRatio[Client]);
#endif
	}
}

public printRankChat(failState, Handle:Query, Error[], errorId, Data[], dataSize, Float:queueTime)
{
	static Client = 0, Rank = 0, rankString[16], recordsString[16], scoreString[16], \
		killsString[16], deathsString[16], headShotsString[16];

	if (failState != 0 || errorId != 0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() failed @ printRankChat()");
		log_to_file(Errors_File, "[%d] %s", errorId, Error);
	}

	else if (queueTime > 15.0)
	{
		log_to_file(Errors_File, "SQL_ThreadQuery() @ printRankChat() :  This query took 15.0 seconds. \
			Talk to the game host company tell them the MySQL database works too slow.");
	}

	Client = str_to_num(Data);

	if (is_user_connected(Client) == 1 && is_user_bot(Client) == 0 && is_user_hltv(Client) == 0)
	{
		Rank = SQL_NumResults(Query);

		addCommas(Rank, rankString, charsmax(rankString));
		addCommas(g_recordsCount, recordsString, charsmax(recordsString));
		addCommas(g_Kills[Client], killsString, charsmax(killsString));
		addCommas(g_Deaths[Client], deathsString, charsmax(deathsString));
		addCommas(g_Score[Client], scoreString, charsmax(scoreString));
		addCommas(g_headShots[Client], headShotsString, charsmax(headShotsString));

		coloredMessage(0, "\x03%s\x01's rank is\x04 %s\x01 out of\x04 %s\x01.", \
			g_Name[Client], rankString, recordsString);

#if Chat_Detailed_Rank == 1
		coloredMessage(0, "They got\x03 %s\x01 kills,\x03 %s\x01 deaths,\x03 %s\x01 headshots and their KPD is\x04 %.2f\x01.", \
			killsString, deathsString, headShotsString, g_kpdRatio[Client]);
#endif
	}
}
User avatar
Laurentiu P.
Super moderator
Super moderator
Posts: 2095
Joined: 10 Jul 2013, 20:26
Detinator Steam: Da
CS Status: Activitate scazuta !
Detinator server CS: Da
SteamID: trust_ro
Reputatie: Moderator > Super moderator
Nume anterior: Do[N]e ;3
Fond eXtream: 1
Location: Constanta
Has thanked: 4 times
Been thanked: 3 times

23 Jun 2018, 22:35

Asta spune tot
#include sqlx
Image
ImparctVirtual
Membru, skill 0
Membru, skill 0
Posts: 62
Joined: 21 Jun 2018, 02:41
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

24 Jun 2018, 07:58

pai uite cum sta treaba eu am luat pluginul dintr-un addons de ZP 6.3 care este aici pe EXtreamCs
si am gasit doar #include sqlx.inc

nu mi-se salveaza orele jucate.
User avatar
Laurentiu P.
Super moderator
Super moderator
Posts: 2095
Joined: 10 Jul 2013, 20:26
Detinator Steam: Da
CS Status: Activitate scazuta !
Detinator server CS: Da
SteamID: trust_ro
Reputatie: Moderator > Super moderator
Nume anterior: Do[N]e ;3
Fond eXtream: 1
Location: Constanta
Has thanked: 4 times
Been thanked: 3 times

25 Jun 2018, 07:06

Nu a baza de date creata, plus nu le ai trecute nici in sursa

Code: Select all

#define SQL_Server ""
#define SQL_Person ""
#define SQL_Password ""
#define SQL_Database "StatsDb"
Image
User avatar
Laurentiu P.
Super moderator
Super moderator
Posts: 2095
Joined: 10 Jul 2013, 20:26
Detinator Steam: Da
CS Status: Activitate scazuta !
Detinator server CS: Da
SteamID: trust_ro
Reputatie: Moderator > Super moderator
Nume anterior: Do[N]e ;3
Fond eXtream: 1
Location: Constanta
Has thanked: 4 times
Been thanked: 3 times

25 Jun 2018, 07:06

Nu a baza de date creata, plus nu le ai trecute nici in sursa

Code: Select all

#define SQL_Server ""
#define SQL_Person ""
#define SQL_Password ""
#define SQL_Database "StatsDb"
Image
ImparctVirtual
Membru, skill 0
Membru, skill 0
Posts: 62
Joined: 21 Jun 2018, 02:41
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Contact:

25 Jun 2018, 14:16

rezolvat Cer T/C
Post Reply

Return to “Probleme in jocul Counter-Strike”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests