SA-MP Forums Archive
Saving files - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Saving files (/showthread.php?tid=278693)



Saving files - Wesley221 - 23.08.2011

Hey guys,

Again my files arent saving the right way.
http://pastebin.com/nX3FHRT5
The first things are when you register. Then when you save your files (log out), it doesnt overwrite the existing lines, but just creates new lines with a value in it. How can i fix this?
pawn Code:
forward SaveStats(playerid);
public SaveStats(playerid) // CONTAINS BUGGING INFORMATION
{
    new INI:file = INI_Open(UserPath(playerid));
    INI_SetTag(file, "data");
    INI_WriteInt(file, "Money", PlayerInfo[playerid][pMoney]); printf("Saved money %s", GetName(playerid));
    INI_WriteInt(file, "Score", PlayerInfo[playerid][pScore]); printf("Saved score %s", GetName(playerid));
    INI_WriteInt(file, "Admin level", PlayerInfo[playerid][pAdmin]); printf("Saved admin level %s", GetName(playerid));
    INI_WriteInt(file, "Vip level", PlayerInfo[playerid][pVip]); printf("Saved vip level %s", GetName(playerid));
    INI_WriteInt(file, "Commands used", PlayerInfo[playerid][pCMD]); printf("Saved commands used %s", GetName(playerid));
    INI_SetTag(file, "kills");      // kills tag
    INI_WriteInt(file, "RKills", PlayerInfo[playerid][pRKills]); printf("Saved last round kills %s", GetName(playerid));
    INI_WriteInt(file, "RDeaths", PlayerInfo[playerid][pRDeaths]); printf("Saved last round deaths %s", GetName(playerid));
    INI_WriteInt(file, "RKD", PlayerInfo[playerid][pRKd]); printf("Saved last round kd %s", GetName(playerid));
    INI_WriteInt(file, "Kills", PlayerInfo[playerid][pKills]); printf("Saved total kills %s", GetName(playerid));
    INI_WriteInt(file, "Deaths", PlayerInfo[playerid][pDeaths]); printf("Saved total deaths %s", GetName(playerid));
    INI_WriteInt(file, "KD", PlayerInfo[playerid][pKd]); printf("Saved total kd %s", GetName(playerid));
    INI_SetTag(file, "weapons");        // weapons tag
    INI_WriteInt(file, "Weapon 0", WeaponInfo[playerid][pWeapon0]); printf("Saved Weaponinfo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1", WeaponInfo[playerid][pWeapon1]); printf("Saved Weaponinfo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2", WeaponInfo[playerid][pWeapon2]); printf("Saved Weaponinfo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3", WeaponInfo[playerid][pWeapon3]); printf("Saved Weaponinfo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4", WeaponInfo[playerid][pWeapon4]); printf("Saved Weaponinfo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5", WeaponInfo[playerid][pWeapon5]); printf("Saved Weaponinfo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6", WeaponInfo[playerid][pWeapon6]); printf("Saved Weaponinfo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7", WeaponInfo[playerid][pWeapon7]); printf("Saved Weaponinfo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8", WeaponInfo[playerid][pWeapon8]); printf("Saved Weaponinfo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9", WeaponInfo[playerid][pWeapon9]); printf("Saved Weaponinfo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10", WeaponInfo[playerid][pWeapon10]); printf("Saved Weaponinfo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11", WeaponInfo[playerid][pWeapon11]); printf("Saved Weaponinfo11 %s", GetName(playerid));
    INI_SetTag(file, "weapons ammo");       // ammo tag
    INI_WriteInt(file, "Weapon 0 ammo", WeaponInfo[playerid][pAmmo0]); printf("Saved Weaponammo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1 ammo", WeaponInfo[playerid][pAmmo1]); printf("Saved Weaponammo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2 ammo", WeaponInfo[playerid][pAmmo2]); printf("Saved Weaponammo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3 ammo", WeaponInfo[playerid][pAmmo3]); printf("Saved Weaponammo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4 ammo", WeaponInfo[playerid][pAmmo4]); printf("Saved Weaponammo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5 ammo", WeaponInfo[playerid][pAmmo5]); printf("Saved Weaponammo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6 ammo", WeaponInfo[playerid][pAmmo6]); printf("Saved Weaponammo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7 ammo", WeaponInfo[playerid][pAmmo7]); printf("Saved Weaponammo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8 ammo", WeaponInfo[playerid][pAmmo8]); printf("Saved Weaponammo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9 ammo", WeaponInfo[playerid][pAmmo9]); printf("Saved Weaponammo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10 ammo", WeaponInfo[playerid][pAmmo10]); printf("Saved Weaponammo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11 ammo", WeaponInfo[playerid][pAmmo11]); printf("Saved Weaponammo11 %s", GetName(playerid));
    INI_Close(file);
    return 1;
}
This gets called at OnPlayerDisconnect
As you can see the variables contain information, so that isnt the problem. It also has the INI_SetTag, and its all the same!
~Wesley


