SA-MP Forums Archive
Problem in SQLite.... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem in SQLite.... (/showthread.php?tid=437777)



Problem in SQLite.... - electrux - 17.05.2013

OK... so i have a problem again.
This code:-

Код:
new DBResult:res,str1[3];
format(query,sizeof(query),"SELECT * FROM `USERS` WHERE `Name` = '%s' AND `Password` = '%s'",DB_Escape(name),DB_Escape(hashpass));
	res = db_query(users,query);
	if(db_num_rows(res))
	{
		db_get_field_assoc(res,"Level",str1,3);
                pinfo[playerid][level] = strval(str1);
        }
It aint a problem in aompiling but it gives problem at runtime... i printed
Код:
pinfo[playerid][level]
. It just has random values in it. what is wrong? :-/


Re: Problem in SQLite.... - Scrillex - 17.05.2013

Umm maybe show how you define level! Not saving...


Re: Problem in SQLite.... - electrux - 17.05.2013

Код:
enum info
{
level
}
new pinfo[MAX_PLAYERS][info];



Re: Problem in SQLite.... - Scrillex - 17.05.2013

Okay this is ok but when you are giving level up? Like level++


Re: Problem in SQLite.... - electrux - 17.05.2013

i didnt make that... i just printed the value of level on console... the values in level are random


Re: Problem in SQLite.... - Scrillex - 17.05.2013

Did you saved it like 0? playerinfo or what was your thing there PlayerInfo[playerid][level] = 0;


Re: Problem in SQLite.... - electrux - 17.05.2013

here is the register and login thing...

Код:
stock RegisterPlayer(playerid, password[])
{
	new query[500],name[50],Float:x,Float:y,Float:z,rand,hashpass[200];
 	WP_Hash(hashpass,sizeof(hashpass),password);
	GetPlayerName(playerid,name,sizeof(name));
	rand = randomEx(1000,9999);
	GetPlayerPos(playerid,x,y,z);
    format(query,sizeof(query),"INSERT INTO `USERS`(`Name`,`Password`,`LoggedIn`,`Level`,`Admin`,`VIP`,`Money`,`Score`,`Death`,`Number`) VALUES('%s','%s','1','0','0','0','30000','0','0','%d')",DB_Escape(name),DB_Escape(hashpass),rand);
    db_query(users,query);
	pinfo[playerid][level] = 0;
    pinfo[playerid][admin] = 0;
    pinfo[playerid][vip] = 0;
    pinfo[playerid][money] = 30000;
    pinfo[playerid][score] = 0;
    pinfo[playerid][death] = 0;
    pinfo[playerid][number] = rand;
    SendClientMessage(playerid,-1,"Succesfully Registered! ENJOY!!");
    SetTimerEx("Refresh", 5000, true, "i", playerid);
	return 1;
}

stock LoginPlayer(playerid, password[])
{
    new query[500],name[50],hashpass[200],DBResult:res,str1[3],str2[3],str3[3],str4[3],str5[3],str6[3],str7[3];
    WP_Hash(hashpass,sizeof(hashpass),password);
	GetPlayerName(playerid,name,sizeof(name));
	format(query,sizeof(query),"UPDATE `USERS` SET `LoggedIn` = '1' WHERE `Name` = '%s'",DB_Escape(name),DB_Escape(hashpass));
	db_query(users,query);
	format(query,sizeof(query),"SELECT * FROM `USERS` WHERE `Name` = '%s' AND `Password` = '%s'",DB_Escape(name),DB_Escape(hashpass));
	res = db_query(users,query);
	if(db_num_rows(res))
	{
		db_get_field_assoc(res,"Level",str1,3);
		db_get_field_assoc(res,"Admin",str2,3);
		db_get_field_assoc(res,"VIP",str3,3);
		db_get_field_assoc(res,"Money",str4,9);
		db_get_field_assoc(res,"Score",str5,3);
		db_get_field_assoc(res,"Death",str6,3);
		db_get_field_assoc(res,"Number",str7,3);
		pinfo[playerid][level] = strval(str1);
		pinfo[playerid][admin] = strval(str2);
		pinfo[playerid][vip] = strval(str3);
		pinfo[playerid][money] = strval(str4);
		pinfo[playerid][score] = strval(str5);
		pinfo[playerid][death] = strval(str6);
		pinfo[playerid][number] = strval(str7);
		printf("///////////LOGIN//////////");
        printf("%d",pinfo[playerid][admin]);
	    printf("%d",pinfo[playerid][vip]);
	    printf("%d",pinfo[playerid][money]);
	    printf("%d",pinfo[playerid][score]);
		SetPlayerMoney(playerid,pinfo[playerid][money]);
		SetPlayerScore(playerid,pinfo[playerid][score]);
		SendClientFormattedMessage(playerid,-1,"Successfully logged in!");
	}
	else
	{
		SendClientMessage(playerid,-1,"Incorrect password! Please retry!!");
		ShowPlayerDialog(playerid,LOGINDIALOG, DIALOG_STYLE_PASSWORD, "Login", "Enter your password below:", "Login!", "Kick!");
	}
	db_free_result(res);
	SetTimerEx("Refresh", 5000, true, "i", playerid);
	return 1;
}



Re: Problem in SQLite.... - Scrillex - 17.05.2013

it could maybe mix with that rand! Btw how much value is in there? (like how much numbers)


Re: Problem in SQLite.... - electrux - 17.05.2013

at registration its all proper... when i login, it jst goes crazy and somehow gets random numbers. all fields have same random number


Re: Problem in SQLite.... - Scrillex - 17.05.2013

You see what I think is that str7,3 == the same as str1,3 and could be in trouble... Thats my thought... And it could maybe do the same effect... To loging in... Or maybe somewhere else it is set up as rand level!