Saving and loading (playerid, health)
#1

Hi there, I'm new to pawno coding and I decided to save/load a player's health and armor using dini, but now i'm having a problem. The info saves only when the player disconnects, so if a new player registers on the server, they die all the time.

Here is the code for... public OnPlayerDisconnect(playerid, reason)

Код:
public OnPlayerDisconnect(playerid, reason)
{
	new file[128], pname[MAX_PLAYER_NAME];
	new Float:x, Float:y, Float:z, Float:ang,Float:health,Float:armour;
	GetPlayerName(playerid, pname, sizeof(pname));
	format(file, sizeof(file), "PlayerInfo/%s.ini", pname);
	if(!dini_Exists(file))
	dini_Create(file);
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, ang);
	GetPlayerHealth(playerid, health);
	GetPlayerArmour(playerid, armour);
	dini_FloatSet(file, "PosX", x);
	dini_FloatSet(file, "PosY", y);
	dini_FloatSet(file, "PosZ", z);
	dini_FloatSet(file, "Angle", ang);
	dini_FloatSet(file, "Health", health);
	dini_FloatSet(file, "Armour", armour);
	dini_IntSet(file, "Skin", GetPlayerSkin(playerid));
	dini_IntSet(file, "Interior", GetPlayerInterior(playerid));
	dini_IntSet(file, "VirtualWorld", GetPlayerVirtualWorld(playerid));
	dini_IntSet(file, "Money", GetPlayerMoney(playerid));
	dini_IntSet(file, "WantedLevel", GetPlayerWantedLevel(playerid));
	dini_IntSet(file, "FightingStyle", GetPlayerFightingStyle(playerid));
	dini_IntSet(file, "Level", GetPlayerScore(playerid));
	return 1;
}
And here is the code for... public OnPlayerSpawn(playerid)

Код:
public OnPlayerSpawn(playerid)
{
	new file[128], pname[MAX_PLAYER_NAME];
	new Float:x, Float:y, Float:z, Float:ang, Float:health, Float:armour;
	GetPlayerName(playerid, pname, sizeof(pname));

	format(file, sizeof(file), "PlayerInfo/%s.ini", pname);
	x = dini_Float(file, "posX");
	y = dini_Float(file, "posY");
	z = dini_Float(file, "posZ");
	ang = dini_Float(file, "Angle");
	health = dini_Float(file, "Health");
	armour = dini_Float(file, "Armour");

	SetPlayerPos(playerid, x, y, z);
	SetPlayerFacingAngle(playerid, ang);
	SetPlayerHealth(playerid, health);
	SetPlayerArmour(playerid, armour);
	SetPlayerSkin(playerid, dini_Int(file, "Skin"));
	SetPlayerInterior(playerid, dini_Int(file, "Interior"));
	SetPlayerVirtualWorld(playerid, dini_Int(file, "VirtualWorld"));
	SetPlayerMoney(playerid, dini_Int(file, "Money"));
	SetPlayerWantedLevel(playerid, dini_Int(file, "WantedLevel"));
	SetPlayerFightingStyle(playerid, dini_Int(file, "FightingStyle"));
	SetPlayerScore(playerid, dini_Int(file, "Level"));
	return 1;
}
Any ideas would be appreciated
Reply


Messages In This Thread
Saving and loading (playerid, health) - by Hyperfire - 20.08.2012, 23:42
Re: Saving and loading (playerid, health) - by detter - 20.08.2012, 23:51
Re: Saving and loading (playerid, health) - by Hyperfire - 21.08.2012, 00:46

Forum Jump:


Users browsing this thread: 1 Guest(s)