LoadObjectsFromFile and Y_INI
#1

Hello everybody,

I just started testing while i noticed that my i could see trough my objects.
I think it was a problem with my drawing distance but when i edited the code nothing worked anymore

here is the code

pawn Код:
stock LoadObjectsFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new var_from_line[64];
    new Object;
    new Float:SpawnX;
    new Float:SpawnY;
    new Float:SpawnZ;
    new Float:SpawnRX;
    new Float:SpawnRY;
    new Float:SpawnRZ;
    new Float:draw;
    new index;
    new Objects_loaded;

    file_ptr = fopen(filename,filemode:io_read);
    if(!file_ptr) return 0;

    Objects_loaded = 0;

    while(fread(file_ptr,line,256) > 0)
    {
        index = 0;

        // Read type
        index = token_by_delim(line,var_from_line,',',index);
        print("1");
        if(index == (-1)) continue;
        Object = strval(var_from_line);

        // Read X, Y, Z, Rotation
        index = token_by_delim(line,var_from_line,',',index+1);
        print("2");
        if(index == (-1)) continue;
        SpawnX = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        print("3");
        if(index == (-1)) continue;
        SpawnY = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        print("4");
        if(index == (-1)) continue;
        SpawnZ = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        print("5");
        if(index == (-1)) continue;
        SpawnRX = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        print("6");
        if(index == (-1)) continue;
        SpawnRY = floatstr(var_from_line);

        index = token_by_delim(line,var_from_line,',',index+1);
        print("7");
        if(index == (-1)) continue;
        SpawnRZ = floatstr(var_from_line);
       
        index = token_by_delim(line,var_from_line,',',index+1);
        print("8");
        if(index == (-1)) continue;
        draw = floatstr(var_from_line);

        CreateObject(Object, SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);

        Objects_loaded++;
    }

    fclose(file_ptr);
    printf("Loaded %d objects from: %s",Objects_loaded,filename);
    return Objects_loaded;
}
i know that this is an edited code from grand larceny but still...

and can sombody tell me too how i can edit this code to be compatible with Y_INI and its tag function?

Thanks in Advance,

Sansko

P.S.

Here is the token_by_delim stock

pawn Код:
stock token_by_delim(const string[], return_str[], delim, start_index)
{
    new x=0;
    while(string[start_index] != EOS && string[start_index] != delim) {
        return_str[x] = string[start_index];
        x++;
        start_index++;
    }
    return_str[x] = EOS;
    if(string[start_index] == EOS) start_index = (-1);
    return start_index;
}
Reply
#2

Can anybody help me? I need this really quick. it is one of the most important parts of the script.
Reply
#3

omg, why aren't you using sscanf?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Can you crash in to the objects? If so it's just a loading problem, often occurring when in vehicles.

As for converting to y_ini, that file isn't in ini format so you would have to change everything to use that, and there's really no point.
No, first the objects only half appeared and after some changes i in the drawing distance which i tried to fix they totaly disappeard.

and about Y_INI, i am creating the server from scratch and if needed will change any code to make it possible,
becuase Y_ini is faster and it gives me the possibility to use tags. which i can use verry good for other gamemodes
(load one tag if its CTF or or the other for if its Demolition.

[edit]
there are/will be no vehicles in this server, meaby only for testing.

Quote:
Originally Posted by wups
Посмотреть сообщение
omg, why aren't you using sscanf?
Because i wasnt at the point to use that, and BTW can you tell me where i have to use that . (hold in mind that it is a edited grand larceny vehicle script and used this only to convert it for objects)


thanks for replying,

Sansko
Reply
#5

pawn Код:
stock LoadObjectsFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new var_from_line[64];
    new Object;
    new Float:SpawnX;
    new Float:SpawnY;
    new Float:SpawnZ;
    new Float:SpawnRX;
    new Float:SpawnRY;
    new Float:SpawnRZ;
    new Float:draw;
    new index;
    new Objects_loaded;

    file_ptr = fopen(filename,filemode:io_read);
    if(!file_ptr) return 0;

    Objects_loaded = 0;

    while(fread(file_ptr,line,256))
    {
        sscanf(line,"p<,>iffffffi",SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);
   
        CreateObject(Object, SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);

        Objects_loaded++;
    }

    fclose(file_ptr);
    printf("Loaded %d objects from: %s",Objects_loaded,filename);
    return Objects_loaded;
}
Reply
#6

Quote:
Originally Posted by wups
Посмотреть сообщение
pawn Код:
stock LoadObjectsFromFile(const filename[])
{
    new File:file_ptr;
    new line[256];
    new var_from_line[64];
    new Object;
    new Float:SpawnX;
    new Float:SpawnY;
    new Float:SpawnZ;
    new Float:SpawnRX;
    new Float:SpawnRY;
    new Float:SpawnRZ;
    new Float:draw;
    new index;
    new Objects_loaded;

    file_ptr = fopen(filename,filemode:io_read);
    if(!file_ptr) return 0;

    Objects_loaded = 0;

    while(fread(file_ptr,line,256))
    {
        sscanf(line,"p<,>iffffffi",SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);
   
        CreateObject(Object, SpawnX, SpawnY, SpawnZ, SpawnRX, SpawnRY, SpawnRZ, draw);

        Objects_loaded++;
    }

    fclose(file_ptr);
    printf("Loaded %d objects from: %s",Objects_loaded,filename);
    return Objects_loaded;
}
Thanks Wups,

I already solved it using sscanf not sure what the problem was, my code was much longer than your so i used your now. you getting credit in the GM for this.

There was a typo in the code but i've fixed that

Greetings,

Sansko
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)