PDA

View Full Version : Mysql spawning


thimo
08/12/2011, 04:50 PM
Ok so i wanted to save position on disconnect and that finally works but now i got the problem it keeps spawning me at 0,0,0. This is my code:

public OnPlayerSpawn(playerid)
{
new string[128];
format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s' AND X='%d',Y='%d',Z='%d'", UserStats[playerid][Name], UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
mysql_query(string);
mysql_store_result();
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
mysql_free_result();
return 1;
}

Anyone knows whats wrong? :S

Laronic
08/12/2011, 04:54 PM
public OnPlayerSpawn(playerid)
{
new string[128], load[50];
format(string, sizeof(string), "SELECT `X`, `Y`, `Z` FROM Users WHERE Name = '%s'", UserStats[playerid][Name]);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(load))
{
sscanf(load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
}
mysql_free_result();
return 1;
}

thimo
08/12/2011, 04:57 PM
Testing now
Edit: its still not working:
What am i doing wrong here:


public OnPlayerDisconnect(playerid, reason)
{
new Float:X, Float:Y, Float:Z, string[120];
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
format(string, sizeof(string), "UPDATE Users SET X='%d',Y='%d',Z='%d' WHERE Name='%s'",X, Y, Z,UserStats[playerid][Name]);
mysql_query(string);
SavePlayer(playerid);

UserStats[playerid][Admin] = 0;
UserStats[playerid][Money] = 0;
AccountExists[playerid] = 0;
PlayerLogged[playerid] = 0;
return 1;
}

public OnPlayerSpawn(playerid)
{
new string[128], load[50];
format(string, sizeof(string), "SELECT `X`, `Y`, `Z` FROM Users WHERE Name = '%s'", UserStats[playerid][Name]);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(load))
{
sscanf(load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
}
mysql_free_result();
return 1;
}

Laronic
08/12/2011, 04:58 PM
Whoopsie, I updated my previous post.

Edit: Show your account info enum

thimo
08/12/2011, 05:09 PM
This for the pawn acc info

enum pEnum
{
Name[MAX_PLAYER_NAME],
Password[34],
Admin,
Money,
Float:X,
Float:Y,
Float:Z
};
new UserStats[MAX_PLAYERS][pEnum];

This is both:
http://img33.imageshack.us/img33/7175/naamloosyg.png

Laronic
08/12/2011, 05:11 PM
Looks correct, try this:


public OnPlayerDisconnect(playerid, reason)
{
new Float:X, Float:Y, Float:Z, string[110];
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
format(string, sizeof(string), "UPDATE Users SET X = '%f', Y = '%f', Z = '%f' WHERE Name = '%s'", X, Y, Z, UserStats[playerid][Name]);
mysql_query(string);
SavePlayer(playerid);

UserStats[playerid][Admin] = 0;
UserStats[playerid][Money] = 0;
AccountExists[playerid] = 0;
PlayerLogged[playerid] = 0;
return 1;
}

public OnPlayerSpawn(playerid)
{
new string[65], load[50];
format(string, sizeof(string), "SELECT X, Y, Z FROM Users WHERE Name = '%s'", UserStats[playerid][Name]);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(load))
{
sscanf(load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
}
mysql_free_result();
return 1;
}


If it dont works, then comment "SavePlayer(playerid);" and try again. If it works when you have commented "SavePlayer(playerid);" then show us that function

thimo
08/12/2011, 05:18 PM
Ok i got these errors from this:

public OnPlayerDisconnect(playerid, reason)
{
new string[120];
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
format(string, sizeof(string), "UPDATE Users SET X = '%f', Y = '%f', Z = '%f' WHERE Name = '%s'", X, Y, Z, UserStats[playerid][Name]);
mysql_query(string);
SavePlayer(playerid);

UserStats[playerid][Admin] = 0;
UserStats[playerid][Money] = 0;
AccountExists[playerid] = 0;
PlayerLogged[playerid] = 0;
return 1;
}

