SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 23/08/2011, 03:59 PM   #1
Wesley221
High-roller
 
Wesley221's Avatar
 
Join Date: Apr 2011
Posts: 2,730
Reputation: 714
Default Saving files

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?
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
__________________
yes
Wesley221 is offline  
Old 23/08/2011, 06:33 PM   #2
Wesley221
High-roller
 
Wesley221's Avatar
 
Join Date: Apr 2011
Posts: 2,730
Reputation: 714
Default Re: Saving files

Bump - cant really continue without this
__________________
yes
Wesley221 is offline  
Old 23/08/2011, 09:36 PM   #3
uprp
Big Clucker
 
uprp's Avatar
 
Join Date: Aug 2011
Location: Lolhi
Posts: 169
Reputation: 11
Default Respuesta: Saving files

Try this.
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.
__________________
If i helped you, why not hand me a +rep? Thanks.
Epic server[30 playerbase..Daily!]:
Click me to play United Parliament Roleplay.. 50 Members!


_____
My stuff:

Tutorial: How to add maps to your server
http://forum.sa-mp.com/showthread.php?p=1373974

__________
http://www.trrsa.tk
uprp is offline  
Old 24/08/2011, 09:34 AM   #4
Wesley221
High-roller
 
Wesley221's Avatar
 
Join Date: Apr 2011
Posts: 2,730
Reputation: 714
Default Re: Respuesta: Saving files

Quote:
Originally Posted by uprp View Post
Try this.
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
__________________
yes
Wesley221 is offline  
Old 24/08/2011, 10:50 AM   #5
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,521
Reputation: 2927
Default Re: Saving files

Ahh! I know why! You can't have spaces in key names - make "weapon 0" in to "weapon_0" for example. I really should document this fact as I keep forgetting.
Y_Less is offline  
Old 24/08/2011, 11:05 AM   #6
Wesley221
High-roller
 
Wesley221's Avatar
 
Join Date: Apr 2011
Posts: 2,730
Reputation: 714
Default Re: Saving files

Ah-ha!
Now it works the right way
Thanks
__________________
yes
Wesley221 is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restarting & Saving player files Skylar Paul Help Archive 4 12/03/2011 01:09 AM
Saving text into files then loading them up afterwards Cardinaal Help Archive 7 10/04/2010 05:00 PM
Saving something in Files (i thing its simple , but i cant) mirkoiz Help Archive 2 02/06/2009 10:12 PM


All times are GMT. The time now is 01:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.