SA-MP Forums Archive
[Include] Load Dynamic Object From File - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Load Dynamic Object From File (/showthread.php?tid=534400)



Load Dynamic Object From File - kaZax - 29.08.2014

Include with function for loading objects from file.

Now supports: Changelog:
Version 1.0
- Created.
Version 2.0
- Fully updated code.

How to use:
PHP код:
public OnGameModeInit()
{
    
LoadDynamicObjectsFromFile("objects.txt");
    return 
1;

Source Code:
PHP код:
#if defined _objectLoader_included
  #endinput
#endif
#define _objectLoader_included
/*
Author: kaZax
Include Version: 2.0
samp.work
*/
stock LoadDynamicObjectsFromFile(const filename[])
{
    new 
File:fileHandle fopen(filenameio_read);
     
    if(
fileHandle)
    {
        new 
startPosendPosidxline[64], buf[128], objectcount;
        new 
modelid,
            
Float:x,
            
Float:y,
            
Float:z,
            
Float:rx,
            
Float:ry,
            
Float:rz,
            
worldid,
            
interiorid,
            
playerid,
            
Float:streamdistance,
            
Float:drawdistance,
            
STREAMER_TAG_AREA areaid,
            
priority;
        while(
fread(fileHandlebuf))
        {
            
startPos strfind(buf"("); 
            
endPos strfind(buf")"); 
            if (
startPos && endPos)
            {
                
strmid(bufbuf, (startPos 1), endPos);
                
idx 0;
                
worldid = -1,
                
interiorid = -1,
                
playerid = -1,
                
streamdistance STREAMER_OBJECT_SD,
                
drawdistance STREAMER_OBJECT_DD,
                
areaid = -1,
                
priority 0;
                
idx token_by_delim(bufline','idx);                             modelid         strval(line); 
                
idx token_by_delim(bufline',', (idx 1));                     x                 floatstr(line);
                
idx token_by_delim(bufline',', (idx 1));                     y                 floatstr(line);
                
idx token_by_delim(bufline',', (idx 1));                     z                 floatstr(line);
                
idx token_by_delim(bufline',', (idx 1));                     rx                 floatstr(line);
                
idx token_by_delim(bufline',', (idx 1));                     ry                 floatstr(line);
                
idx token_by_delim(bufline',', (idx 1));                     rz                 floatstr(line);    
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     worldid         strval(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     interiorid         strval(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     playerid         strval(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     streamdistance     floatstr(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     drawdistance     floatstr(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     areaid             strval(line);
                if (
idx != -1idx token_by_delim(bufline',', (idx 1)),     priority         strval(line);
                
CreateDynamicObject(modelidxyzrxryrzworldidinterioridplayeridstreamdistancedrawdistanceareaidpriority);
                
objectcount ++;
            }
        }
     
        
fclose(fileHandle);
        
printf("DynamicObjectLoader: Loaded %d objects from \"%s\"."objectcountfilename);
    }
    else
    {
        
printf("DynamicObjectLoader: The file \"%s\" does not exists, or can't be opened."filename);
    }
    return 
1;
}
stock token_by_delim(const string[], return_str[], delimstart_index)
{
    new 
0;
    while(
string[start_index] != EOS && string[start_index] != delim
    {
        
return_str[x] = string[start_index];
        
++;
        
start_index ++;
    }
    
return_str[x] = EOS;
    if(
string[start_index] == EOSstart_index = (-1);
    return 
start_index;




Re: Load Dynamic Object From File - JonathanW - 29.08.2014

I'd rather prefer a fully dynamic system, in which objects are created IG..i dont know how I went off the tracks. Nice work!


Re: Load Dynamic Object From File - zT KiNgKoNg - 29.08.2014

Good system overall, but I prefer to use MySQL and custom written PHP to create a Insert code (mainly so I don't need to insert it manually).


Re: Load Dynamic Object From File - Pottus - 29.08.2014

I would just use sscanf and call it a day seems much more logical than all doing it this way.


Re: Load Dynamic Object From File - Rudy_ - 02.09.2014

And if anyone would've needed it like this, They would've used it, And he'd have not made it for to see comments 'i'd do that' Then just don't come here if you'd use something else.
OT: Nice work, tbh...


Re: Load Dynamic Object From File - ScripteRNaBEEL - 02.09.2014

how to use man


Re: Load Dynamic Object From File - satafinix - 04.09.2014

Quote:
Originally Posted by ScripteRNaBEEL
Посмотреть сообщение
how to use man
it s Include


Re: Load Dynamic Object From File - Crayder - 07.09.2014

Actually, I haven't tested but i don't think this will work because CreateDynamicObject doesn't always have 7 parameters...


Re: Load Dynamic Object From File - kaZax - 12.06.2016

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Actually, I haven't tested but i don't think this will work because CreateDynamicObject doesn't always have 7 parameters...
Yes! Fixed.


Re: Load Dynamic Object From File - Richie - 12.06.2016

Add support for SetObjectMaterial


Re: Load Dynamic Object From File - kaZax - 12.06.2016

Quote:
Originally Posted by Richie
Посмотреть сообщение
Add support for SetObjectMaterial
Maybe on next updates.


Re: Load Dynamic Object From File - AbyssMorgan - 12.06.2016

Definitely I staying still at BINLDR.inc

DynamicObjectLoader:
obiekty-world.txt objects: 100597 load time 4141 ms file size: 10.30 MB (Byte: 10'875'043)

BINLDR object loader:
obiekty-world.bin objects: 100597 load time 1981 ms file size: 4.02 MB (Byte: 4'225'074)


Re: Load Dynamic Object From File - kaZax - 12.06.2016

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
Definitely I staying still at BINLDR.inc

DynamicObjectLoader:
obiekty-world.txt objects: 100597 load time 4141 ms file size: 10.30 MB (Byte: 10'875'043)

BINLDR object loader:
obiekty-world.bin objects: 100597 load time 1981 ms file size: 4.02 MB (Byte: 4'225'074)
File size good, but need compress file.
Load time? Ok!
I will update include for the best results.


Re: Load Dynamic Object From File - AbyssMorgan - 12.06.2016

Use sscanf to increase speed


Re: Load Dynamic Object From File - Luicy. - 12.06.2016

Or just

#include <objects.pwn>


Re: Load Dynamic Object From File - AbyssMorgan - 12.06.2016

Quote:
Originally Posted by Meller
Посмотреть сообщение
Or just

#include <objects.pwn>
Large number of objects slows compilations.
I am using a minimum 30'000 objects.


Re: Load Dynamic Object From File - kaZax - 12.06.2016

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
Use sscanf to increase speed
Need include without external includes.