What am I doing wrong?[HELP ME]
#1

What is wrong with this script.....all it does is create a .ini file called pos.ini and puts in it pos=0

Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128], pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pname, sizeof(pname));
	format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
	if(!dini_Exists(file))
	dini_Create(file);
	new Float:x, Float:y, Float:z;
	dini_IntSet(file, "Pos", GetPlayerPos(playerid, x, y, z));
	return 1;
}

public OnPlayerSpawn(playerid)
{
new file[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
SetPlayerPos(playerid, dini_Int(file, "Pos"));
return 1;
}
Reply
#2

Dini for the loser.

Anyway, you should have it like this instead:
pawn Код:
GetPlayerPos( playerid, x, y, z );
dini_FloatSet( file, "PosX", x );
dini_FloatSet( file, "PosY", y );
dini_FloatSet( file, "PosZ", z );
Firstly, you are writing an integer to the file when it should be a float value (coordinates are floats). I would also suggestion you add a check in OnPlayerSpawn, to check if the file exists.
Reply
#3

I'm really new to Pawno so could you embed that in my code please?
Reply
#4

Just to clarify, Pawno is the program you are using to code the PAWN language in. So you are new to PAWN.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128], pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
    if(!dini_Exists(file))
    dini_Create(file);
    new Float:x, Float:y, Float: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];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
if( !dini_Exists( file ) ) return 0; // file doesn't exist, don't set their pos.
SetPlayerPos(playerid, dini_Int(file, "Pos"));
return 1;
}
Reply
#5

Yes, I am, thanks ,
Reply
#6

It doesn't work, it creates the .ini file with my player name on it but in it only says

PosX=0.000000
PosY=0.000000
PosZ=0.000000



(i moved from that coordinate and it's the same)
Reply
#7

Sorry, I forgot to add GetPlayerPos function.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new file[128], pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
    if(!dini_Exists(file))
    dini_Create(file);
    new Float:x, Float:y, Float:z;
    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];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), "\\Positions\\%s.ini", pname);//leader the name of your folder in scriptfiles
if( !dini_Exists( file ) ) return 0; // file doesn't exist, don't set their pos.
SetPlayerPos(playerid, dini_Int(file, "Pos"));
return 1;
}
Reply
#8

Now it's saving to .ini file but i'm still spawning in other position
Reply
#9

maybe because there is no "pos" in the .ini there are floats now?
Reply
#10

Sorry, I'm quite tired right now and seem to be overlooking everything. You are correct!
pawn Код:
SetPlayerPos( playerid, dini_Float( file, "PosX" ), dini_Float( file, "PosY" ), dini_float( file, "PosZ" ) );
dini_Float may be the incorrect function, so check for the correct function if the compiler spits out errors.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)