A small question
#5

Quote:
Originally Posted by DemME
Посмотреть сообщение
Arh-.. and how do I do so?
You could have them stored in a file using a specifier to separate the object model, x, y, z positions, x, y, z rotations respectively and finally use sscanf.

Imagine I have a file called objects.txt in the scriptfiles folder, and I've predefined the following format to store the objects in the file:

Код:
Object model|PosX|PosY|PosZ|RotX|RotY|RotZ
Note I'm using the | delimiter to break up the needed information for each object.


If we considerate the format stated above we might end up with a line into the file which would look like this:

Код:
19941|144.134|931.33|444.11|0.0|.0.0|0.0
4141|1444.134|1131.33|44.11|0.0|.0.0|0.0
5414|1484.134|51.33|344.11|0.0|.0.0|0.0
Now to load these objects and create them in game you would come up with something like this:

PHP код:
LoadObjects()
{
    new 
        
File:handle fopen("objects.txt"io_read),
        
buf[128]
    ;
    if(!
handle) return 0;
    new
        
model,
        
Float:pos[3],
        
Float:rot[3],
        
count
    
;
    while(
fread(handlebuf))
    {
        if(
sscanf(buf"p<|>dffffff"modelpos[0], pos[1], pos[2], rot[0], rot[1], rot[2]))
        {
            
count++;
            
CreateObject(modelpos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
        }
    }
    
fclose(handle);
    
printf("Objects loaded from 'objects.txt': %d objects."count);
    return 
1;

Reply


Messages In This Thread
A small question - by DemME - 02.11.2015, 02:02
Re: A small question - by Kevln - 02.11.2015, 02:15
Re: A small question - by DemME - 02.11.2015, 02:28
Re: A small question - by rangerxxll - 02.11.2015, 03:09
Re: A small question - by ThePhenix - 02.11.2015, 03:09
Re: A small question - by AbyssMorgan - 02.11.2015, 05:22
Re: A small question - by Gammix - 02.11.2015, 08:27
Re: A small question - by DemME - 06.11.2015, 05:33

Forum Jump:


Users browsing this thread: 1 Guest(s)