02.11.2015, 03:09
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:
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:
Now to load these objects and create them in game you would come up with something like this:
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
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
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(handle, buf))
{
if(sscanf(buf, "p<|>dffffff", model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]))
{
count++;
CreateObject(model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
}
}
fclose(handle);
printf("Objects loaded from 'objects.txt': %d objects.", count);
return 1;
}