SA-MP Forums Archive
problem teleport to a position reading from file with io_read - 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)
+--- Thread: problem teleport to a position reading from file with io_read (/showthread.php?tid=572885)



problem teleport to a position reading from file with io_read - AIped - 02.05.2015

Hello,

I thought i'd make a simple command to teleport to a position i saved earlyer in a file.
The position it saved works perfect..however the loading/teleport doesnt teleport me.

It says 'invalid line' instead of setting my position

pawn Код:
if(!strcmp(cmdtext, "/gopos", true))
    {
        if(fexist("mypos.txt"))
        {
            new File:IFile = fopen("mypos.txt", io_read), str[128];

            while(fread(IFile, str))
            {
                if(str[0] == '#') continue;

                new Float:X, Float:Y, Float:Z;
                if(sscanf(str, "fff",X, Y, Z))
                {
                    printf("(i) Invalid Line: %s", str);
                }
                else
                {
                    SetPlayerPos(playerid, X, Y, Z);
                }
            }

            fclose(IFile);
        }
        return 1;
    }



Re: problem teleport to a position reading from file with io_read - AIped - 03.05.2015

Please..anyone can help me fix this ?


Re: problem teleport to a position reading from file with io_read - arlindi - 03.05.2015

PHP код:
    if(!strcmp(cmdtext"/gopos"true))
    {
        if(
fexist("mypos.txt"))
        {
            new 
File:IFile fopen("mypos.txt"io_read), str[128];

            while(
fread(IFilestr))
            {
                if(
str[0] == '#') continue;

                new 
Float:XFloat:YFloat:Z;
                if(
sscanf(str"fff",XYZ))
                {
                                
SetPlayerPos(playeridXYZ);
                }
                else
                {
                    
printf("(i) Invalid Line: %s"str);                     
                }
            }

            
fclose(IFile);
        }
        return 
1;
    } 
I dont know if it will work but try
Thank you


Re: problem teleport to a position reading from file with io_read - AIped - 03.05.2015

I tried your way didnt work but i noticed something weird
it teleports me at ALMOSt the correct point..meaning +/- 50 feet away from the x or y position


Re: problem teleport to a position reading from file with io_read - AIped - 04.05.2015

Could anyone see the problem or test this please ?


Re: problem teleport to a position reading from file with io_read - Threshold - 04.05.2015

Can we at least see the contents of the file?


Re: problem teleport to a position reading from file with io_read - AIped - 04.05.2015

Ofcourse you can here it is;

pawn Код:
2412.7454,-1697.8491,13.7579
Just one coordinate to set the players position from that file.

I have the feeling i teleport at the wrong position because of something in my GM.
However..when i change gamemodes the same happens


Re: problem teleport to a position reading from file with io_read - ATomas - 04.05.2015

pawn Код:
if(!strcmp(cmdtext,"/gopos",true))
{
    if(fexist("mypos.txt"))
    {
        new File:IFile = fopen("mypos.txt",io_read),str[128];

        while(fread(IFile,str))
        {
            if(str[0] == '#') continue;

            new Float:X = floatstr(str);
           
            new pos = chrfind(',',str)+1;
            if(pos == 0) print("Missing 2nd parameter");
            new Float:Y = floatstr(str[pos])
           
            pos = chrfind(',',str,pos)+1;
            if(pos == 0) print("Missing 3rd parameter");
            new Float:Z = floatstr(str[pos]);
           
            printf("SetPlayerPos(playerid,%f,%f,%f)",X,Y,Z);
            SetPlayerPos(playerid,X,Y,Z);
        }
        fclose(IFile);
    }
    return 1;
}

stock chrfind(n,h[],s=0)
{
    new l = strlen(h);
    while(s < l)
    {
        if(h[s] == n) return s;
        s++;
    }
    return -1;
}



Re: problem teleport to a position reading from file with io_read - Konstantinos - 04.05.2015

pawn Код:
if (sscanf(str, "p<,>fff", X, Y, Z))



Re: problem teleport to a position reading from file with io_read - Threshold - 04.05.2015

God dammit, I really wanted to answer this one. I knew I shouldn't have left it for this long.

gg Konstantinos.