[Tutorial] Save, load and set player position - using y_ini
#21

i have this working but when i restart the server the coords do not load it spawns me at 0,0,0
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    if(IsPlayerLoggedIn[playerid] == 1)
    {
        new INI:iFile = INI_Open(PlayerPath(playerid));
        INI_SetTag(iFile,"data");
        GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
        GetPlayerFacingAngle( playerid, PlayerInfo[playerid][pAngle]);
        INI_SetTag(iFile, "position");
        INI_WriteFloat(iFile,"PositionX",PlayerInfo[playerid][pPosX]);
        INI_WriteFloat(iFile,"PositionY",PlayerInfo[playerid][pPosY]);
        INI_WriteFloat(iFile,"PositionZ",PlayerInfo[playerid][pPosZ]);
        INI_WriteFloat(iFile,"Angle",PlayerInfo[playerid][pAngle]);
        INI_WriteInt(iFile,"Interior",GetPlayerInterior(playerid));
        INI_WriteInt(iFile,"VirtualWorld",GetPlayerVirtualWorld(playerid));
        INI_Close(iFile);
    }
    return 1;
}

public UserDataLoad_data(playerid,name[],value[]) {
    INI_Int("Pass",PlayerInfo[playerid][pPass]);
    #if defined AUTOLOGIN
        INI_String("IP",pIP[playerid],16);
    #endif
    INI_Float("PositionX",PlayerInfo[playerid][pPosX]);
    INI_Float("PositionY",PlayerInfo[playerid][pPosY]);
    INI_Float("PositionZ",PlayerInfo[playerid][pPosZ]);
    INI_Float("Angle",PlayerInfo[playerid][pAngle]);
    INI_Int("Interior",PlayerInfo[playerid][pInterior]);
    INI_Int("VirtualWorld",PlayerInfo[playerid][pVirtualWorld]);
   
    return 1;
}

public SkipSpawn(playerid)
{
    if(PlayerInfo[playerid][pReg] == 1)
    {
        SetSpawnInfo( playerid, 0, 0, PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ],PlayerInfo[playerid][pAngle], 0, 0, 0, 0, 0, 0 );
        SetPlayerInterior( playerid, PlayerInfo[playerid][pInterior]);
        SetPlayerVirtualWorld( playerid, PlayerInfo[playerid][pVirtualWorld]);
        SpawnPlayer(playerid);
        SendClientMessage( playerid, -1, "welcome to your last position" );
    }
    else if(PlayerInfo[playerid][pReg] == 0)
    {
        SetSpawnInfo( playerid, 0, 0, -2764.9766,375.4572,6.3430,271.0806, 0, 0, 0, 0, 0, 0 );
        SpawnPlayer(playerid);
    }
    return 1;
}
Reply
#22

BUMP Same problem !
Reply
#23

I believe that It won't be saved when it's a server restart. (START/STOP). Try to quit the game and join again.
Reply
#24

EDIT: Fixed & working with different code !
Reply
#25

Thanks Man Its Works +rep
Reply
#26

Hey i server restarting , it not work and not load players pos !
Spawn all players to x0 y0 z0 !
can you help ?
Reply
#27

Hi, i am newbie to scripting and i used your script to make a FS and it compiled without any error and loaded too... and when i discconects it saves my location but when i connect it spawns me at the default position. can anyone tell what's the problem?
Reply
#28

when you really want to use this system, just create timer what saves player positsion after every minute.
Reply
#29

Very Nice
Reply
#30

Quote:
Originally Posted by CodeStyle175
View Post
when you really want to use this system, just create timer what saves player positsion after every minute.
False. You save it on OnPlayerDisconnect. What if you want to leave the server but won't save?
Something went wrong with your saving?
Reply
#31

Hi Derick,
Can you help me? Actually the FS is working fine and when I left the server it saves the coords in the file but when I log in it spawns me at my default location

I will be thankful if u can help me
Reply
#32

Quote:
Originally Posted by beastmaster
View Post
Hi Derick,
Can you help me? Actually the FS is working fine and when I left the server it saves the coords in the file but when I log in it spawns me at my default location

I will be thankful if u can help me
What does it print out?
Reply
#33

Quote:

what does it print out?

this is how FS looks

Quote:

#include <a_samp>
#include <YSI\y_ini>

new
Float: PosX[ MAX_PLAYERS ],
Float: PosY[ MAX_PLAYERS ],
Float: PosZ[ MAX_PLAYERS ],
Float: Angle[ MAX_PLAYERS ],
Interior[ MAX_PLAYERS ],
VirtualWorld[ MAX_PLAYERS ]
;

stock user_ini_file(playerid)
{
new
string[ 128 ],
user_name[ MAX_PLAYER_NAME ]
;

GetPlayerName( playerid, user_name, MAX_PLAYER_NAME );
format( string, sizeof ( string ), "%s.ini", user_name );
/* scriptfiles directory */
return
string;
}

forward @load_user_position( playerid, name[], value[] );

@load_user_position( playerid, name[], value[] )
{
INI_Float( "PositionX", PosX[ playerid ] );
INI_Float( "PositionY", PosY[ playerid ] );
INI_Float( "PositionZ", PosZ[ playerid ] );
INI_Float( "Angle", Angle[ playerid ] );
INI_Int( "Interior", Interior[ playerid ] );
INI_Int( "VirtualWorld", VirtualWorld[ playerid ] );
return ( 1 );
}

public OnPlayerDisconnect( playerid, reason )
{
GetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
GetPlayerFacingAngle( playerid, Angle[ playerid ] );

new INI:File = INI_Open( user_ini_file( playerid ) );
INI_SetTag( File, "position" );
INI_WriteFloat( File, "PositionX", PosX[ playerid ] );
INI_WriteFloat( File, "PositionY", PosY[ playerid ] );
INI_WriteFloat( File, "PositionZ", PosZ[ playerid ] );
INI_WriteFloat( File, "Angle", Angle[ playerid ] );
INI_WriteInt( File, "Interior", GetPlayerInterior( playerid ) );
INI_WriteInt( File, "VirtualWorld", GetPlayerVirtualWorld( playerid ) );
INI_Close( File );
return ( 1 );
}

public OnPlayerConnect( playerid )
{
PosX[ playerid ] = 0;
PosY[ playerid ] = 0;
PosZ[ playerid ] = 0;
Angle[ playerid ] = 0;
Interior[ playerid ] = 0;
VirtualWorld[ playerid ] = 0;

INI_ParseFile( user_ini_file( playerid ), "load_user_%s", .bExtra = true, .extra = playerid );
return ( 1 );
}


public OnPlayerSpawn( playerid )
{
if ( PosX[ playerid ] != 0 && PosY[ playerid ] != 0 && PosZ[ playerid ] != 0 )
{
SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
SetPlayerFacingAngle( playerid, Angle[ playerid ] );
SetPlayerInterior( playerid, Interior[ playerid ] );
SetPlayerVirtualWorld( playerid, VirtualWorld[ playerid ] );
SendClientMessage( playerid, -1, "welcome to your last position" );
}
return ( 1 );
}

and when i leave the server it saves my last cords but when i join again it spawns me at the default loaction( which is in gamemode)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)