Help with Saving/Loading Player Positions. EASY
#1

Hello Guys.
I've already ask this today, but no-one was able to help me....
I want to make my server save and load/set player position when login to the last position....

So when player login, he will be in the same place where he lefted...
I hope that you can help me as i tried many things, failing...
My script is:
(The needed callbacks for this system).


pInfo Enum:
pawn Код:
enum pInfo
{
    AdminLevel,
    Cash,
    Score,
    Color,
    Job,
    Vw,
    Int,
    Warns,
    Fleader,
    Fmember,
    Bank,
    Prods,
    Skin,
    RepairOffer,
    Credit,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Register Dialog:
pawn Код:
if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), "RicAdmin/users/%s.ini", name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext)) return
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][AdminLevel] = 0);
        dini_IntSet(file, "Cash",PlayerInfo[playerid][Cash] = 500);
        dini_IntSet(file, "Score",PlayerInfo[playerid][Score] = 0);
        dini_IntSet(file, "Job",PlayerInfo[playerid][Job] = 0);
        dini_IntSet(file, "Color",PlayerInfo[playerid][Color] = 0);
        dini_IntSet(file, "Vw",PlayerInfo[playerid][Vw] = 0);
        dini_IntSet(file, "Int",PlayerInfo[playerid][Int] = 0);
        dini_IntSet(file, "Warns",PlayerInfo[playerid][Warns] = 0);
        dini_IntSet(file, "Fleader",PlayerInfo[playerid][Fleader] = 0);
        dini_IntSet(file, "Fmember",PlayerInfo[playerid][Fmember] = 0);
        dini_IntSet(file, "Bank",PlayerInfo[playerid][Bank] = 0);
        dini_IntSet(file, "Prods",PlayerInfo[playerid][Prods] = 0);
        dini_IntSet(file, "Skin",PlayerInfo[playerid][Skin] = 0);
        dini_IntSet(file, "RepairOffer",PlayerInfo[playerid][RepairOffer] = 0);
        dini_IntSet(file, "Credit",PlayerInfo[playerid][Credit] = 0);
        format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s, you have been auto logged in.", name, inputtext);
        SendClientMessage(playerid, 0xFF00CC, string);
        IsLogged[playerid] = 1;
    }
Login Dialog:
pawn Код:
if (dialogid == 2)
    {
      new name[MAX_PLAYER_NAME];
      GetPlayerName(playerid, name, sizeof(name));
      format(file, sizeof(file), "RicAdmin/users/%s.ini", name);
      if(!response) return Kick(playerid);
      if (!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "You are registred, please login.", "Login", "Leave");
      new tmp;
      tmp = dini_Int(file, "Password");
      if(udb_hash(inputtext) != tmp) {
      SendClientMessage(playerid, 0xFF00CC, "Wrong PW sir.");
      ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Hi your registered", "You are registred, put the password below.", "Login", "Leave");
      }
      else
      {
        IsLogged[playerid] = 1;
        SetPlayerMoney(playerid, dini_Int(file, "Cash"));
        SetPlayerScore(playerid, dini_Int(file, "Score"));
        SetPlayerColor(playerid, dini_Int(file, "Color"));
        SetPlayerVirtualWorld(playerid, dini_Int(file, "Vw"));
        SetPlayerInterior(playerid, dini_Int(file, "Int"));
        PlayerInfo[playerid][Job] = dini_Int(file, "Job");
        PlayerInfo[playerid][Warns] = dini_Int(file, "Warns");
        PlayerInfo[playerid][Fleader] = dini_Int(file, "Fleader");
        PlayerInfo[playerid][Fmember] = dini_Int(file, "Fmember");
        PlayerInfo[playerid][Bank] = dini_Int(file, "Bank");
        PlayerInfo[playerid][Prods] = dini_Int(file, "Prods");
        PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
        PlayerInfo[playerid][RepairOffer] = dini_Int(file, "RepairOffer");
        PlayerInfo[playerid][Credit] = dini_Int(file, "Credit");
        SetPlayerSkin(playerid, dini_Int(file, "Skin"));
        SendClientMessage(playerid,0xFF00CC, "[SYSTEM]: Successfully logged in!");
    }
    }
return 1;
}
My OnPlayerSpawn:
pawn Код:
public OnPlayerSpawn(playerid)
{
    SetPlayerMapIcon(playerid, 4, 1461.215209, -1012.771972, 26.843750, 52, COLOR_YELLOW);  // Bank
    SetPlayerMapIcon(playerid, 8, 2468.4919,-2092.9902,13.5469, 51, COLOR_YELLOW)// Truck Place
    SetPlayerMapIcon(playerid, 10, 1235.013916, 360.252166, 19.554687, 27, COLOR_YELLOW);   // Mechanic Place
    SetPlayerMapIcon(playerid, 13, -1421.7410,-287.9273,14.1484, 5, COLOR_YELLOW); // SF Airport
    SetPlayerMapIcon(playerid, 14, 1675.3717,1447.8632,10.7876, 5, COLOR_YELLOW); // LV Airport
    SetPlayerMapIcon(playerid, 15, 1685.9310,-2239.2971,-2.7028, 5, COLOR_YELLOW); // LS Airport
    SetPlayerMapIcon(playerid, 28, 1555.3328,-1610.7543,12.4250, 11, COLOR_YELLOW); // Helipad LSPD
    SetPlayerMapIcon(playerid, 29, 2789.7092,-2531.5193,12.6450, 11, COLOR_YELLOW); // Helipad Army
    SetPlayerMapIcon(playerid, 3, 1227.623535, 181.653335, 20.409919, 30, COLOR_YELLOW); //Police Station
    SetPlayerMapIcon(playerid, 4, 1310.981689, 329.641571, 19.914062, 52, COLOR_YELLOW);  // Ammu
    SetPlayerMapIcon(playerid, 4, 1256.442871, 275.010467, 19.554687, 52, COLOR_YELLOW);  // 24/7
    SetPlayerMapIcon(playerid, 8, 1200.335937, 248.921127, 19.281734, 51, COLOR_YELLOW);    // Truck Place Country
    SetPlayerMapIcon( playerid, 1, 1315.4899, -900.8430, 39.5781, 17, 0 ); // 24/7 Vinewood
    SetPlayerMapIcon( playerid, 2, 1352.3300, -1755.7100, 13.3530, 17, 0 ); // 24/7 Perishing
    SetPlayerMapIcon( playerid, 3, 2045.9812,-1907.9951,13.5469, 55, 0 ); // DMV
    SetPlayerMapIcon( playerid, 4, 1565.5342, 23.0955, 24.1641, 18, 0 ); // Arms Dealer Registration
    SetPlayerMapIcon( playerid, 5, -2170.3726,-232.9594,36.5156, 18, 0 ); // Arms Dealer Pick Up
    SetPlayerMapIcon( playerid, 6, -489.3573,611.6118,1.7739, 18, 0 ); // Arms Dealer Drop Off
    SetPlayerMapIcon( playerid, 7, 1831.7091, -1682.1526, 13.5456, 49, 0 ); // Alhambra
    SetPlayerMapIcon( playerid, 8, 2851.5830, -1532.2117, 11.0938, 49, 0 ); // Emerald Club
    SetPlayerMapIcon( playerid, 9, 2421.5200, -1221.7500, 25.3998, 49, 0 ); // Pig Pen
    SetPlayerMapIcon( playerid, 10, 1003.7123, -935.3038, 41.7400, 56, 0 ); // Vinewood Gas Station
    SetPlayerMapIcon( playerid, 11, 1942.9373, -1772.9230, 13.3906, 56, 0 ); // Downtown Gas Station
    SetPlayerMapIcon( playerid, 12, 1553.3510, -1675.4082, 16.1953, 30, 0 ); // LSPD
    SetPlayerMapIcon( playerid, 13, 2421.2256,-1222.2745, 25.3670, 12, 0 ); // Whore Job
    SetPlayerMapIcon( playerid, 14, 1830.6687, -1075.4744, 23.8479, 25, 0 ); // Drug Dealer Crack House
    SetPlayerMapIcon( playerid, 15, 1109.3318, -1796.3042, 16.5938, 51, 0 ); // Car Jacker Join
    SetPlayerMapIcon( playerid, 16, 214.7574, -230.5657, 1.7786, 51, 0); // Car Jacker Drop Off
    SetPlayerMapIcon( playerid, 17, -2185.7229, 2415.9033, 5.1728, 19, 0); // Arms Smuggler Join
    SetPlayerMapIcon( playerid, 18, -1694.9041, 1330.4119, 7.1814, 19, 0); // Drugs Smuggler Join
    SetPlayerMapIcon( playerid, 19, -2419.1257, 2313.8582, 2.3012, 38, 0); // Smuggler Boat
    SetPlayerMapIcon( playerid, 20, 593.0324,-1241.1177,17.9662, 52, 0 ); // Bank Icon
    SetPlayerMapIcon( playerid, 21, 1833.4976, -1842.4099, 13.5781, 17, 0 ); // 24/7 Unity Icon
    SetPlayerMapIcon( playerid, 22, -1465.6941, 1086.6008, 1.5894, 24, 0 ); // Drug Smuggler Pickup
    SetPlayerMapIcon( playerid, 23, 1766.8953, -2286.1663, 26.9665, 56, 0 ); // Drug Smuggler Pickup
    SetPlayerMapIcon( playerid, 24, 417.8507, -1729.2375, 9.3467, 49, 0 ); // Emerald Club
    SetPlayerMapIcon( playerid, 25, 2166.3772,-1675.3829,15.0859, 24, 0 ); // Drug Dealer Join
    SetPlayerMapIcon( playerid, 26, 417.8507, -1729.2375, 9.3467, 49, 0 ); // 187 Club
    SetPlayerMapIcon( playerid, 27, 1761.3638,-1894.3767,13.5609, 11, 0 ); // Taxi Co.
    SetPlayerMapIcon( playerid, 28, 2306.5583,-2322.2639,13.3828, 27, 0 ); // Streetsweeper and Mechanic Jobs
    SetPlayerMapIcon( playerid, 29, 1008.0930,-929.5586,42.3281, 52, 0 ); // ATM 1
    SetPlayerMapIcon( playerid, 30, 1601.1042,-1539.5621,13.6062, 55, 0 ); //Mod Shop
    CreatePickup(1274, 1, 1461.215209, -1012.771972, 26.843750, -1); //BankLS
    CreatePickup(1240, 1, 1359.573974, 205.404083, 19.755516, -1); //HospitalCountry
    CreatePickup(1247, 1, 1555.333007, -1675.624511, 16.195312, -1); //LSPD
    CreatePickup(1239, 1, 1235.013916, 360.252166, 19.554687, -1); //MechanicCountry
    CreatePickup(1239, 1, 1227.402709, 312.508087, 19.757813, -1); //TaxiCountry
    CreatePickup(1239, 1, 1256.442871, 275.010467, 19.554687, -1); //24/7
    CreatePickup(1239, 1, 1200.335937, 248.921127, 19.281734, -1); //Trucker
    CreatePickup(1239, 1, 2464.828125, -2109.241943, 13.546875, -1); //TruckerLS
    CreatePickup(1239, 1, 1368.896972, -1279.801391, 13.546875, -1); //AmmuNation
    CreatePickup(1239, 1, 1162.419067, -1761.851440, 13.661267, -1); //BusLS
    CreatePickup(1239, 1, 1192.036132,  -1814.132812, 13.581386, -1); //TaxiLS
    CreatePlayer3DTextLabel(playerid,"Use /becometaxi to become a taxi driver!",0x008080FF,1192.036132,  -1814.132812, 13.581386,40.0);
    CreatePlayer3DTextLabel(playerid,"Use /becomebus to become a bus driver!",0x008080FF,1162.419067, -1761.851440, 13.661267,40.0);
    CreatePlayer3DTextLabel(playerid,"Use /becometrucker to become a trucker!",0x008080FF,2464.828125, -2109.241943, 13.546875,40.0);
    CreatePlayer3DTextLabel(playerid,"Use /goin to enter!",0x008080FF,1461.215209, -1012.771972, 26.843750,40.0);
    CreatePlayer3DTextLabel(playerid,"Use /goin to enter!",0x008080FF,1368.896972, -1279.801391, 13.546875,40.0);

    SetPlayerPos(playerid,1186.534301, -1830.901367, 13.297243);
    SetPlayerSkin(playerid, 7);
    SetPlayerHealth(playerid, 100);
    GivePlayerWeapon(playerid, 24, 30);
    return 1;
}
My OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new name[24];
    GetPlayerName(playerid,name,24);
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
        dini_IntSet(file,"Score",GetPlayerScore(playerid));
        dini_IntSet(file,"Color",GetPlayerColor(playerid));
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][AdminLevel]);
        dini_IntSet(file,"Job",PlayerInfo[playerid][Job]);
        dini_IntSet(file,"Vw",GetPlayerVirtualWorld(playerid));
        dini_IntSet(file,"Int",GetPlayerInterior(playerid));
        dini_IntSet(file,"Warns",PlayerInfo[playerid][Warns]);
        dini_IntSet(file,"Fleader",PlayerInfo[playerid][Fleader]);
        dini_IntSet(file,"Fmember",PlayerInfo[playerid][Fmember]);
        dini_IntSet(file,"Bank",PlayerInfo[playerid][Bank]);
        dini_IntSet(file,"Prods",PlayerInfo[playerid][Prods]);
        dini_IntSet(file,"Skin",GetPlayerSkin(playerid));
        dini_IntSet(file,"RepairOffer",PlayerInfo[playerid][RepairOffer]);
        dini_IntSet(file,"Credit",PlayerInfo[playerid][Credit]);
        IsLogged[playerid] = 0;
        return 1;
    }
    return 1;
}
Please help me...
Thank you.
Reply
#2

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new name[24];
    GetPlayerName(playerid,name,24);
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Exists(file))
    {
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
        dini_IntSet(file,"Score",GetPlayerScore(playerid));
        dini_IntSet(file,"Color",GetPlayerColor(playerid));
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][AdminLevel]);
        dini_IntSet(file,"Job",PlayerInfo[playerid][Job]);
        dini_IntSet(file,"Vw",GetPlayerVirtualWorld(playerid));
        dini_IntSet(file,"Int",GetPlayerInterior(playerid));
        dini_IntSet(file,"Warns",PlayerInfo[playerid][Warns]);
        dini_IntSet(file,"Fleader",PlayerInfo[playerid][Fleader]);
        dini_IntSet(file,"Fmember",PlayerInfo[playerid][Fmember]);
        dini_IntSet(file,"Bank",PlayerInfo[playerid][Bank]);
        dini_IntSet(file,"Prods",PlayerInfo[playerid][Prods]);
        dini_IntSet(file,"Skin",GetPlayerSkin(playerid));
        dini_IntSet(file,"RepairOffer",PlayerInfo[playerid][RepairOffer]);
        dini_IntSet(file,"Credit",PlayerInfo[playerid][Credit]);
        dini_IntSet(file,"x", x);
        dini_IntSet(file,"y", y);
        dini_IntSet(file,"z", z);
        dini_IntSet(file,"a", a);
        IsLogged[playerid] = 0;
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    SetPlayerPos(playerid,dini_Int(file, "x"), dini_Int(file, "y", dini_Int(file, "z"));
    SetPlayerFacingAngle(playerid, dini_IntSet(file, "a"));
    return 1;
}
This should work
Reply
#3

It gives me some errors...
I think that i need to create this on the Register dialog.
And, if teh player login for the first time, he doesn't have positions saveds.
Reply
#4

Add something to your register system, like "First login = 1", and put onplayerspawn "If dini_int(file, "first login") == 1) SetPlayerPos(x,y,z)

Then in onplayerdisconnect if(dini_int(file, "first login") == 1) return dini_intset(file, "first login", 0);
Something like that, and also: what are the errors you get?
Reply
#5

Let it.... I will give up as i can't do this shit.
I try again tomorrow. I was waiting for someone that can make the inteir code....
I am really tired of this today as i was some hours around....
THANK you for all.
Reply
#6

Ill help you tomorrow morning, tell me the things you need and tomorrow its done
Reply
#7

I Just need the whole system....
I think that i need to create the PositionsX PositionsY and PositionsZ in the user file, on the registering moment, load it in the login(idk if it is needed), make it read from the file on the spawn, and save it on the disconnect.

Anyway, i think that i need to set it to some base coordenates on the register, so the player will spawn there when he register for the first time....

If you can make me this...
My script is on the first top. I will be really thankfull.
Reply
#8

This would do it, post in here if you get any errors or use my PM

pawn Код:
if (dialogid == 1)
    {
        new name[MAX_PLAYER_NAME], string[128];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), "RicAdmin/users/%s.ini", name);
        if(!response) return Kick(playerid);
        if(!strlen(inputtext)) return
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Hi your not registered", "Welcome, your not registered mate, input your registration pw below", "Register", "Leave");
        dini_Create(file);
        dini_IntSet(file, "Password", udb_hash(inputtext));
        dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][AdminLevel] = 0);
        dini_IntSet(file, "Cash",PlayerInfo[playerid][Cash] = 500);
        dini_IntSet(file, "Score",PlayerInfo[playerid][Score] = 0);
        dini_IntSet(file, "Job",PlayerInfo[playerid][Job] = 0);
        dini_IntSet(file, "Color",PlayerInfo[playerid][Color] = 0);
        dini_IntSet(file, "Vw",PlayerInfo[playerid][Vw] = 0);
        dini_IntSet(file, "Int",PlayerInfo[playerid][Int] = 0);
        dini_IntSet(file, "Warns",PlayerInfo[playerid][Warns] = 0);
        dini_IntSet(file, "Fleader",PlayerInfo[playerid][Fleader] = 0);
        dini_IntSet(file, "Fmember",PlayerInfo[playerid][Fmember] = 0);
        dini_IntSet(file, "Bank",PlayerInfo[playerid][Bank] = 0);
        dini_IntSet(file, "Prods",PlayerInfo[playerid][Prods] = 0);
        dini_IntSet(file, "Skin",PlayerInfo[playerid][Skin] = 0);
        dini_IntSet(file, "RepairOffer",PlayerInfo[playerid][RepairOffer] = 0);
        dini_IntSet(file, "Credit",PlayerInfo[playerid][Credit] = 0);
        dini_IntSet(file, "Spawn X", 0);
        dini_IntSet(file, "Spawn Y", 0);
        dini_IntSet(file, "Spawn Z", 0);
        dini_IntSet(file, "Spawn A", 0);
        dini_IntSet(file, "First login", 1);
        format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s, you have been auto logged in.", name, inputtext);
        SendClientMessage(playerid, 0xFF00CC, string);
        IsLogged[playerid] = 1;
    }
   
