Saving help
#1

Please don't spend your time commenting telling me I am dumb. I know I am C++ dumb, and I don't need to be called that.

Unless you are actually willing to help me, don't bother leaving a comment.

For those who are not dicks:

I am having a bit of trouble, I used this dini code (yes I did #include <dini> at the top of the script) that saved your position, and when I did. It spawned you in blueberry.

Код:
public OnPlayerDisconnect(playerid, reason)
{
IsPlayerPassenger[playerid] = 0;
new file[128], pname[MAX_PLAYER_NAME];
new Float:x, Float:y, Float:z;
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
if(!dini_Exists(file))
dini_Create(file);
GetPlayerPos(playerid, x, y, z);
dini_FloatSet(file, "posX", x);
dini_FloatSet(file, "posY", y);
dini_FloatSet(file, "posZ", z);
return 1;
}

public OnPlayerSpawn(playerid)
{
new file[128], pname[MAX_PLAYER_NAME];
new Float:x, Float:y, Float:z;
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
x = dini_Float(file, "posX");
y = dini_Float(file, "posY");
z = dini_Float(file, "posZ");
SetPlayerPos(playerid, x, y, z);
SetPlayerColor(playerid, 0xFFFFFFFF );
return 1;
}
I then added:

Код:
SetPlayerPos(playerid, -1421.3221,-287.5208,14.1484);
And you spawned at the Easter Bay Airport, which is what I intended. But positions, do not save. They are changed in the file, but not loaded.

Could someone make this script spawn you if you log in for the first time at
Код:
-1421.3221,-287.5208,14.1484
and load your position afterwards?

Код:
public OnPlayerDisconnect(playerid, reason)
{
IsPlayerPassenger[playerid] = 0;
new file[128], pname[MAX_PLAYER_NAME];
new Float:x, Float:y, Float:z;
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
if(!dini_Exists(file))
dini_Create(file);
GetPlayerPos(playerid, x, y, z);
dini_FloatSet(file, "posX", x);
dini_FloatSet(file, "posY", y);
dini_FloatSet(file, "posZ", z);
return 1;
}

public OnPlayerSpawn(playerid)
{
new file[128], pname[MAX_PLAYER_NAME];
new Float:x, Float:y, Float:z;
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
x = dini_Float(file, "posX");
y = dini_Float(file, "posY");
z = dini_Float(file, "posZ");
SetPlayerPos(playerid, x, y, z);
SetPlayerColor(playerid, 0xFFFFFFFF );
SetPlayerPos(playerid, -1421.3221,-287.5208,14.1484);
return 1;
}
This is my player class:
Код:
AddPlayerClass(299,-1421.3221,-287.5208,14.1484,138.4006,0,0,0,0,0,0);
This is my RequestPlayerClass blah crap

Код:
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, -1421.3221,-287.5208,14.1484);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}
I've searched for a solution, and can not find one. Please help me.
Reply
#2

I don't see what C++ has to do with any of this.

1. As you are new to scripting with SA:MP, don't use the dini library. It is very outdated, inefficient, and no longer supported. Search for one of the newer includes such as Y_INI.

2. You may want to do some checks to make sure the files are actually there before reading/writing values to them. I'm not sure if dini does this internally.

3. To make them spawn at the specified position on first log-in (assuming the only code for that is above) check if the file exists under OnPlayerSpawn. If it doesn't, then that is their first spawn, and set the position. If it does exist, read the value from the file and set it. This requires saving the values under OnPlayerDisconnect, which I believe you already do.
Reply
#3

PHP код:
new Float:xFloat:yFloat:z;
dini_Get(a file"PosX");
dini_Get(a file"PosY");
dini_Get(a file"PosZ");
SetPlayerPos(playeridxyz); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)