[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


Messages In This Thread
Load Dynamic Object From File - by kaZax - 29.08.2014, 17:05
Re: Load Dynamic Object From File - by JonathanW - 29.08.2014, 17:34
Re: Load Dynamic Object From File - by zT KiNgKoNg - 29.08.2014, 17:39
Re: Load Dynamic Object From File - by Pottus - 29.08.2014, 17:51
Re: Load Dynamic Object From File - by Rudy_ - 02.09.2014, 14:14
Re: Load Dynamic Object From File - by ScripteRNaBEEL - 02.09.2014, 15:57
Re: Load Dynamic Object From File - by satafinix - 04.09.2014, 08:51
Re: Load Dynamic Object From File - by Crayder - 07.09.2014, 13:42
Re: Load Dynamic Object From File - by kaZax - 12.06.2016, 12:54
Re: Load Dynamic Object From File - by Richie - 12.06.2016, 16:52
Re: Load Dynamic Object From File - by kaZax - 12.06.2016, 17:10
Re: Load Dynamic Object From File - by AbyssMorgan - 12.06.2016, 17:31
Re: Load Dynamic Object From File - by kaZax - 12.06.2016, 18:03
Re: Load Dynamic Object From File - by AbyssMorgan - 12.06.2016, 18:21
Re: Load Dynamic Object From File - by Luicy. - 12.06.2016, 18:32
Re: Load Dynamic Object From File - by AbyssMorgan - 12.06.2016, 18:35
Re: Load Dynamic Object From File - by kaZax - 12.06.2016, 18:39

Forum Jump:


Users browsing this thread: 1 Guest(s)