public OnPlayerDisconnect(playerid, reason)
{
    new name[24];
    GetPlayerName(playerid,name,24);
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Exists(file))
    {
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x, y, z);
        GetPlayerFacingAngle(playerid, a);
        dini_IntSet(file,"Cash",GetPlayerMoney(playerid));
        dini_IntSet(file,"Score",GetPlayerScore(playerid));
        dini_IntSet(file,"Color",GetPlayerColor(playerid));
        dini_IntSet(file,"AdminLevel",PlayerInfo[playerid][AdminLevel]);
        dini_IntSet(file,"Job",PlayerInfo[playerid][Job]);
        dini_IntSet(file,"Vw",GetPlayerVirtualWorld(playerid));
        dini_IntSet(file,"Int",GetPlayerInterior(playerid));
        dini_IntSet(file,"Warns",PlayerInfo[playerid][Warns]);
        dini_IntSet(file,"Fleader",PlayerInfo[playerid][Fleader]);
        dini_IntSet(file,"Fmember",PlayerInfo[playerid][Fmember]);
        dini_IntSet(file,"Bank",PlayerInfo[playerid][Bank]);
        dini_IntSet(file,"Prods",PlayerInfo[playerid][Prods]);
        dini_IntSet(file,"Skin",GetPlayerSkin(playerid));
        dini_IntSet(file,"RepairOffer",PlayerInfo[playerid][RepairOffer]);
        dini_IntSet(file,"Credit",PlayerInfo[playerid][Credit]);
        dini_IntSet(file, "Spawn X", x);
        dini_IntSet(file, "Spawn Y", y);
        dini_IntSet(file, "Spawn Z", z);
        dini_IntSet(file, "Spawn A", a);
        if(dini_Int(file, "First login") == 1) return dini_IntSet(file, "First login", 0);
        if(dini_Int(file, "First login") == 0) return dini_IntSet(file, "First login", 0);
        IsLogged[playerid] = 0;
        return 1;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new name[MAX_PLAYER_NAME], file[128];
    GetPlayerName(playerid,name,sizeof(name));
    format(file,sizeof(file),"RicAdmin/users/%s.ini",name);
    if(dini_Int(file, "First login") == 1) return SetPlayerPos(playerid, 1186.534301, -1830.901367, 13.297243);
    if(dini_Int(file, "First login") == 0) return SetPlayerPos(playerid,dini_Int(file, "Spawn X"), dini_Int(file, "Spawn Y"), dini_Int(file, "Spawn Z"));
    SetPlayerFacingAngle(playerid, dini_IntSet(file, "Spawn A"));
    return 1;
}
Reply
#9

I made a couple of functions for you. I've tested a little bit and it works fine.

IMPORTANT: You need to have a folder in your scriptfiles directory called "lastpos". If you don't your server will crash.

The following code has a couple of test commands if you remove them you can remove the zcmd include. Other than that it requires sscanf. Could have done it without but this was faster.

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

enum E_POSITION_DATA
{
    Float:e_fLastX,
    Float:e_fLastY,
    Float:e_fLastZ,
    Float:e_fLastAngle,
    e_iLastWorld,
    e_iLastInt,
};
new PositionData[MAX_PLAYERS][E_POSITION_DATA];

stock SaveLastPos(playerid)
{
    new
        File:PosFile,
        fOutput[64],
        FileDest[MAX_PLAYER_NAME + 64];
    GetPlayerPos(playerid, PositionData[playerid][e_fLastX], PositionData[playerid][e_fLastY], PositionData[playerid][e_fLastZ]);
    GetPlayerFacingAngle(playerid, PositionData[playerid][e_fLastAngle]);
    PositionData[playerid][e_iLastWorld] = GetPlayerVirtualWorld(playerid);
    PositionData[playerid][e_iLastWorld] = GetPlayerInterior(playerid);
    format(fOutput, sizeof(fOutput), "%f|%f|%f|%f|%d|%d",
        PositionData[playerid][e_fLastX],
        PositionData[playerid][e_fLastY],
        PositionData[playerid][e_fLastZ],
        PositionData[playerid][e_fLastAngle],
        PositionData[playerid][e_iLastWorld],
        PositionData[playerid][e_iLastInt]
    );
    GetPlayerName(playerid, FileDest, MAX_PLAYER_NAME);
    format(FileDest, sizeof(FileDest), "/lastpos/%s.txt", FileDest);
    PosFile = fopen(FileDest, io_write);
    fwrite(PosFile, fOutput);
    fclose(PosFile);
}

