Load Files with y_ini | Problem
#1

Hi!

I tried to make a save pos system. Code saves everything correctly. But there is a problem with a load. This is my first time when I used y_ini. Can you help me? Please

This is my code:

First:

Код:
new
    Float: PosX[ MAX_PLAYERS ],
    Float: PosY[ MAX_PLAYERS ],
    Float: PosZ[ MAX_PLAYERS ],
    Float: Angle[ MAX_PLAYERS ],
    Interior[ MAX_PLAYERS ],
    Skin[ MAX_PLAYERS ],
    VirtualWorld[ MAX_PLAYERS ]
;
Then:

Код:
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 );
    return
        string;
}
Save Code (Disconnect):

Код:
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_WriteInt( File, "Skin", GetPlayerSkin( playerid ) );
INI_Close( File );
Load Code:

Код:
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 ] );
    INI_Int( "Skin", Skin[ playerid ] );
    return ( 1 );
}
Load in Connect:

Код:
PosX[ playerid ] = 0;
PosY[ playerid ] = 0;
PosZ[ playerid ] = 0;
Angle[ playerid ] = 0;
Interior[ playerid ] = 0;
VirtualWorld[ playerid ] = 0;
Skin[ playerid ] = 0;

INI_ParseFile( user_ini_file( playerid ), "load_user_%s", .bExtra = true, .extra = playerid );
Load in Spawn:

Код:
if ( PosX[ playerid ] != 0 && PosY[ playerid ] != 0 && PosZ[ playerid ] != 0 && Angle[ playerid ] != 0 )
{
SetPlayerPos( playerid, PosX[ playerid ], PosY[ playerid ], PosZ[ playerid ] );
SetPlayerFacingAngle( playerid, Angle[ playerid ] );
SetPlayerInterior( playerid, Interior[ playerid ] );
SetPlayerVirtualWorld( playerid, VirtualWorld[ playerid ] );
SetPlayerSkin( playerid, Skin[ playerid ] );
SendClientMessage( playerid, -1, "Twoje dane po wyjściu zostały wczytane." );
}
else
{
new rand = random(sizeof(RandomSpawnsCzlowiek));
SetPlayerPos(playerid, RandomSpawnsCzlowiek[rand][0], RandomSpawnsCzlowiek[rand][1], RandomSpawnsCzlowiek[rand][2]);
}
Can someone help me?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)