Raised This Month: $32 Target: $400
 8% 

Achievements =/= codmod, database problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
supertimor
AlliedModders Donor
Join Date: Sep 2017
Old 09-05-2018 , 15:42   Achievements =/= codmod, database problem
Reply With Quote #1

Hello everyone.
At the beginning - sorry. English is not my native language.


Some time ago, i used achievements engine by MAGNET https://forums.alliedmods.net/showthread.php?t=310309
but i had problem with my classes in codmod.
Codmod is unfortunately written in polish language, but i'll send some code as you can check wtf is going here..

We edited code with MAGNET, and i will post it all here. We were going to get achievements available only with choosen class for flags (look at achievementsgo.inc).
Its working, okay - but.. with big-lag. After map change, it need 4-5 mins to load mysql database with codmod. Without AGO plugin and ago-changed-classes its like 1-2seconds after map change.
We already checked it on another IP, with another database, and it was much faster.

It should be on server :
Plugins(ago,codmod,others) -> codmod mysql connection -> get classes, levels etc -> ago register achievements

Already its like :
Plugins(ago,codmod failure database connection (other plugins which use the same mysql fail too) -> 4-5 mins -> codmod get access to mysql -> ago register achievements

mysql connection from codmod :

OnPluginStart -> DataBaseConnect();
Code:
public Action:DataBaseConnect()
{
	new String:error[128];
	sql = SQL_Connect("codmod_lvl_sql", true, error, sizeof(error));
	if(sql == INVALID_HANDLE)
	{
		LogError("Could not connect: %s", error);
		return Plugin_Continue;
	}

	new String:zapytanie[1024];
	Format(zapytanie, sizeof(zapytanie), "CREATE TABLE IF NOT EXISTS `%s` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `accountID` INT UNSIGNED NOT NULL, `klasa` VARCHAR(64) NOT NULL, `poziom` INT UNSIGNED NOT NULL DEFAULT 1, `doswiadczenie` INT UNSIGNED NOT NULL DEFAULT 1, UNIQUE KEY `accountID_klasa`(`accountID`, `klasa`), `inteligencja` INT UNSIGNED NOT NULL DEFAULT 0, `zdrowie` INT UNSIGNED NOT NULL DEFAULT 0, `obrazenia` INT UNSIGNED NOT NULL DEFAULT 0, `wytrzymalosc` INT UNSIGNED NOT NULL DEFAULT 0, `kondycja` INT UNSIGNED NOT NULL DEFAULT 0, `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)", TABELA);
	//StrCat(zapytanie, sizeof(zapytanie), "`inteligencja` INT UNSIGNED NOT NULL DEFAULT 0, `zdrowie` INT UNSIGNED NOT NULL DEFAULT 0, `obrazenia` INT UNSIGNED NOT NULL DEFAULT 0, `wytrzymalosc` INT UNSIGNED NOT NULL DEFAULT 0, `kondycja` INT UNSIGNED NOT NULL DEFAULT 0)");

	SQL_LockDatabase(sql);
	SQL_FastQuery(sql, zapytanie);
	SQL_UnlockDatabase(sql);

	return Plugin_Continue;
}
OnClientPutInServer -> WczytajDane(client);

Code:
public Action:WczytajDane(client)
{
	if(IsClientSourceTV(client))
		return Plugin_Continue;

	if(IsFakeClient(client))
	{
		wczytane_dane[client] = true; // WCZYTAJ_DANE = LOAD_DATA
		return Plugin_Continue;
	}

	int accountID =  GetSteamAccountID(client);

	new String:zapytanie[512];
	Format(zapytanie, sizeof(zapytanie), "SELECT `klasa`, `poziom`, `doswiadczenie`, `inteligencja`, `zdrowie`, `obrazenia`, `wytrzymalosc`, `kondycja` FROM %s WHERE accountID=%d;", TABELA, accountID);
	SQL_TQuery(sql, WczytajDane_Handler, zapytanie, client);

	return Plugin_Continue;
}
Code:
public WczytajDane_Handler(Handle:owner, Handle:query, const String:error[], any:client)
{
	if(query == INVALID_HANDLE)
	{
		LogError("Load error: %s", error);
		return;
	}
	if(SQL_GetRowCount(query))
	{
		new String:klasa[64];
		while(SQL_MoreRows(query))
		{
			while(SQL_FetchRow(query))
			{
				SQL_FetchString(query, 0, klasa, sizeof(klasa));
				for(new i = 1; i <= ilosc_klas; i ++)
				{
					if(!StrEqual(nazwy_klas[i], klasa))
						continue;

					lvl_klasy_gracza[client][i] = SQL_FetchInt(query, 1);
					xp_klasy_gracza[client][i] = SQL_FetchInt(query, 2);
					int_klasy_gracza[client][i] = SQL_FetchInt(query, 3);
					zdr_klasy_gracza[client][i] = SQL_FetchInt(query, 4);
					obr_klasy_gracza[client][i] = SQL_FetchInt(query, 5);
					wyt_klasy_gracza[client][i] = SQL_FetchInt(query, 6);
					kon_klasy_gracza[client][i] = SQL_FetchInt(query, 7);
					break;
				}
			}
		}
	}

	wczytane_dane[client] = true;
}
and thats it -
Code:
public Action:WybierzKlase(client, args)
{
	if (!IsValidClient(client)) return Plugin_Handled;
	if(wczytane_dane[client])
	{
		lvl_klasy_gracza[client][klasa_gracza[client]] = poziom_gracza[client];	
		xp_klasy_gracza[client][klasa_gracza[client]] = doswiadczenie_gracza[client];
		int_klasy_gracza[client][klasa_gracza[client]] = inteligencja_gracza[client];
		zdr_klasy_gracza[client][klasa_gracza[client]] = zdrowie_gracza[client];
		obr_klasy_gracza[client][klasa_gracza[client]] = obrazenia_gracza[client];
		wyt_klasy_gracza[client][klasa_gracza[client]] = wytrzymalosc_gracza[client];
		kon_klasy_gracza[client][klasa_gracza[client]] = kondycja_gracza[client];

		new String:menu_item[77];
		new Handle:menu = CreateMenu(WybierzKlase_Handler);
		SetMenuTitle(menu, "Wybierz klasę:");
		for(new i = 1; i <= ilosc_klas; i ++)
		{
			Format(menu_item, sizeof(menu_item), "%s (Lv: %i)\n    %s", nazwy_klas[i], lvl_klasy_gracza[client][i], opisy_klas[i]);
			AddMenuItem(menu, "", menu_item);
		}
		SetMenuExitButton(menu, true);
		DisplayMenu(menu, client, 250);
	}
	else
		PrintToChat(client, "%s Trwa wczytywanie Twoich danych!", PREFIX);

	return Plugin_Handled;
}
wybierz klase - choose class, else at the bottom is when database is not loaded so printtochat - "Still loading your data"


scripting.zip is all files from edited ago in english language so it will be easy

Codmod - mysql
Ago - sqlite

Please, if someone will help me, i'll be grateful a lot.. we don't know explanation.
If i can send you some more code, just ask - i don't know what i should attach more at the moment.
And - sorry once more for my sick language skill


// errors for every plugin using same mysql database are similiar like :
L 09/05/2018 - 19:519: [jb_ip.smx] Last Connect SQL Error: Lost connection to MySQL server during query
L 09/05/2018 - 19:51:41: [SM] Exception reported: Invalid database Handle 0 (error: 4)
L 09/05/2018 - 19:51:41: [SM] Blaming: cod/codmod_nowy_cod.smx
L 09/05/2018 - 19:51:41: [SM] Call stack trace:
L 09/05/2018 - 19:51:41: [SM] [0] SQL_TQuery
L 09/05/2018 - 19:51:41: [SM] [1] Line 1375, cod\codmod_nowy_cod.sp::WczytajDane
L 09/05/2018 - 19:51:41: [SM] [2] Line 298, cod\codmod_nowy_cod.sp::OnClientPutInServer
Attached Files
File Type: zip scripting.zip (13.1 KB, 64 views)

Last edited by supertimor; 09-05-2018 at 15:44.
supertimor is offline
supertimor
AlliedModders Donor
Join Date: Sep 2017
Old 09-07-2018 , 14:49   Re: Achievements =/= codmod, database problem
Reply With Quote #2

Please guys.. problem is propably located on achievements engine, hope someone will help us
supertimor 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 02:14.


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