I have questions about mysql
#1

Im new to pawn so im trying to understand how to set up mysql data saves like level and exp system
most of the codes i will give wont be my code i will add //mycode to the lines i added

Код:
public regist(playerid, pass[]){

	format(USER[playerid][PASS],24, "%s",pass);

	new query[512];
	GetPlayerName(playerid, USER[playerid][NAME], MAX_PLAYER_NAME);
	mysql_format(mysql, query, sizeof(query), "INSERT INTO `userlog_info` (`NAME`,`PASS`,`ADMIN`,`MONEY`,`KILLS`,`DEATHS`,`SKIN`,`POS_X`,`POS_Y`,`POS_Z`,`ANGLE`,`HP`,`AM`, `LEVEL`) VALUES ('%s','%s',%d,%d,%d,%d,%d,%f,%f,%f,%f,%f,%f,%d)", USER[playerid][NAME], USER[playerid][PASS],
	USER[playerid][ADMIN] = 0,
	USER[playerid][MONEY] = 1000,
	USER[playerid][KILLS] = 0,
	USER[playerid][DEATHS] = 0,
	USER[playerid][SKIN] = 129,
	USER[playerid][POS_X] = 1925.0215,
 	USER[playerid][POS_Y] = -1684.2222,
	USER[playerid][POS_Z] = 13.5469,
	USER[playerid][ANGLE] = 255.7507,
	USER[playerid][HP] = 100.0,
	USER[playerid][AM] = 100.0,
	USER[playerid][EXP] = 0, //mycode doesnt save in the database
	USER[playerid][LEVEL] = 1); //mycode doesnt save in the database

	mysql_query(mysql, query);
	USER[playerid][ID] = cache_insert_id();

	SendClientMessage(playerid,-1,"You Have Successfully Registered.");
	INGAME[playerid][LOGIN] = true;
	spawn(playerid);
}

public save(playerid){
	GetPlayerPos(playerid,USER[playerid][POS_X],USER[playerid][POS_Y],USER[playerid][POS_Z]);
	GetPlayerFacingAngle(playerid, USER[playerid][ANGLE]);

	new query[256];
	mysql_format(mysql, query, sizeof(query), "UPDATE `userlog_info` SET `ADMIN`=%d,`MONEY`=%d,`KILLS`=%d,`DEATHS`=%d,`SKIN`=%d,`POS_X`=%f,`POS_Y`=%f,`POS_Z`=%f WHERE `NAME`=%d", USER[playerid][ADMIN], USER[playerid][MONEY], USER[playerid][KILLS], USER[playerid][DEATHS], USER[playerid][SKIN], USER[playerid][POS_X], USER[playerid][POS_Y], USER[playerid][POS_Z],playerid);
	mysql_query(mysql, query);
	mysql_format(mysql, query, sizeof(query), "UPDATE `userlog_info` SET `ANGLE`=%f,`HP`=%f,`AM`=%f WHERE `ID`=%d, `EXP`=%d, `LEVEL`=%d WHERE `NAME`=%d", USER[playerid][ANGLE], USER[playerid][HP], USER[playerid][AM], USER[playerid][ID], USER[playerid][EXP], USER[playerid][LEVEL],playerid);
	mysql_query(mysql, query);
}
Public save and the two lines in the public regist doesnt seem to work but however with same variables i can read them on this load code block(like if i set exp to 14 from a mysql client and login game game can fetch the level and exp properly) by the way otheer variables in public regist saves only last two lines doesnt save

Код:
public load(playerid){
	new query[128];
	mysql_format(mysql, query, sizeof(query), "SELECT * FROM `userlog_info` WHERE `ID` = %d LIMIT 1", USER[playerid][ID]);
	mysql_query(mysql, query);

	USER[playerid][ADMIN]   = cache_get_field_content_int(0, "ADMIN");
	USER[playerid][MONEY]   = cache_get_field_content_int(0, "MONEY");
	USER[playerid][KILLS]   = cache_get_field_content_int(0, "KILLS");
	USER[playerid][DEATHS]  = cache_get_field_content_int(0, "DEATHS");
	USER[playerid][SKIN]    = cache_get_field_content_int(0, "SKIN");
	USER[playerid][POS_X]   = cache_get_field_content_float(0, "POS_X");
	USER[playerid][POS_Y]   = cache_get_field_content_float(0, "POS_Y");
	USER[playerid][POS_Z]   = cache_get_field_content_float(0, "POS_Z");
	USER[playerid][ANGLE]   = cache_get_field_content_float(0, "ANGLE");
	USER[playerid][HP]      = cache_get_field_content_float(0, "HP");
	USER[playerid][AM]      = cache_get_field_content_float(0, "AM");
	USER[playerid][EXP]     = cache_get_field_content_int(0, "EXP");
	USER[playerid][LEVEL]   = cache_get_field_content_int(0, "LEVEL");
	spawn(playerid);
}
What am i doing wrong ?
Reply
#2

You should really consider scrolling through some forum tutorials before scripting with mysql and 'l' in mysql stands for LANGUAGE.

You didn't even place it right in the format, and that is a non-threaded query.
Reply
#3

apparently this dude who gave away the code did a mistake in save i just saw that my bad and this topic can be locked solved.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)