SA-MP Forums Archive
Mysql spawning - 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: Mysql spawning (/showthread.php?tid=302364)



Mysql spawning - thimo - 08.12.2011

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:
pawn Код:
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


Re: Mysql spawning - Laronic - 08.12.2011

pawn Код:
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;
}



Re: Mysql spawning - thimo - 08.12.2011

Testing now
Edit: its still not working:
What am i doing wrong here:
pawn Код:
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;
}



Re: Mysql spawning - Laronic - 08.12.2011

Whoopsie, I updated my previous post.

Edit: Show your account info enum


Re: Mysql spawning - thimo - 08.12.2011

This for the pawn acc info
pawn Код:
enum pEnum
{
    Name[MAX_PLAYER_NAME],
    Password[34],
    Admin,
    Money,
    Float:X,
    Float:Y,
    Float:Z
};
new UserStats[MAX_PLAYERS][pEnum];
This is both:



Re: Mysql spawning - Laronic - 08.12.2011

Looks correct, try this:

pawn Код:
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


Re: Mysql spawning - thimo - 08.12.2011

Ok i got these errors from this:
pawn Код:
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:
pawn Код:
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:
pawn Код:
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;
}



Re: Mysql spawning - Laronic - 08.12.2011

Try this:

pawn Код:
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?


Re: Mysql spawning - thimo - 08.12.2011

GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);


Re: Mysql spawning - Laronic - 08.12.2011

Quote:
Originally Posted by thimo
Посмотреть сообщение
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