Advertisement
ukazax

[Include] Dynamic Object Loader

Jun 11th, 2016
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.96 KB | None | 0 0
  1. #if defined _objectLoader_included
  2.   #endinput
  3. #endif
  4. #define _objectLoader_included
  5.  
  6. /*
  7. Author: kaZax
  8. Include Version: 2.0
  9. samp.work
  10. */
  11.  
  12. stock LoadDynamicObjectsFromFile(const filename[])
  13. {
  14.     new File:fileHandle = fopen(filename, io_read);
  15.      
  16.     if(fileHandle)
  17.     {
  18.         new startPos, endPos, idx, line[64], buf[128], objectcount;
  19.         new modelid,
  20.             Float:x,
  21.             Float:y,
  22.             Float:z,
  23.             Float:rx,
  24.             Float:ry,
  25.             Float:rz,
  26.             worldid,
  27.             interiorid,
  28.             playerid,
  29.             Float:streamdistance,
  30.             Float:drawdistance,
  31.             STREAMER_TAG_AREA areaid,
  32.             priority;
  33.  
  34.         while(fread(fileHandle, buf))
  35.         {
  36.             startPos = strfind(buf, "(");
  37.             endPos = strfind(buf, ")");
  38.  
  39.             if (startPos && endPos)
  40.             {
  41.                 strmid(buf, buf, (startPos + 1), endPos);
  42.  
  43.                 idx = 0;
  44.                 worldid = -1,
  45.                 interiorid = -1,
  46.                 playerid = -1,
  47.                 streamdistance = STREAMER_OBJECT_SD,
  48.                 drawdistance = STREAMER_OBJECT_DD,
  49.                 areaid = -1,
  50.                 priority = 0;
  51.  
  52.                 idx = token_by_delim(buf, line, ',', idx);                          modelid         = strval(line);
  53.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    x               = floatstr(line);
  54.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    y               = floatstr(line);
  55.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    z               = floatstr(line);
  56.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    rx              = floatstr(line);
  57.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    ry              = floatstr(line);
  58.                 idx = token_by_delim(buf, line, ',', (idx + 1));                    rz              = floatstr(line);  
  59.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     worldid         = strval(line);
  60.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     interiorid      = strval(line);
  61.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     playerid        = strval(line);
  62.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     streamdistance  = floatstr(line);
  63.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     drawdistance    = floatstr(line);
  64.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     areaid          = strval(line);
  65.                 if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)),     priority        = strval(line);
  66.  
  67.                 CreateDynamicObject(modelid, x, y, z, rx, ry, rz, worldid, interiorid, playerid, streamdistance, drawdistance, areaid, priority);
  68.  
  69.                 objectcount ++;
  70.             }
  71.         }
  72.      
  73.         fclose(fileHandle);
  74.  
  75.         printf("DynamicObjectLoader: Loaded %d objects from \"%s\".", objectcount, filename);
  76.     }
  77.     else
  78.     {
  79.         printf("DynamicObjectLoader: The file \"%s\" does not exists, or can't be opened.", filename);
  80.     }
  81.     return 1;
  82. }
  83.  
  84. stock token_by_delim(const string[], return_str[], delim, start_index)
  85. {
  86.     new x = 0;
  87.     while(string[start_index] != EOS && string[start_index] != delim)
  88.     {
  89.         return_str[x] = string[start_index];
  90.         x ++;
  91.         start_index ++;
  92.     }
  93.     return_str[x] = EOS;
  94.     if(string[start_index] == EOS) start_index = (-1);
  95.     return start_index;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement