I need ANY system to save Player Position and Skin.
#2

I guess you could use this as a separate filterscript if you wanted to. For this, you need to follow the following steps:

- Create a folder in your scriptfiles directory called 'Positions'. You should now have a '..\scriptfiles\Positions\' directory.
- You need the YSI Library (preferably), or at least the 'y_ini' include.

pawn Код:
#include <a_samp>
#include <YSI\y_ini>

enum PosData
{
    Float:X,
    Float:Y,
    Float:Z,
    Float:Angle,
    Skin
};
new Position[MAX_PLAYERS][PosData];
new bool:HasFirstSpawned[MAX_PLAYERS];

public OnPlayerDisconnect(playerid, reason)
{
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    new file[40], playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(file, sizeof(file), "Positions/%s.ini", playername);
    new INI:PFile = INI_Open(file);
    INI_WriteFloat(PFile, "Pos_X", x);
    INI_WriteFloat(PFile, "Pos_Y", y);
    INI_WriteFloat(PFile, "Pos_Z", z);
    INI_WriteFloat(PFile, "Pos_Angle", a);
    INI_WriteInt(PFile, "Skin", GetPlayerSkin(playerid));
    INI_Close(PFile);
    return 1;
}

public OnPlayerConnect(playerid)
{
    HasFirstSpawned[playerid] = false;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    //Add important code here. (Ones that you want to run EVERY time a player spawns)
    if(!HasFirstSpawned[playerid])
    {
        new file[40], playername[MAX_PLAYER_NAME];
        GetPlayerName(playerid, playername, sizeof(playername));
        format(file, sizeof(file), "Positions/%s.ini", playername);
        INI_ParseFile(file, "LoadPositions_%s", .bExtra = true, .extra = playerid);
        SetPlayerPos(playerid, Position[playerid][X], Position[playerid][Y], Position[playerid][Z]);
        SetPlayerFacingAngle(playerid, Position[playerid][Angle]);
        SetPlayerSkin(playerid, Position[playerid][Skin]);
        HasFirstSpawned[playerid] = true;
        return 1;
    }
    //Add other stuff here, like setting a player to respawn at certain locations.
    return 1;
}

forward LoadPositions_data(playerid, name[], value[]);
public LoadPositions_data(playerid, name[], value[])
{
    INI_Float("Pos_X", Position[playerid][X]);
    INI_Float("Pos_Y", Position[playerid][Y]);
    INI_Float("Pos_Z", Position[playerid][Z]);
    INI_Float("Pos_Angle", Position[playerid][Angle]);
    INI_Int("Skin", Position[playerid][Skin]);
    return 1;
}
Reply


Messages In This Thread
I need ANY system to save Player Position and Skin. - by Aerotactics - 12.02.2014, 07:29
Re: I need ANY system to save Player Position and Skin. - by Threshold - 12.02.2014, 10:28
Re: I need ANY system to save Player Position and Skin. - by Aerotactics - 12.02.2014, 19:53

Forum Jump:


Users browsing this thread: 1 Guest(s)