Mysql loading and saving
#1

My gamemode is loading everything fine except the positions.
When I register it inserts the player position fine. But it wont update the position when the player gets saved.
And then doesnt load it again when I login

Could someone help me please?
Thanks

Код:
case DIALOG_REGISTER:
	    {
	        if(response)
	        {
	            if(response)
	            {
	                new query[250], pName[MAX_PLAYER_NAME];
	            	GetPlayerName(playerid, pName, sizeof(pName));

	            	format(query, sizeof(query), "INSERT INTO playerdata (Name, Password, PlayerPos) VALUES ('%s', '%s', '1757.1228 -1867.2832 13.5704')", pName, inputtext);
	            	mysql_query(query);

	            	SendClientMessage(playerid, -1, "You have successfully registered!");

	            	SetSpawnInfo(playerid, 0, 299, 1757.1228, -1867.2832, 13.5704, 0, 0, 0, 0, 0, 0, 0);
	            	SpawnPlayer(playerid);
	            	SetPlayerPos(playerid, 1757.1228, -1867.2832, 13.5704);
	            	SetPVarInt(playerid, "prelogin", 0);
	            }
	        }
	    }
Код:
stock LoginPlayer(playerid)
{
	new query[126];
	format(query, sizeof(query), "SELECT * FROM playerdata WHERE Name = '%s'", GetName(playerid));
	mysql_query(query);
	mysql_store_result();

	while(mysql_fetch_row_format(query,"|"))
	{
		mysql_fetch_field_row(query, "ID"); PlayerInfo[playerid][ID] = strval(query);
		mysql_fetch_field_row(PlayerInfo[playerid][Name], "Name");
		mysql_fetch_field_row(PlayerInfo[playerid][Password], "Password");
		mysql_fetch_field_row(query, "AdminLevel"); PlayerInfo[playerid][AdminLevel] = strval(query);
		mysql_fetch_field_row(query, "PlayerPos");
		sscanf(query, "fff", PlayerInfo[playerid][Position][0], PlayerInfo[playerid][Position][1], PlayerInfo[playerid][Position][2]);
		mysql_fetch_field_row(query, "Cash"); PlayerInfo[playerid][Cash] = strval(query);
	}
	GivePlayerMoney(playerid, PlayerInfo[playerid][Cash]);
	SetSpawnInfo(playerid, 0, 299, PlayerInfo[playerid][Position][0], PlayerInfo[playerid][Position][1], PlayerInfo[playerid][Position][2], 0, 0, 0, 0, 0, 0, 0);
	SpawnPlayer(playerid);
	SetPlayerPos(playerid, PlayerInfo[playerid][Position][0], PlayerInfo[playerid][Position][1], PlayerInfo[playerid][Position][2]);
}

stock SavePlayer(playerid)
{
	new query[126];

	GetPlayerPos(playerid, PlayerInfo[playerid][Position][0], PlayerInfo[playerid][Position][1], PlayerInfo[playerid][Position][2]);

	format(query, sizeof(query), "UPDATE playerdata SET Name = '%s', Password = '%s', AdminLevel = %d, PlayerPos = '%f %f %f', Cash = %d WHERE id = %d", GetName(playerid), PlayerInfo[playerid][Password], PlayerInfo[playerid][AdminLevel], PlayerInfo[playerid][Position][0], PlayerInfo[playerid][Position][1], PlayerInfo[playerid][Position][2], PlayerInfo[playerid][Cash], PlayerInfo[playerid][ID]);
	mysql_query(query);
	printf("Player ID %d (%s) has been saved", playerid, GetName(playerid));
}
Reply
#2

Anyone that can help?
Reply
#3

Does nobody know how to fix this?
Reply
#4

GetPlayerPos does not work in OnPlayerDisconnect because the player has already left at that point.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)