problem teleport to a position reading from file with io_read
#1

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;
    }
Reply
#2

Please..anyone can help me fix this ?
Reply
#3

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
Reply
#4

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
Reply
#5

Could anyone see the problem or test this please ?
Reply
#6

Can we at least see the contents of the file?
Reply
#7

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
Reply
#8

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;
}
Reply
#9

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

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

gg Konstantinos.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)