Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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(filename, io_read);
- if(fileHandle)
- {
- new startPos, endPos, idx, line[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(fileHandle, buf))
- {
- startPos = strfind(buf, "(");
- endPos = strfind(buf, ")");
- if (startPos && endPos)
- {
- strmid(buf, buf, (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(buf, line, ',', idx); modelid = strval(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); x = floatstr(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); y = floatstr(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); z = floatstr(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); rx = floatstr(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); ry = floatstr(line);
- idx = token_by_delim(buf, line, ',', (idx + 1)); rz = floatstr(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), worldid = strval(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), interiorid = strval(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), playerid = strval(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), streamdistance = floatstr(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), drawdistance = floatstr(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), areaid = strval(line);
- if (idx != -1) idx = token_by_delim(buf, line, ',', (idx + 1)), priority = strval(line);
- CreateDynamicObject(modelid, x, y, z, rx, ry, rz, worldid, interiorid, playerid, streamdistance, drawdistance, areaid, priority);
- objectcount ++;
- }
- }
- fclose(fileHandle);
- printf("DynamicObjectLoader: Loaded %d objects from \"%s\".", objectcount, filename);
- }
- 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[], delim, start_index)
- {
- new x = 0;
- while(string[start_index] != EOS && string[start_index] != delim)
- {
- return_str[x] = string[start_index];
- x ++;
- start_index ++;
- }
- return_str[x] = EOS;
- if(string[start_index] == EOS) start_index = (-1);
- return start_index;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement