Saving problem
#1

I am using YSI to save my accounts, but I am having a problem, ever since I been trying to make it so I can save a gun on log out, the thing is whenever I /q i always log back in about 2 mins before I logged out, I have a timer on a loop going every second that calls the function SaveAccountStats I also have this function under onplayerdisconnect

Here is the code for my function
so my question is is why don't my guns save, and why don't my stats update everysecond considering I have a repeating timer that calls this function every second.
I log out and I am where I was 2 mins before I logged out.
pawn Код:
function SaveAccountStats(playerid)
{
    if(Logged[playerid] == 1)
    {
    new
        INI:File = INI_Open(UserPath(playerid))
    ;
    INI_SetTag(File,"data");
   
    PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
    PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid);

    new
        Float:x,
        Float:y,
        Float:z,
        guns[13][2]
    ;

    GetPlayerPos(playerid,x,y,z);
    PlayerInfo[playerid][pPos_x] = x;
    PlayerInfo[playerid][pPos_y] = y;
    PlayerInfo[playerid][pPos_z] = z;
    for (new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, guns[i][0], guns[i][1]);
    }
    PlayerInfo[playerid][pGun2] = guns[2][0];
    PlayerInfo[playerid][pGun3] = guns[3][0];
    PlayerInfo[playerid][pGun4] = guns[4][0];
    PlayerInfo[playerid][pGun5] = guns[5][0];
    PlayerInfo[playerid][pGun6] = guns[6][0];
   
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]);
    INI_WriteInt(File, "Job",PlayerInfo[playerid][pJob]);
    INI_WriteInt(File, "Dlvpkg",PlayerInfo[playerid][pDlvpkg]);
    INI_WriteInt(File, "Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File, "Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File, "Dead",PlayerInfo[playerid][pDead]);
    INI_WriteInt(File, "Cop",PlayerInfo[playerid][pCop]);
    INI_WriteInt(File, "Leader",PlayerInfo[playerid][pLeader]);
    INI_WriteInt(File,"GunPermit",PlayerInfo[playerid][pGunPermit]);
    INI_WriteInt(File,"Politician",PlayerInfo[playerid][pPolitician]);
    INI_WriteInt(File,"Bank",PlayerInfo[playerid][pBank]);
    INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
    INI_WriteInt(File,"Hours",PlayerInfo[playerid][pHours]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"ScrapMetal", PlayerInfo[playerid][pScrapMetal]);
    INI_WriteInt(File,"Wtest", PlayerInfo[playerid][pWtest]);
    INI_WriteInt(File,"Dtest",PlayerInfo[playerid][pDtest]);
    INI_WriteInt(File,"Car", PlayerInfo[playerid][pCar]);
    INI_WriteFloat(File,"CarPos_x", PlayerInfo[playerid][pCarPos_x]);
    INI_WriteFloat(File,"CarPos_y", PlayerInfo[playerid][pCarPos_y]);
    INI_WriteFloat(File,"CarPos_z", PlayerInfo[playerid][pCarPos_z]);
    INI_WriteFloat(File,"CarPos_a", PlayerInfo[playerid][pCarPos_a]);
    INI_WriteInt(File,"CarID", PlayerInfo[playerid][pCarID]);
    INI_WriteInt(File,"RadioFreq", PlayerInfo[playerid][pRadioFreq]);
    INI_WriteInt(File,"Radio",PlayerInfo[playerid][pRadio]);
    INI_WriteInt(File,"Gun1",PlayerInfo[playerid][pGun1]);
    INI_WriteInt(File,"Gun2",PlayerInfo[playerid][pGun2]);
    INI_WriteInt(File,"Gun3",PlayerInfo[playerid][pGun3]);
    INI_WriteInt(File,"Gun4",PlayerInfo[playerid][pGun4]);
    INI_WriteInt(File,"Gun5",PlayerInfo[playerid][pGun5]);
    INI_WriteInt(File,"Gun6",PlayerInfo[playerid][pGun6]);
    INI_Close(File);
    }
    return 1;
}
Reply
#2

You have to use GetPlayerWeaponData for each weapon and assign it to the vars used for your saving system. This is how I implement saving of guns in my game mode.

pawn Код:
new ammo;
public SaveAccount(playerid) // Saving
{
    GetPlayerWeaponData(playerid,1,pInfo[playerid][pGun1],ammo);
    GetPlayerWeaponData(playerid,2,pInfo[playerid][pGun2],ammo);
    GetPlayerWeaponData(playerid,3,pInfo[playerid][pGun3],ammo);
    GetPlayerWeaponData(playerid,4,pInfo[playerid][pGun4],ammo);
    GetPlayerWeaponData(playerid,5,pInfo[playerid][pGun5],ammo);
    GetPlayerWeaponData(playerid,6,pInfo[playerid][pGun6],ammo);
    GetPlayerWeaponData(playerid,7,pInfo[playerid][pGun7],ammo);
    GetPlayerWeaponData(playerid,8,pInfo[playerid][pGun8],ammo);
    GetPlayerWeaponData(playerid,9,pInfo[playerid][pGun9],ammo);
    GetPlayerWeaponData(playerid,10,pInfo[playerid][pGun10],ammo);
    GetPlayerWeaponData(playerid,11,pInfo[playerid][pGun11],ammo);
    GetPlayerWeaponData(playerid,12,pInfo[playerid][pGun12],ammo);
    new
        Float:x = pInfo[playerid][pPosX],
        Float:y = pInfo[playerid][pPosY],
        Float:z = pInfo[playerid][pPosZ],
        Float:a = pInfo[playerid][pAngle],
        Float:h = pInfo[playerid][pHealth],
       Float:ar = pInfo[playerid][pArmour];

    GetPlayerPos(playerid,x,y,z);
    pInfo[playerid][pAngle] = GetPlayerFacingAngle(playerid,a);
    pInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    pInfo[playerid][pHealth] = GetPlayerHealth(playerid,h);
    pInfo[playerid][pArmour] = GetPlayerArmour(playerid,ar);
    pInfo[playerid][pInterior] = GetPlayerInterior(playerid);
    pInfo[playerid][pVW] = GetPlayerVirtualWorld(playerid);
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Bank",pInfo[playerid][pBank]);
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Faction",pInfo[playerid][pFaction]);
    INI_WriteInt(File,"OnDuty",pInfo[playerid][pDuty]);
    INI_WriteInt(File,"Rank",pInfo[playerid][pRank]);
    INI_WriteInt(File,"Leader",pInfo[playerid][pLeader]);
    INI_WriteInt(File,"Job",pInfo[playerid][pJob]);
    INI_WriteInt(File,"Mats",pInfo[playerid][pMats]);
    INI_WriteInt(File,"Crack",pInfo[playerid][pCrack]);
    INI_WriteInt(File,"HasInvite",pInfo[playerid][pHasInvite]);
    INI_WriteInt(File,"CanKill",pInfo[playerid][pCanKill]);
    INI_WriteInt(File,"Skin",pInfo[playerid][pSkin]);
    INI_WriteFloat(File,"LastX",x);
    INI_WriteFloat(File,"LastY",y);
    INI_WriteFloat(File,"LastZ",z);
    INI_WriteFloat(File,"Angle",a);
    INI_WriteFloat(File,"Health",h);
    INI_WriteFloat(File,"Armour",ar);
    INI_WriteInt(File,"AdminLevel",pInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Accent",pInfo[playerid][pAccent]);
    INI_WriteInt(File,"Jailed",pInfo[playerid][pJailed]);
    INI_WriteInt(File,"JailTime",pInfo[playerid][pJailTime]);
    INI_WriteInt(File,"Gun1",pInfo[playerid][pGun1]);
    INI_WriteInt(File,"Gun2",pInfo[playerid][pGun2]);
    INI_WriteInt(File,"Gun3",pInfo[playerid][pGun3]);
    INI_WriteInt(File,"Gun4",pInfo[playerid][pGun4]);
    INI_WriteInt(File,"Gun5",pInfo[playerid][pGun5]);
    INI_WriteInt(File,"Gun6",pInfo[playerid][pGun6]);
    INI_WriteInt(File,"Gun7",pInfo[playerid][pGun7]);
    INI_WriteInt(File,"Gun8",pInfo[playerid][pGun8]);
    INI_WriteInt(File,"Gun9",pInfo[playerid][pGun9]);
    INI_WriteInt(File,"Gun10",pInfo[playerid][pGun10]);
    INI_WriteInt(File,"Gun11",pInfo[playerid][pGun11]);
    INI_WriteInt(File,"Gun12",pInfo[playerid][pGun12]);
    INI_WriteInt(File,"Interior",pInfo[playerid][pInterior]);
    INI_WriteInt(File,"VirtualWorld",pInfo[playerid][pVW]);
    INI_WriteInt(File,"Cuffed",pInfo[playerid][pCuffed]);
    INI_Close(File);
    return 1;
}





stock LoadUserWeapons(playerid,name[],value[]) // Loading
{
    INI_Int("Gun1",pInfo[playerid][pGun1]);
    INI_Int("Gun2",pInfo[playerid][pGun2]);
    INI_Int("Gun3",pInfo[playerid][pGun3]);
    INI_Int("Gun4",pInfo[playerid][pGun4]);
    INI_Int("Gun5",pInfo[playerid][pGun5]);
    INI_Int("Gun6",pInfo[playerid][pGun6]);
    INI_Int("Gun7",pInfo[playerid][pGun7]);
    INI_Int("Gun8",pInfo[playerid][pGun8]);
    INI_Int("Gun9",pInfo[playerid][pGun9]);
    INI_Int("Gun10",pInfo[playerid][pGun10]);
    INI_Int("Gun11",pInfo[playerid][pGun11]);
    INI_Int("Gun12",pInfo[playerid][pGun12]);
    return 1;
}


public OnPlayerSpawn(playerid) // Gives them the guns on spawn
{
   
    if(pInfo[playerid][pPosX] == 0)
    {
        SetPlayerPos(playerid,2102.6221,-104.2249,2.2702);
        SetPlayerSkin(playerid,299);
        SetPlayerHealth(playerid,100);
        SetCameraBehindPlayer(playerid);
        SetPlayerFacingAngle(playerid,304.6372);
        GivePlayerMoney(playerid,10000);
        pInfo[playerid][pBank] = 20000;
        TogglePlayerControllable(playerid,1);
    }
    else
    {
        SetPlayerPos(playerid,pInfo[playerid][pPosX],pInfo[playerid][pPosY],pInfo[playerid][pPosZ]);
        SetPlayerSkin(playerid,pInfo[playerid][pSkin]);
        SetPlayerFacingAngle(playerid,pInfo[playerid][pAngle]);
        SetPlayerHealth(playerid,pInfo[playerid][pHealth]);
        SetPlayerArmour(playerid,pInfo[playerid][pArmour]);
        SetPlayerVirtualWorld(playerid,pInfo[playerid][pVW]);
        SetPlayerInterior(playerid,pInfo[playerid][pInterior]);
        GivePlayerMoney(playerid,pInfo[playerid][pCash]);
        SetCameraBehindPlayer(playerid);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun1],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun2],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun3],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun4],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun5],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun6],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun7],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun8],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun9],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun10],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun11],999999);
        GivePlayerWeapon(playerid,pInfo[playerid][pGun12],999999);
        TogglePlayerControllable(playerid,1);
    }
EDIT: Nevermind took me awhile to see that you already did.
Reply
#3

So why isn't the guns saving and why is it when I relog I loose the things I gained in the last 2 mins I was playing
Reply
#4

Try going IG. Get a gun, then log out. From there go to your User.ini file and post it here. This can help you determine where your problem is.
Reply
#5

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Try going IG. Get a gun, then log out. From there go to your User.ini file and post it here. This can help you determine where your problem is.
They are not saving to the INI file. everything else is though, I fixed the issue with the delayed saving though
Reply
#6

Have you made the path in your scripfiles at all?
Reply
#7

Of course I have... Everything saves fine, except the weapons...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)