SA-MP Forums Archive
[HELP] question about coords. - 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: [HELP] question about coords. (/showthread.php?tid=92148)



[HELP] question about coords. - arnutisz - 18.08.2009

Well, I am using dini, and I waant to know how I can get float from dini file and use it for player pos? Example:

Код:
//In dini file:

spawn=1235.756, 789.123, 785.12
There are any way to use like this?
Код:
spawnpos = dini_Get("filename.txt", "spawn");

SetPlayerPos(playerid, spawnpos);



Re: [HELP] question about coords. - dice7 - 18.08.2009

pawn Код:
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
dini_FloatSet("/folder/file.ini", "F_X", X);
dini_FloatSet("/folder/file.ini", "F_Y", Y);
dini_FloatSet("/folder/file.ini", "F_Z", Z);

// the output to "file.ini" in the folder "folder" will be
// F_X = 0.000000
// F_Y = 0.000000
// F_Z = 0.000000


////////////////////////////
new Float:X, Float:Y, FloatZ;
X = dini_Float("/folder/file.ini", "F_X");
Y = dini_Float("/folder/file.ini", "F_Y");
Z = dini_Float("/folder/file.ini", "F_Z");
SetPlayerPos(playerid, X, Y, Z);



Re: [HELP] question about coords. - arnutisz - 18.08.2009

I know this way, but I need to load about 20 spawnpoints from file, so any ideas?


Re: [HELP] question about coords. - dice7 - 18.08.2009

Make so that every player has It's own file

pawn Код:
OnPlayerSpawn(playerid)
{
  new name[MAX_PLAYER_NAME], string[128];
  GetPlayerName(playerid, name, sizeof(name));
  format(string, sizeof(string), "/folder/%s.ini", name);

  if(dini_Exists(string))
  {
    new Float:X, Float:Y, FloatZ;
    X = dini_Float("/folder/file.ini", "F_X");
    Y = dini_Float("/folder/file.ini", "F_Y");
    Z = dini_Float("/folder/file.ini", "F_Z");
    SetPlayerPos(playerid, X, Y, Z);
  }
  else dini_Create(string);
}

OnPlayerDisconnect(playerid, reason)
{
  new Float:X, Float:Y, Float:Z;
  GetPlayerPos(playerid, X, Y, Z);
  dini_FloatSet(string, "F_X", X);
  dini_FloatSet(string, "F_Y", Y);
  dini_FloatSet(string, "F_Z", Z);
}



Re: [HELP] question about coords. - arnutisz - 18.08.2009

I have only one file, and I need do in that way, like I said, and without split. Is it possible?


Re: [HELP] question about coords. - CAR - 18.08.2009

I wanted to make that, no succes, maybe this helps?

Код:
new spawn;
spawn=1235.756, 789.123, 785.12

dini_IntSet(filename, "spawn", spawn);

//OnPlayerConnect Etc.

dini_Get("filename.txt", "spawn");
SetPlayerPos(playerid, spawn);



Re: [HELP] question about coords. - dice7 - 18.08.2009

Impossible with dini


Re: [HELP] question about coords. - CAR - 19.08.2009

That's not true you can get it with dini.
The only question is "how?".

My person spawns on another place then the Class spawn. That means there is something good and the is something wrong.

But It Can Be With Dini


Re: [HELP] question about coords. - dice7 - 19.08.2009

It can't be done with dini. Dini assigns values to keys, It can't create multidimentional arrays. The only way it can be done is the way a few posts up


Re: [HELP] question about coords. - bogeymanEST - 19.08.2009

This could be done with the file functions & sscanf:
pawn Код:
//On top of the script
//20 spawns for example
new Float:Spawns[20][3];

//Somewhere below
stock LoadSpawns()
{
    new read[15];
    new File:fSpawns = fopen("filename.txt", io_read);
    new Float:x, Float:y, Float:z;
    new i = 0;
    while(fread(fSpawns, read))
    {
        if(!sscanf(read, "fff", x, y, z))
        {
            Spawns[i][0] = x;
            Spawns[i][1] = y;
            Spawns[i][2] = z;
            i++;
        }
    }
    fclose(fSpawns);
    return 1;
}
The file would have to look like this:
pawn Код:
1235.756 789.123 785.12
1337.999 5543.65 15.992
Just do LoadSpawns() in OnGameModeInit and the spawns will go nicely into the Spawns array.
To spawn a player:
pawn Код:
SetPlayerPos(playerid, Spawns[0][0], Spawns[0][1], Spawns[0][2]);