How do i save health in file?
#1

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
Reply
#2

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.
Reply
#3

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


Forum Jump:


Users browsing this thread: 1 Guest(s)