Player positions not loading properly -
OMonger - 25.07.2018
I've got another problem. Basically on my load player, it doesn't load the players position properly. It always spawns them at the blueberry farm instead of their most recent position before leaving. Here are the codes that could be affecting this:
PHP код:
Of course on the dialog login it allows them to access the request class, and with or without the logged in statement on requestclass does not affect results
public OnPlayerRequestClass(playerid, classid)
{
if(playerInfo[playerid][LoggedIn] == true)
{
new Float:posX, Float:posY, Float:posZ;
cache_get_value_name_float(0, "playerX", posX);
cache_get_value_name_float(0, "playerY", posY);
cache_get_value_name_float(0, "playerZ",posZ);
SetSpawnInfo( playerid, 0, 0, posX, posY, posZ, 0, 0, 0, 0, 0, 0, 0 );
SpawnPlayer(playerid);
}
return 1;
}
stock LoadPlayerStats(playerid)
{
if(playerInfo[playerid][LoggedIn] == true)
{
new query[200], name[24];
GetPlayerName(playerid, name, 24);
format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `playerName` = '%s'", name);
mysql_tquery(Database, query);
playerInfo[playerid][playerAdmin] = cache_get_value_int(0, "playerAdmin", playerInfo[playerid][playerAdmin]);
playerInfo[playerid][playerMod] = cache_get_value_int(0, "playerMod", playerInfo[playerid][playerMod]);
playerInfo[playerid][playerHelper] = cache_get_value_int(0, "playerHelper", playerInfo[playerid][playerHelper]);
playerInfo[playerid][playerLevel] = cache_get_value_int(0, "playerLevel", playerInfo[playerid][playerLevel]);
playerInfo[playerid][playerCash] = cache_get_value_int(0, "playerCash", playerInfo[playerid][playerCash]);
SetPlayerScore(playerid, playerInfo[playerid][playerLevel]);
GivePlayerMoney(playerid, playerInfo[playerid][playerCash]);
printf("player loaded.");
}
}
Re: Player positions not loading properly -
Usmanmemon - 25.07.2018
You must save player position on OnPlayerDisconnect! then it will work.
Re: Player positions not loading properly -
denNorske - 25.07.2018
Perhaps we can get to see how you save the positions as well?
Re: Player positions not loading properly -
Calisthenics - 25.07.2018
This is wrong. Do not use cache functions in random places, there must be active cache in order to use them or else will give warning in mysql logs.
mysql_tquery uses another callback, see example:
https://sampwiki.blast.hk/wiki/MySQL#mysql_tquery
Re: Player positions not loading properly -
OMonger - 25.07.2018
They're being saved on player disconnect.
@Calisthenics, should I use the format function aswell to get the info?
Re: Player positions not loading properly -
Calisthenics - 25.07.2018
It's a good practice as you need to escape necessary strings.
When a player connects:
pawn Код:
mysql_format(...);
mysql_tquery(Database, query, "OnPlayerDataLoad", "d", playerid);
Check if player is registered or not:
pawn Код:
forward OnPlayerDataLoad(playerid);
public OnPlayerDataLoad(playerid)
{
if (cache_num_rows())
{
// player is register, show "login" dialog
}
else
{
// player is not registered, show "register" dialog
}
}
In OnDialogResponse, you check if passwords match and then you call all cache functions to retrieve data.
This is also wrong:
pawn Код:
playerInfo[playerid][playerAdmin] = cache_get_value_int(0, "playerAdmin", playerInfo[playerid][playerAdmin]);
function returns 0 or 1 (failure or success) so just:
pawn Код:
cache_get_value_int(0, "playerAdmin", playerInfo[playerid][playerAdmin]);
But this is rather basic. Mysql race is a condition that can happen even in a samp server, you do not want random players get the data of previous player and their administrator status. For an example script, look at here:
https://raw.githubusercontent.com/pB...stem-cache.pwn
Re: Player positions not loading properly -
GTLS - 26.07.2018
Heres how it goes.
Under OnPlayerConnect, via MySQL, player's data is fetched using
SELECT statement(Make sure to use tquery), now the command is passed to the threaded function. Under That function, get the float values from the cache and store them inside the player variables. Now, under OnPlayerRequestSpawn, use SetSpawnInfo() with the values you previously got from DB and then Spawn him.