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

Well... if user is newly registered that meas that he does not have .ini
so you need ,before giving player stats ,check if he is registered ,and if he is not reg. you create his .ini file and store in there all variables you need ,and then you load that but you need to put that onplayerspawn or OnPlayerConnect...
Reply
#3

Thanx for the quick reply, I tried it, at first I struggled but in the end you helped me solve more then one problem in my script, thanx alot

[Rep+] for you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)