public OnPlayerSpawn(playerid)
{
new string[128], load[50];
format(string, sizeof(string), "SELECT X, Y, Z FROM Users WHERE Name = '%s'", UserStats[playerid][Name]);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(load))
{
sscanf(load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
}
mysql_free_result();
return 1;
}

The error:

C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(73) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

Player SAVE function:

SavePlayer(playerid)
{
if(!PlayerLogged[playerid])
return 0;

UserStats[playerid][Money] = GetPlayerMoney(playerid);


CheckMySQL();

new string[256];
format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Name]);
mysql_query(string);
return 1;
}

Laronic
08/12/2011, 05:24 PM
Try this:


public OnPlayerDisconnect(playerid, reason)
{
new Float:X, Float:Y, Float:Z, string[110];
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
format(string, sizeof(string), "UPDATE Users SET X = '%f', Y = '%f', Z = '%f' WHERE Name = '%s'", X, Y, Z, UserStats[playerid][Name]);
mysql_query(string);
SavePlayer(playerid);

UserStats[playerid][Admin] = 0;
UserStats[playerid][Money] = 0;
AccountExists[playerid] = 0;
PlayerLogged[playerid] = 0;
return 1;
}

public OnPlayerSpawn(playerid)
{
new string[65], load[50];
format(string, sizeof(string), "SELECT X, Y, Z FROM Users WHERE Name = '%s'", UserStats[playerid][Name]);
mysql_query(string);
mysql_store_result();
if(mysql_num_rows() != 0 && mysql_fetch_row(load))
{
sscanf(load, "p<|>fff", UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
SetPlayerPos(playerid, UserStats[playerid][X], UserStats[playerid][Y], UserStats[playerid][Z]);
}
mysql_free_result();
return 1;
}

SavePlayer(playerid)
{
if(!PlayerLogged[playerid]) return 0;

UserStats[playerid][Money] = GetPlayerMoney(playerid);

CheckMySQL();

new string[256];
format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Name]);
mysql_query(string);
}


About the error? what line?

Edit: Do you get any error in the MySQL debug log?

thimo
08/12/2011, 05:25 PM
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);

Laronic
08/12/2011, 05:27 PM
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);

Ok use my last posted code, i saw you had removed the "Float:X, Float:Y, Float:Z" from OnPlayerDisconnect.

If you are BlueG's plugin. run the debugging finction and show me the log

thimo
08/12/2011, 05:28 PM
When i use this:

new Float:X, Float:Y, Float:Z, string[110];
GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);

I get these errors:


C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 219: local variable "X" shadows a variable at a preceding level
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 219: local variable "Y" shadows a variable at a preceding level
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 219: local variable "Z" shadows a variable at a preceding level
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(73) : error 035: argument type mismatch (argument 2)
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 203: symbol is never used: "Z"
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 203: symbol is never used: "Y"
C:\Users\Thimo\Desktop\Sa-mp 0.3d\gamemodes\European_RolePlay.pwn(72) : warning 203: symbol is never used: "X"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Error.

Lines


70public OnPlayerDisconnect(playerid, reason)
71{
72. new Float:X, Float:Y, Float:Z, string[110];
73 GetPlayerPos(playerid, X, Y, Z);
74 format(string, sizeof(string), "UPDATE Users SET X = '%f', Y = '%f', Z = '%f' WHERE Name = '%s'", X, Y, Z, UserStats[playerid][Name]);
75 mysql_query(string);
76 SavePlayer(playerid);
77
78 UserStats[playerid][Admin] = 0;
79 UserStats[playerid][Money] = 0;
80 AccountExists[playerid] = 0;
81 PlayerLogged[playerid] = 0;
82 return 1;
83}

Kingunit
08/12/2011, 05:42 PM
warning 219: local variable "X" shadows a variable at a preceding level

Means that you have already:

new X;