Re: Saving files - Wesley221 - 23.08.2011

Bump - cant really continue without this


Respuesta: Saving files - uprp - 23.08.2011

Try this.
pawn Code:
forward SavePlayerStats(playerid);
public SavePlayerStats(playerid) // CONTAINS BUGGING INFORMATION
{
    new INI:file = INI_Open(UserPath(playerid));
    INI_SetTag(file, "data");
    INI_WriteInt(file, "Money", PlayerInfo[playerid][pMoney]); printf("Saved money %s", GetName(playerid));
    INI_WriteInt(file, "Score", PlayerInfo[playerid][pScore]); printf("Saved score %s", GetName(playerid));
    INI_WriteInt(file, "Admin level", PlayerInfo[playerid][pAdmin]); printf("Saved admin level %s", GetName(playerid));
    INI_WriteInt(file, "Vip level", PlayerInfo[playerid][pVip]); printf("Saved vip level %s", GetName(playerid));
    INI_WriteInt(file, "Commands used", PlayerInfo[playerid][pCMD]); printf("Saved commands used %s", GetName(playerid));
    INI_SetTag(file, "kills");      // kills tag
    INI_WriteInt(file, "RKills", PlayerInfo[playerid][pRKills]); printf("Saved last round kills %s", GetName(playerid));
    INI_WriteInt(file, "RDeaths", PlayerInfo[playerid][pRDeaths]); printf("Saved last round deaths %s", GetName(playerid));
    INI_WriteInt(file, "RKD", PlayerInfo[playerid][pRKd]); printf("Saved last round kd %s", GetName(playerid));
    INI_WriteInt(file, "Kills", PlayerInfo[playerid][pKills]); printf("Saved total kills %s", GetName(playerid));
    INI_WriteInt(file, "Deaths", PlayerInfo[playerid][pDeaths]); printf("Saved total deaths %s", GetName(playerid));
    INI_WriteInt(file, "KD", PlayerInfo[playerid][pKd]); printf("Saved total kd %s", GetName(playerid));
    INI_SetTag(file, "weapons");        // weapons tag
    INI_WriteInt(file, "Weapon 0", WeaponInfo[playerid][pWeapon0]); printf("Saved Weaponinfo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1", WeaponInfo[playerid][pWeapon1]); printf("Saved Weaponinfo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2", WeaponInfo[playerid][pWeapon2]); printf("Saved Weaponinfo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3", WeaponInfo[playerid][pWeapon3]); printf("Saved Weaponinfo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4", WeaponInfo[playerid][pWeapon4]); printf("Saved Weaponinfo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5", WeaponInfo[playerid][pWeapon5]); printf("Saved Weaponinfo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6", WeaponInfo[playerid][pWeapon6]); printf("Saved Weaponinfo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7", WeaponInfo[playerid][pWeapon7]); printf("Saved Weaponinfo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8", WeaponInfo[playerid][pWeapon8]); printf("Saved Weaponinfo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9", WeaponInfo[playerid][pWeapon9]); printf("Saved Weaponinfo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10", WeaponInfo[playerid][pWeapon10]); printf("Saved Weaponinfo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11", WeaponInfo[playerid][pWeapon11]); printf("Saved Weaponinfo11 %s", GetName(playerid));
    INI_SetTag(file, "weapons ammo");       // ammo tag
    INI_WriteInt(file, "Weapon 0 ammo", WeaponInfo[playerid][pAmmo0]); printf("Saved Weaponammo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1 ammo", WeaponInfo[playerid][pAmmo1]); printf("Saved Weaponammo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2 ammo", WeaponInfo[playerid][pAmmo2]); printf("Saved Weaponammo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3 ammo", WeaponInfo[playerid][pAmmo3]); printf("Saved Weaponammo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4 ammo", WeaponInfo[playerid][pAmmo4]); printf("Saved Weaponammo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5 ammo", WeaponInfo[playerid][pAmmo5]); printf("Saved Weaponammo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6 ammo", WeaponInfo[playerid][pAmmo6]); printf("Saved Weaponammo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7 ammo", WeaponInfo[playerid][pAmmo7]); printf("Saved Weaponammo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8 ammo", WeaponInfo[playerid][pAmmo8]); printf("Saved Weaponammo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9 ammo", WeaponInfo[playerid][pAmmo9]); printf("Saved Weaponammo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10 ammo", WeaponInfo[playerid][pAmmo10]); printf("Saved Weaponammo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11 ammo", WeaponInfo[playerid][pAmmo11]); printf("Saved Weaponammo11 %s", GetName(playerid));
    INI_Close(file);
    return 1;
}

Please repme if i helped.

Also try SaveServerStats.


Re: Respuesta: Saving files - Wesley221 - 24.08.2011

Quote:
Originally Posted by uprp
View Post
Try this.
pawn Code:
forward SavePlayerStats(playerid);
public SavePlayerStats(playerid) // CONTAINS BUGGING INFORMATION
{
    new INI:file = INI_Open(UserPath(playerid));
    INI_SetTag(file, "data");
    INI_WriteInt(file, "Money", PlayerInfo[playerid][pMoney]); printf("Saved money %s", GetName(playerid));
    INI_WriteInt(file, "Score", PlayerInfo[playerid][pScore]); printf("Saved score %s", GetName(playerid));
    INI_WriteInt(file, "Admin level", PlayerInfo[playerid][pAdmin]); printf("Saved admin level %s", GetName(playerid));
    INI_WriteInt(file, "Vip level", PlayerInfo[playerid][pVip]); printf("Saved vip level %s", GetName(playerid));
    INI_WriteInt(file, "Commands used", PlayerInfo[playerid][pCMD]); printf("Saved commands used %s", GetName(playerid));
    INI_SetTag(file, "kills");      // kills tag
    INI_WriteInt(file, "RKills", PlayerInfo[playerid][pRKills]); printf("Saved last round kills %s", GetName(playerid));
    INI_WriteInt(file, "RDeaths", PlayerInfo[playerid][pRDeaths]); printf("Saved last round deaths %s", GetName(playerid));
    INI_WriteInt(file, "RKD", PlayerInfo[playerid][pRKd]); printf("Saved last round kd %s", GetName(playerid));
    INI_WriteInt(file, "Kills", PlayerInfo[playerid][pKills]); printf("Saved total kills %s", GetName(playerid));
    INI_WriteInt(file, "Deaths", PlayerInfo[playerid][pDeaths]); printf("Saved total deaths %s", GetName(playerid));
    INI_WriteInt(file, "KD", PlayerInfo[playerid][pKd]); printf("Saved total kd %s", GetName(playerid));
    INI_SetTag(file, "weapons");        // weapons tag
    INI_WriteInt(file, "Weapon 0", WeaponInfo[playerid][pWeapon0]); printf("Saved Weaponinfo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1", WeaponInfo[playerid][pWeapon1]); printf("Saved Weaponinfo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2", WeaponInfo[playerid][pWeapon2]); printf("Saved Weaponinfo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3", WeaponInfo[playerid][pWeapon3]); printf("Saved Weaponinfo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4", WeaponInfo[playerid][pWeapon4]); printf("Saved Weaponinfo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5", WeaponInfo[playerid][pWeapon5]); printf("Saved Weaponinfo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6", WeaponInfo[playerid][pWeapon6]); printf("Saved Weaponinfo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7", WeaponInfo[playerid][pWeapon7]); printf("Saved Weaponinfo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8", WeaponInfo[playerid][pWeapon8]); printf("Saved Weaponinfo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9", WeaponInfo[playerid][pWeapon9]); printf("Saved Weaponinfo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10", WeaponInfo[playerid][pWeapon10]); printf("Saved Weaponinfo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11", WeaponInfo[playerid][pWeapon11]); printf("Saved Weaponinfo11 %s", GetName(playerid));
    INI_SetTag(file, "weapons ammo");       // ammo tag
    INI_WriteInt(file, "Weapon 0 ammo", WeaponInfo[playerid][pAmmo0]); printf("Saved Weaponammo0 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 1 ammo", WeaponInfo[playerid][pAmmo1]); printf("Saved Weaponammo1 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 2 ammo", WeaponInfo[playerid][pAmmo2]); printf("Saved Weaponammo2 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 3 ammo", WeaponInfo[playerid][pAmmo3]); printf("Saved Weaponammo3 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 4 ammo", WeaponInfo[playerid][pAmmo4]); printf("Saved Weaponammo4 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 5 ammo", WeaponInfo[playerid][pAmmo5]); printf("Saved Weaponammo5 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 6 ammo", WeaponInfo[playerid][pAmmo6]); printf("Saved Weaponammo6 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 7 ammo", WeaponInfo[playerid][pAmmo7]); printf("Saved Weaponammo7 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 8 ammo", WeaponInfo[playerid][pAmmo8]); printf("Saved Weaponammo8 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 9 ammo", WeaponInfo[playerid][pAmmo9]); printf("Saved Weaponammo9 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 10 ammo", WeaponInfo[playerid][pAmmo10]); printf("Saved Weaponammo10 %s", GetName(playerid));
    INI_WriteInt(file, "Weapon 11 ammo", WeaponInfo[playerid][pAmmo11]); printf("Saved Weaponammo11 %s", GetName(playerid));
    INI_Close(file);
    return 1;
}

Please repme if i helped.

Also try SaveServerStats.
It wont make any difference if you just rename the function. It DOES save, just not the right way


Re: Saving files - Wesley221 - 24.08.2011

Ah-ha!
Now it works the right way
Thanks