Save/Load Positions
#2

This is the one i made it also saves the player's skin

Code:
#define FILTERSCRIPT

#include <a_samp>
#include <Dini>
#include <dudb>

new Float:positionx;
new Float:positiony;
new Float:positionz;
new skin;

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Position saver by Jueix");
	print("--------------------------------------\n");
	return 1;
}

public OnPlayerConnect(playerid)
{
	LoadStats(playerid);
	return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
	new Float:x;
	new Float:y;
	new Float:z;

	GetPlayerPos(playerid,x,y,z);
	skin = GetPlayerSkin(playerid);
	positionx = x;
	positiony = y;
	positionz = z;
	if (!dini_Exists(Pos(playerid)))
	{
		dini_Create(Pos(playerid));
	}

	SaveStats(playerid);
	return 1;
}

public OnPlayerSpawn(playerid)
{
	if (!dini_Exists(Pos(playerid))) {
	SetPlayerPos(playerid, 1676.8462, 1447.7908, 10.7833); //change to coords on players first login / register
	}
	else
	{
	SetPlayerPos(playerid, positionx,positiony,positionz);
	SetPlayerSkin(playerid,skin);
	}
	return 1;
}

Player(playerid)
{
 new player[MAX_PLAYER_NAME];
 GetPlayerName(playerid, player, sizeof(player));
 return player;
}

Pos(playerid)
{
  new a[256]; format(a, sizeof(a), "%s.ini",udb_encode(Player(playerid)));
  return a;
}

SaveStats(playerid)
{
  dini_IntSet(Pos(playerid), "PositionX", floatround(positionx));
  dini_IntSet(Pos(playerid), "PositionY", floatround(positiony));
  dini_IntSet(Pos(playerid), "PositionZ", floatround(positionz));
  dini_IntSet(Pos(playerid), "skin", (skin));
}

LoadStats(playerid)
{
  positionx = dini_Int(Pos(playerid), "PositionX");
  positiony = dini_Int(Pos(playerid), "PositionY");
  positionz = dini_Int(Pos(playerid), "PositionZ");
  skin = dini_Int(Pos(playerid), "skin");
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	print("\n----------------------------------");
	print(" Blank Gamemode by Jueix");
	print("----------------------------------\n");
}

#endif
Hope this helped.
Reply


Messages In This Thread
Save/Load Positions - by MarcoWesley - 07.06.2012, 14:10
Re: Save/Load Positions - by jueix - 07.06.2012, 14:28
Re: Save/Load Positions - by MarcoWesley - 07.06.2012, 15:36

Forum Jump:


Users browsing this thread: 1 Guest(s)