[Include] Load Dynamic Object From File
#1

Include with function for loading objects from file.

Now supports:
  • CreateDynamicObject
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;

Reply
#2

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!
Reply
#3

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).
Reply
#4

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

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...
Reply
#6

how to use man
Reply
#7

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

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

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.
Reply
#10

Add support for SetObjectMaterial
Reply
#11

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

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)
Reply
#13

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.
Reply
#14

Use sscanf to increase speed
Reply
#15

Or just

#include <objects.pwn>
Reply
#16

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)