SA-MP Forums Archive
What am I doing wrong?[HELP ME] - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: What am I doing wrong?[HELP ME] (/showthread.php?tid=201735)



What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

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;
}



Re: What am I doing wrong?[HELP ME] - Grim_ - 22.12.2010

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.


Re: What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

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


Re: What am I doing wrong?[HELP ME] - Grim_ - 22.12.2010

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;
}



Re: What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

Yes, I am, thanks ,


Re: What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

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)


Re: What am I doing wrong?[HELP ME] - Grim_ - 22.12.2010

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;
}



Re: What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

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


Re: What am I doing wrong?[HELP ME] - [JnA]DukeNukem - 22.12.2010

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


Re: What am I doing wrong?[HELP ME] - Grim_ - 22.12.2010

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.