Y_INI Position saving -
Everybody - 07.06.2012
Hello!
I tried following, googling the problem and found no solutions. The tutorials on the forums didnt help me
The problem is it wont save the coordinates correctly.
OnPlayerDisconnect:
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
switch(reason)
{
case 0: format(string, sizeof(string), "%s crashis serverist. (Timeout)", pname);
case 1: format(string, sizeof(string), "%s lahkus serverist.", pname);
case 2: format(string, sizeof(string), "%s kickiti/banniti serverist.", pname);
}
SendClientMessageToAll(COLOR_GREY, string);
new name[MAX_PLAYER_NAME], reasonMsg[8];
switch(reason)
{
case 0: reasonMsg = "Timeout";
case 1: reasonMsg = "Leaving";
case 2: reasonMsg = "Kicked";
}
GetPlayerName(playerid, name, sizeof(name));
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][Angle]);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Kills",PlayerInfo[playerid][Kills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][Deaths]);
INI_WriteInt(File,"Adminlevel",PlayerInfo[playerid][Adminlevel]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][Skin]);
INI_SetTag( File, "position" );
new Float:X, Float:Y, Float:Z, Float:A;
GetPlayerPos(playerid, X, Y, Z);
INI_WriteFloat(File, "PosX", X);
INI_WriteFloat(File, "PosY", Y);
INI_WriteFloat(File, "PosZ", Z);
//INI_WriteFloat(File, "Angle", GetPlayerFacingAngle(playerid, A);
INI_WriteInt( File, "Interior", GetPlayerInterior( playerid ) );
INI_WriteInt( File, "VirtualWorld", GetPlayerVirtualWorld( playerid ) );
INI_Close(File);
return 1;
}
I know its very messy, but help meh!
Re: Y_INI Position saving -
alpha500delta - 07.06.2012
If I'm right, GetPlayerPos does not work under OnPlayerDisconnect as it will return 0. You need to save it before the player exits.
I could be wrong though... I've had this problem before but I don't remember how I fixed it.
Re: Y_INI Position saving -
caki - 07.06.2012
This is how i'm saving and loading position. It should help you.
pawn Code:
// saving
GetPlayerPos(playerid, PlayerInfo[playerid][pLastX], PlayerInfo[playerid][pLastY], PlayerInfo[playerid][pLastZ]);
INI_WriteFloat(playerFile, "LastX", PlayerInfo[playerid][pLastX]);
INI_WriteFloat(playerFile, "LastY", PlayerInfo[playerid][pLastY]);
INI_WriteFloat(playerFile, "LastZ", PlayerInfo[playerid][pLastZ]);
PlayerInfo[playerid][pInterior]= GetPlayerInterior(playerid);
INI_WriteInt(playerFile, "Interior", PlayerInfo[playerid][pInterior]);
PlayerInfo[playerid][pVirtualWorld]= GetPlayerVirtualWorld(playerid);
INI_WriteInt(playerFile, "VirtualWorld", PlayerInfo[playerid][pVirtualWorld]);
pawn Code:
// Load it somewhere i use it on player spawn
SetPlayerPos(playerid, PlayerInfo[playerid][pLastX], PlayerInfo[playerid][pLastY], PlayerInfo[playerid][pLastZ]);
SetPlayerInterior(playerid,PlayerInfo[playerid][pInterior]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVirtualWorld]);