Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- seif_convert - MTA to SA-MP map converter by Seif
- */
- /*x---------------------------------Important-------------------------------------x*/
- //**INCLUDES**//
- #include <a_samp>
- /*x---------------------------------Defining-------------------------------------x*/
- //**COLORS*//
- #define GREEN 0x21DD00FF
- #define RED 0xE60000FF
- #define ADMIN_RED 0xFB0000FF
- #define YELLOW 0xFFFF00FF
- #define ORANGE 0xF97804FF
- #define LIGHTRED 0xFF8080FF
- #define LIGHTBLUE 0x00C2ECFF
- #define PURPLE 0xB360FDFF
- #define PLAYER_COLOR 0xFFFFFFFF
- #define BLUE 0x1229FAFF
- #define LIGHTGREEN 0x38FF06FF
- #define DARKPINK 0xE100E1FF
- #define DARKGREEN 0x008040FF
- #define ANNOUNCEMENT 0x6AF7E1FF
- #define COLOR_SYSTEM 0xEFEFF7AA
- #define GREY 0xCECECEFF
- #define PINK 0xD52DFFFF
- #define DARKGREY 0x626262FF
- #define AQUAGREEN 0x03D687FF
- #define NICESKY 0x99FFFFAA
- #define WHITE 0xFFFFFFFF
- /*x---------------------------------CallBacks-------------------------------------x*/
- public OnFilterScriptInit()
- {
- print("<|-----------------------------------------|>");
- print(".:[- seif_convert - map converter by Seif -]:.");
- print("<|-----------------------------------------|>");
- return 1;
- }
- public OnRconCommand(cmd[])
- {
- new fn[128];
- new rconcmd[128];
- new idx;
- rconcmd = strtok(cmd, idx);
- if (!strcmp("convert", rconcmd, true))
- {
- fn = longstr(cmd, idx);
- if (!strlen(fn)) return print("seif_convert: You must enter the file name to convert!");
- new string[128];
- new read[256];
- new times;
- format(string, sizeof string, \"\seif_convert\MTA\%s.map", fn);
- if (!fexist(string)) return printf("seif_convert: %s.map doesn't exist!", fn);
- new File:file = fopen(string, io_read);
- if (file)
- {
- new
- ObjectName[128],
- Float:ObjectX,
- Float:ObjectY,
- Float:ObjectZ,
- Float:ObjectrX,
- Float:ObjectrY,
- Float:ObjectrZ,
- ObjectModel,
- ObjectXYZ[128],
- ObjectRot[128],
- ObjectStr[128],
- reboot = 1;
- print("...");
- WHILELOOP:
- while (fread(file, read))
- {
- new lines;
- // Takes the object name
- if (reboot == 1)
- {
- if (strfind(read, "<object name=\"") == -1) continue;
- new id = strlen("<object name=\"");
- for(new i = id+1; i < 128; i++)
- {
- if (read[i] == '>') break;
- if (read[i] != '"')
- {
- format(string, 1, "%c", read[i]);
- strins(ObjectName, string, lines);
- lines++;
- }
- }
- reboot = 2;
- goto WHILELOOP;
- break;
- }
- new CoordType = 1; // X
- //Gets the object's positions
- if (reboot == 2)
- {
- if (strfind(read, "<position>") == -1) continue;
- new posid = strlen("<position>");
- lines = 0;
- for(new i = posid+4; i < 128; i++)
- {
- if (read[i] != '<' && read[i] != ' ')
- {
- format(string, 1, "%c", read[i]);
- strins(ObjectXYZ, string, lines);
- lines++;
- }
- else if (read[i] == ' ')
- {
- if (CoordType == 1)
- {
- CoordType = 2;
- ObjectX = floatstr(ObjectXYZ);
- format(ObjectXYZ, 128, ""); // Y
- lines = 0;
- }
- else if (CoordType == 2)
- {
- CoordType = 3;
- ObjectY = floatstr(ObjectXYZ);
- format(ObjectXYZ, 128, ""); // Z
- lines = 0;
- }
- }
- else if (read[i] == '<')
- {
- ObjectZ = floatstr(ObjectXYZ);
- lines = 0;
- break;
- }
- }
- reboot = 3;
- goto WHILELOOP;
- break;
- }
- //Gets the object's rotations
- if (reboot == 3)
- {
- if (strfind(read, "<rotation>") == -1) continue;
- new rotid = strlen("<rotation>");
- lines = 0;
- CoordType = 1; // X
- for(new i = rotid+4; i < 128; i++)
- {
- if (read[i] != '<' && read[i] != ' ')
- {
- format(string, 1, "%c", read[i]);
- strins(ObjectRot, string, lines);
- lines++;
- }
- else if (read[i] == ' ')
- {
- if (CoordType == 1)
- {
- CoordType = 2;
- ObjectrZ = floatstr(ObjectRot);
- ObjectrZ = (360 + (ObjectrZ / 0.0174532925));
- while (ObjectrZ >= 360) ObjectrZ = ObjectrZ - 360;
- while (ObjectrZ < 0) ObjectrZ = ObjectrZ + 360;
- format(ObjectRot, 128, ""); // Y
- lines = 0;
- }
- else if (CoordType == 2)
- {
- CoordType = 3;
- ObjectrY = floatstr(ObjectRot);
- ObjectrY = (360 + (ObjectrY / 0.0174532925));
- while (ObjectrY >= 360) ObjectrY = ObjectrY - 360;
- while (ObjectrY < 0) ObjectrY = ObjectY + 360;
- format(ObjectRot, 128, ""); // Z
- lines = 0;
- }
- }
- else if (read[i] == '<')
- {
- ObjectrX = floatstr(ObjectRot);
- ObjectrX = (360 + (ObjectrX / 0.0174532925));
- while (ObjectrX >= 360) ObjectrX = ObjectrX - 360;
- while (ObjectrX < 0) ObjectrX = ObjectrX + 360;
- lines = 0;
- break;
- }
- }
- //printf("rotations: %f %f %f", ObjectX, ObjectY, ObjectZ);
- reboot = 4;
- goto WHILELOOP;
- break;
- }
- //Gets the object's model ID
- if (reboot == 4)
- {
- if (strfind(read, "<model>") == -1) continue;
- new modid = strlen("<model>");
- lines = 0;
- for(new i = modid+4; i < 128; i++)
- {
- if (read[i] == '<') break;
- format(string, 1, "%c", read[i]);
- strins(ObjectStr, string, lines);
- lines++;
- }
- ObjectModel = strval(ObjectStr);
- reboot = 1;
- break;
- }
- }
- format(string, sizeof string, \"\seif_convert\SA-MP\%s.pwn", fn);
- new File:newfile;
- if (!fexist(string)) newfile = fopen(string, io_write);
- else newfile = fopen(string, io_append);
- if (newfile)
- {
- if (ObjectModel == 0)
- {
- printf("|- Objects successfully converted as %s.pwn -|", fn);
- return 1;
- }
- if (times == 0)
- {
- fwrite(newfile, "/*\n\r Converted with seif_convert - by Seif\n\r visit 'http://gtamap.delux-host.com/' for an online converter\n\r*/\n\r\n\r");
- }
- format(string, sizeof string, "CreateObject(%d, %f, %f, %f, %f, %f, %f); // %s - seif_convert\r\n", ObjectModel, ObjectX, ObjectY, ObjectZ, ObjectrX, ObjectrY, ObjectrZ, ObjectName);
- fwrite(newfile, string);
- fclose(newfile);
- times++;
- }
- format(ObjectName, 128, "");
- format(ObjectStr, 128, "");
- ObjectModel = 0;
- ObjectX = 0;
- ObjectY = 0;
- ObjectZ = 0;
- ObjectrX = 0;
- ObjectrY = 0;
- ObjectrZ = 0;
- goto WHILELOOP;
- }
- }
- return 1;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[128];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock longstr(const string[], &idx)
- {
- new length = strlen(string);
- while ((idx < length) && (string[idx] <= ' '))
- {
- idx++;
- }
- new offset = idx;
- new result[128];
- while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
- {
- result[idx - offset] = string[idx];
- idx++;
- }
- result[idx - offset] = EOS;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement