SA-MP Forums Archive
How do i save health in file? - 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)
+--- Thread: How do i save health in file? (/showthread.php?tid=339400)



How do i save health in file? - wilko1995 - 03.05.2012

Hello, Ive been trying to save my players health in his file using the following

Код:
public OnPlayerDisconnect(playerid, reason)
{
	new Float:health, Float:armour, Name[MAX_PLAYER_NAME], File[256];
	GetPlayerName(playerid, Name, sizeof(Name));
	format(File, sizeof(File), PFile, Name);
	if(PInfo[playerid][Logged] == 1)
	{
		dini_IntSet(File, "Health", GetPlayerHealth(playerid,health));
		dini_IntSet(File, "Armour", GetPlayerArmour(playerid, armour));
		return 1;
	}
	return 1;
}
but it saves the health as 1 and the armour as one what ever the health or armour may be.. so even if its full when he leaves it still saves as one. Please help


Re: How do i save health in file? - JaTochNietDan - 03.05.2012

The functions GetPlayerHealth and SetPlayerHealth don't return the values, they store them in the second argument you pass into the function, in this case it is "health" and "armour", so that is what you should be writing to the files.

Also for your information, they are floats, not integers.

Example:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new Float:health, Float:armour, Name[MAX_PLAYER_NAME], File[256];
    GetPlayerName(playerid, Name, sizeof(Name));
    format(File, sizeof(File), PFile, Name);
    if(PInfo[playerid][Logged] == 1)
    {
        GetPlayerHealth(playerid,health); // Store the players health in the float "health"
        GetPlayerArmour(playerid, armour); // Store the players armour in the float "armour"
        dini_FloatSet(File, "Health", health); // Set the float in the file to the value of the float "health"
        dini_FloatSet(File, "Armour", armour); // Set the float in the file to the value of the float "armour"
        return 1; // Also this return is pointless.
    }
    return 1;
}
Hope that helps.


Re: How do i save health in file? - wilko1995 - 03.05.2012

Awesome it work thank you so much for your help and quick reply. + Rep