SA-MP Forums Archive
Saving and loading (playerid, health) - 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: Saving and loading (playerid, health) (/showthread.php?tid=370704)



Saving and loading (playerid, health) - Hyperfire - 20.08.2012

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


Re: Saving and loading (playerid, health) - detter - 20.08.2012

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...


Re: Saving and loading (playerid, health) - Hyperfire - 21.08.2012

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