SA-MP Forums Archive
Saving Score. - 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: Saving Score. (/showthread.php?tid=522280)



Saving Score. - Ghazal - 26.06.2014

Hello,

So i am trying to save the score,

Well thats what i did

Code:
enum E_PLAYERS
{
	ID,
	Name[MAX_PLAYER_NAME],
	Password[129],
	Money,
	Score,
	eHumans,
	eZombies,
	bool:IsLoggedIn,
	bool:IsRegistered,
	LoginAttempts,
	LoginTimer
};
Code:
public OnPlayerSpawn(playerid)
{
	SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
return 1;
}
Code:
AssignPlayerData(playerid)
{
	PlayerInfo[playerid][ID] = cache_get_field_content_int(0, "id");
	cache_get_field_content(0, "password", PlayerInfo[playerid][Password], g_SQL, 129);
	PlayerInfo[playerid][Money] = cache_get_field_content_int(0, "money");
	PlayerInfo[playerid][Score] = cache_get_field_content_int(0, "score");
	return 1;
}
Code:
UpdatePlayerData(playerid)
{
	if(PlayerInfo[playerid][IsLoggedIn] == false)
	    return 0;

	new query[128];
	mysql_format(g_SQL, query, sizeof(query), "UPDATE `players` SET `money` = '%d' SET `score` = '%d' WHERE `id` = '%d' LIMIT 1", PlayerInfo[playerid][Money],PlayerInfo[playerid][Score], PlayerInfo[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
Code:
SetupPlayerTable()
{
	mysql_query(g_SQL, "CREATE TABLE IF NOT EXISTS `players` (`id` int(11) NOT NULL auto_increment PRIMARY KEY,`username` varchar(30) NOT NULL,`password` varchar(130) NOT NULL,`money` int(10) NOT NULL default '0',`score` int(10) NOT NULL default '0')", false);
	return 1;
}
I also added this stock

Code:
stock Player_GiveScore(playerid,amount)
{
	PlayerInfo[playerid][Score] += amount;
	return 1;
}
And this timer
Code:
function MainTimer()
{
	foreach(Player, playerid)
	{
		ResetPlayerMoney(playerid);
		GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
		SetPlayerScore(playerid, PlayerInfo[playerid][Score]);
	}
}
And for sure
Code:
	SetTimer("MainTimer", 500, 1);
under ongamemodeinit

I also added a cmd so i can test,

Code:
CMD:ok(playerid,params[])
{
	Player_GiveScore(playerid,500);
	return 1;
}
But it sets my score, and after i logout My score resets.


Re : Saving Score. - Clad - 26.06.2014

pawn Code:
public OnPlayerDisconnect



Re: Re : Saving Score. - Ghazal - 26.06.2014

Quote:
Originally Posted by Clad
View Post
pawn Code:
public OnPlayerDisconnect
Code:
public OnPlayerDisconnect(playerid,reason)
{
    g_MysqlRaceCheck[playerid]++;
	UpdatePlayerData(playerid);
	return 1;
}
Code:
UpdatePlayerData(playerid)
{
	if(PlayerInfo[playerid][IsLoggedIn] == false)
	    return 0;

	new query[128];
	mysql_format(g_SQL, query, sizeof(query), "UPDATE `players` SET `money` = '%d' SET `score` = '%d' WHERE `id` = '%d' LIMIT 1", PlayerInfo[playerid][Money],PlayerInfo[playerid][Score], PlayerInfo[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}



Re: Saving Score. - Ghazal - 27.06.2014

bump


Re: Saving Score. - yvoms - 27.06.2014

pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    if(Logged[playerid] == 1)
    {
        new score = GetPlayerScore(playerid);
        new money = GetPlayerMoney(playerid);
        new query[300], pname[24]; new nquery[300];
        GetPlayerName(playerid, pname, 24);
        format(query, sizeof(query), "UPDATE `playerdata` SET score='%d', money='%d' WHERE user='%s'",
    mysql_query(query);
        }
    return 1;
}
Thats what i used, worked without any bugs.


Re: Saving Score. - BroZeus - 27.06.2014

huehue the problem is with PlayerInfo[playerid][IsLoggedIn]
you should set it to true OnPlayerSpawn
and to false OnPlayerDisconnect [ at last part of OnPlayerDisconnect just before return1;]


Re: Saving Score. - Ghazal - 28.06.2014

Non of them worked.


Re: Saving Score. - Ghazal - 28.06.2014

Bump.


Re: Saving Score. - Lordzy - 28.06.2014

Quote:
Originally Posted by yvoms
View Post
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    if(Logged[playerid] == 1)
    {
        new score = GetPlayerScore(playerid);
        new money = GetPlayerMoney(playerid);
        new query[300], pname[24]; new nquery[300];
        GetPlayerName(playerid, pname, 24);
        format(query, sizeof(query), "UPDATE `playerdata` SET score='%d', money='%d' WHERE user='%s'",
    mysql_query(query);
        }
    return 1;
}


Thats what i used, worked without any bugs.
You formatted the query, but you haven't inserted the values. Plus, there's a useless array.

OT :

You're having problems with your MySQL query. There have to be commas while updating each column. What the above user done is fine, except no insertion of values while formatting the query which makes things wrong.


Re: Saving Score. - Ghazal - 28.06.2014

BUMP


Re: Saving Score. - Ghazal - 29.06.2014

Bump.......


Re: Saving Score. - Ghazal - 29.06.2014

Bump :3


Re: Saving Score. - Ghazal - 29.06.2014

....


Re: Saving Score. - sammp - 29.06.2014

Stop bumping! Jesus you should be banned for this.