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

Save MySQL- vanishing point some players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 09-14-2016 , 11:07   Save MySQL- vanishing point some players
Reply With Quote #1

Hello,
Can someone tell me what is wrong in this code? The point here is that some players remove the points that have earned (not always, but sometimes, usually the next day disappear)
All records normally, but some players just disappear these points from time to time (the reset)

plugin_init
Code:
public plugin_init() {

	g_SqlTuple = SQL_MakeDbTuple("HOST","LOGIN","HASŁO","NAZWA_BAZY")
	
	if(g_SqlTuple == Empty_Handle)
		set_fail_state("Nie mozna utworzyc uchwytu do polaczenia.");
	
	new iErr, szError[32];
	new Handle:link = SQL_Connect(g_SqlTuple, iErr, szError, 31);
	if(link == Empty_Handle){
		log_amx("Error (%d): %s", iErr, szError);
		set_fail_state("Brak polaczenia z baza danych");
	}
	
	new Handle:query;	
	query = SQL_PrepareQuery(link,
	"CREATE TABLE IF NOT EXISTS `BBB` ( \
		`id` int(5) NOT NULL auto_increment, \
		`nick` varchar(36) NOT NULL, \
		`punkty` INT(11) NOT NULL  DEFAULT 0, \
		PRIMARY KEY  (`id`) \
	)");
	SQL_Execute(query);
	SQL_FreeHandle(query);
}
plugin_end
Code:
public plugin_end() SQL_FreeHandle(g_SqlTuple);
public client_putinserver
Code:
public client_putinserver(id) {
	player_points[id] = 0;		
	wczytane_dane[id] = false;
	get_user_name(id, gNick[id], 32);
	
	formatex(gQuery, charsmax(gQuery), "SELECT * FROM `BBB` WHERE `nick` = ^"%s^" ORDER BY `id` LIMIT 1", gNick[id]);
	new ids[1]; ids[0] = id;
	SQL_ThreadQuery(g_SqlTuple, "handleLoadData", gQuery, ids, 1);
}
public client_disconnect
Code:
public client_disconnect(id) {
	if(!wczytane_dane[id])
		return;
	
	formatex(gQuery, charsmax(gQuery), "UPDATE `BBB` SET `punkty` = %d WHERE `nick` = ^"%s^"", player_points[id], gNick[id]);
	SQL_ThreadQuery(g_SqlTuple, "handleStandard", gQuery);
	player_points[id] = 0;
}
Other
Code:
public handleLoadData(failstate, Handle:query, error[], errnum, data[], size){
	if(failstate != TQUERY_SUCCESS){
		log_amx("SQL Load error: %s",error);
		return;
	}
	
	new id = data[0];
	if(!is_user_connected(id)) return;
	
	if(SQL_MoreResults(query)) {
		player_points[id]		= SQL_ReadResult(query, 2);
	} else {		
		formatex(gQuery, charsmax(gQuery), "INSERT INTO `BBB` (`nick`) VALUES (^"%s^")", gNick[id]);
		SQL_ThreadQuery(g_SqlTuple, "handleStandard", gQuery);
	}
	wczytane_dane[id] = true;
}

public handleStandard(failstate, Handle:query, error[], errnum, data[], size) {
	if(failstate != TQUERY_SUCCESS) {
		log_amx("SQL Insert error: %s",error);
		return;
	}
}

Last edited by Qes; 09-14-2016 at 11:08.
Qes is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-14-2016 , 15:58   Re: Save MySQL- vanishing point some players
Reply With Quote #2

Scenario:
Player1 joins game and already has 500 points.
Player1 plays for 5 mins, earning 50 points to a total of 550 points.
Player1 leaves the server, everything is saved.
Now when this problem occurs, is he/she back to 500 or 0 points?

Saving by name will never be a good idea. I can't really see myself wasting time on this and you suddenly go "Oh, they just changed their names. Of course the data is wiped. lolz."
__________________
Black Rose is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 09-15-2016 , 08:19   Re: Save MySQL- vanishing point some players
Reply With Quote #3

When Player go back to server has 0 points
Qes is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-15-2016 , 08:23   Re: Save MySQL- vanishing point some players
Reply With Quote #4

That points even more to the non-steam issue. I'm sorry, I can't waste time on that.
__________________
Black Rose is offline
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 09-15-2016 , 08:27   Re: Save MySQL- vanishing point some players
Reply With Quote #5

PHP Code:
SELECT FROM `BBBWHERE `nick` = ^"%s^" 
Save and load by SteamID
__________________
gabuch2 is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 09-15-2016 , 11:11   Re: Save MySQL- vanishing point some players
Reply With Quote #6

Since when save informs us about the version of the game (Non-Steam/Steam)?

1. none of these people does not change nickname
2. these are the players STEAM

Thank you for your help : )

Last edited by Qes; 09-15-2016 at 11:12.
Qes is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-15-2016 , 11:46   Re: Save MySQL- vanishing point some players
Reply With Quote #7

Then save by steamid. The only moment when you need to save by name is when you run dproto, so saving method tells a lot.
__________________

Last edited by HamletEagle; 09-15-2016 at 11:46.
HamletEagle is offline
Qes
AlliedModders Donor
Join Date: Jul 2014
Old 09-15-2016 , 12:23   Re: Save MySQL- vanishing point some players
Reply With Quote #8

Okay, thanks for your help. I check and most let you know if something will not work
Qes is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:05.


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