stock LoadLastPos(playerid)
{
    new
        File:PosFile,
        PosData[MAX_PLAYER_NAME + 64];
    GetPlayerName(playerid, PosData, MAX_PLAYER_NAME);
    format(PosData, sizeof(PosData), "/lastpos/%s.txt", PosData);
    if(fexist(PosData))
    {
        PosFile = fopen(PosData, io_read);
        fread(PosFile, PosData);
        fclose(PosFile);
        sscanf(PosData, "p<|>ffffdd",
            PositionData[playerid][e_fLastX],
            PositionData[playerid][e_fLastY],
            PositionData[playerid][e_fLastZ],
            PositionData[playerid][e_fLastAngle],
            PositionData[playerid][e_iLastWorld],
            PositionData[playerid][e_iLastInt]
        );
        SetPlayerPos(playerid, PositionData[playerid][e_fLastX], PositionData[playerid][e_fLastY], PositionData[playerid][e_fLastZ]);
        SetPlayerFacingAngle(playerid, PositionData[playerid][e_fLastAngle]);
        SetPlayerVirtualWorld(playerid, PositionData[playerid][e_iLastWorld]);
        SetPlayerInterior(playerid, PositionData[playerid][e_iLastInt]);
        SetCameraBehindPlayer(playerid);
    }
    else
    {
        //position not saved process as normal.
    }
}

COMMAND:savepos(playerid, params[])
{
    SaveLastPos(playerid);
    return 1;
}

COMMAND:loadpos(playerid, params[])
{
    LoadLastPos(playerid);
    return 1;
}
Reply
#10

Wesley, Your code has some warns...

Код:
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2375) : warning 213: tag mismatch
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2376) : warning 213: tag mismatch
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2377) : warning 213: tag mismatch
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2378) : warning 213: tag mismatch
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2394) : warning 219: local variable "file" shadows a variable at a preceding level
C:\Users\Ricardo\Desktop\Script-Programaзгo\Script SA-MP\RPG Project\RPGProject\RPGProject\gamemodes\RPGProject.pwn(2399) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


6 Warnings.
Lines:
pawn Код:
dini_IntSet(file, "Spawn X", x);
        dini_IntSet(file, "Spawn Y", y);
        dini_IntSet(file, "Spawn Z", z);
        dini_IntSet(file, "Spawn A", a);
AND
new name[MAX_PLAYER_NAME], file[128];
AND
SetPlayerFacingAngle(playerid, dini_IntSet(file, "Spawn A"));
Thank you.

Iggy, I think that your code will nto save it on the disconnect/connect... I will use your code for a /savepos and /loadpos script.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)