using CreateObject function inside a loop
#1

Hello, is it possible to use CreateObject or CreateDynamicObject (incognito's streamer) inside a for loop, if yes, how?


Right now I am doing this:
pawn Код:
new i=0;
    new File:ftw=fopen("1.txt",io_read);
    while(ftw)
    {
        new string[200];
        fread(ftw, string);
        if(isnull(string))
        return 1;
        //printf("\n[%s]",string);
        new s[50];
        new integ;
        new float: x,y,z,rx,ry,rz;
        sscanf(string,"p<(>s[50]p<,>ifffffp<)>f",s,integ,x,y,z,rx,ry,rz);
        if(strcmp("CreateObject",s,true)==0)
        {
            //printf("test");
            printf("\n[%s]\nInteger=%d\nx=%f\ny=%f\nz=%f\nrx=%f\nry=%f\nrz=%f\n",s,integ,x,y,z,rx,ry,rz);
            CreateDynamicObject(integ,x,y,z,rx,ry,rz);
            i++;
        }
        if(i==1)
        AddPlayerClass(150,x,y,z+4,5.4011,0,0,0,0,0,0);
    }

Its running fine with warning: tag mismatch on line where CreateObject is used.
I tried by using CreateObject as well as CreateDynamicObject with the plugin correctly, the script was debugged, and its reading the file 1.txt correctly.

So its not possible to use CreateObject inside for loop ?
Reply
#2

pawn Код:
new float: x,y,z,rx,ry,rz;
It should be
pawn Код:
new Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
And yes, it's possible.
Reply
#3

Thanks Dwane, the warning is gone, but the map is still not loading.
Reply
#4

I haven't used sscanf for more stuff than the usage on commands, but try something like this
pawn Код:
// --
    new i=0;
    new File:ftw=fopen("1.txt",io_read);
    while(ftw)
    {
        new string[200];
        fread(ftw, string);
        if(isnull(string)) return 1;
        new integ, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
        sscanf(string, "p<,>iffffff", integ, x, y, z, rx, ry, rz);
        //printf("test");
        printf("\nInteger=%d\nx=%f\ny=%f\nz=%f\nrx=%f\nry=%f\nrz=%f\n",integ,x,y,z,rx,ry,rz);
        CreateDynamicObject(integ,x,y,z,rx,ry,rz);
        i++;
        if(i==1) AddPlayerClass(150,x,y,z+4,5.4011,0,0,0,0,0,0);
    }
I'm not 100 percent sure about the increasement of the i before the if statement, I mean I am not sure if it works as you'd like to work. And make sure you write on the file like this.
pawn Код:
// An example of 1.txt
2000,5.0,5.0,5.0,5.0,5.0,5.0
Reply
#5

Sorry, it is working! My bad!

I didn't knew till now what is difference between Float and float! Oh god! >_>

Thanks for help Dwane.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)