Advertisement
Hiddos

(Mirror) seif_convert

Apr 17th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.50 KB | None | 0 0
  1. /*
  2.                                 seif_convert - MTA to SA-MP map converter by Seif
  3. */
  4. /*x---------------------------------Important-------------------------------------x*/
  5. //**INCLUDES**//
  6. #include <a_samp>
  7. /*x---------------------------------Defining-------------------------------------x*/
  8. //**COLORS*//
  9. #define GREEN           0x21DD00FF
  10. #define RED             0xE60000FF
  11. #define ADMIN_RED       0xFB0000FF
  12. #define YELLOW          0xFFFF00FF
  13. #define ORANGE          0xF97804FF
  14. #define LIGHTRED        0xFF8080FF
  15. #define LIGHTBLUE       0x00C2ECFF
  16. #define PURPLE          0xB360FDFF
  17. #define PLAYER_COLOR    0xFFFFFFFF
  18. #define BLUE            0x1229FAFF
  19. #define LIGHTGREEN      0x38FF06FF
  20. #define DARKPINK        0xE100E1FF
  21. #define DARKGREEN       0x008040FF
  22. #define ANNOUNCEMENT    0x6AF7E1FF
  23. #define COLOR_SYSTEM    0xEFEFF7AA
  24. #define GREY            0xCECECEFF
  25. #define PINK            0xD52DFFFF
  26. #define DARKGREY        0x626262FF
  27. #define AQUAGREEN       0x03D687FF
  28. #define NICESKY         0x99FFFFAA
  29. #define WHITE           0xFFFFFFFF
  30. /*x---------------------------------CallBacks-------------------------------------x*/
  31. public OnFilterScriptInit()
  32. {
  33.     print("<|-----------------------------------------|>");
  34.     print(".:[- seif_convert - map converter by Seif -]:.");
  35.     print("<|-----------------------------------------|>");
  36.     return 1;
  37. }
  38.  
  39. public OnRconCommand(cmd[])
  40. {
  41.     new fn[128];
  42.     new rconcmd[128];
  43.     new idx;
  44.     rconcmd = strtok(cmd, idx);
  45.     if (!strcmp("convert", rconcmd, true))
  46.     {
  47.         fn = longstr(cmd, idx);
  48.         if (!strlen(fn)) return print("seif_convert: You must enter the file name to convert!");
  49.         new string[128];
  50.         new read[256];
  51.         new times;
  52.         format(string, sizeof string, \"\seif_convert\MTA\%s.map", fn);
  53.         if (!fexist(string)) return printf("seif_convert: %s.map doesn't exist!", fn);
  54.         new File:file = fopen(string, io_read);
  55.         if (file)
  56.         {
  57.             new
  58.                 ObjectName[128],
  59.                 Float:ObjectX,
  60.                 Float:ObjectY,
  61.                 Float:ObjectZ,
  62.                 Float:ObjectrX,
  63.                 Float:ObjectrY,
  64.                 Float:ObjectrZ,
  65.                 ObjectModel,
  66.                 ObjectXYZ[128],
  67.                 ObjectRot[128],
  68.                 ObjectStr[128],
  69.                 reboot = 1;
  70.             print("...");
  71.             WHILELOOP:
  72.             while (fread(file, read))
  73.             {
  74.                 new lines;
  75.  
  76.                 // Takes the object name
  77.                 if (reboot == 1)
  78.                 {
  79.                     if (strfind(read, "<object name=\"") == -1) continue;
  80.                     new id = strlen("<object name=\"");
  81.                     for(new i = id+1; i < 128; i++)
  82.                     {
  83.                         if (read[i] == '>') break;
  84.                         if (read[i] != '"')
  85.                         {
  86.                             format(string, 1, "%c", read[i]);
  87.                             strins(ObjectName, string, lines);
  88.                             lines++;
  89.                         }
  90.                     }
  91.                     reboot = 2;
  92.                     goto WHILELOOP;
  93.                     break;
  94.                 }
  95.                
  96.                 new CoordType = 1; // X
  97.                 //Gets the object's positions
  98.                 if (reboot == 2)
  99.                 {
  100.                     if (strfind(read, "<position>") == -1) continue;
  101.                     new posid = strlen("<position>");
  102.                     lines = 0;
  103.                     for(new i = posid+4; i < 128; i++)
  104.                     {
  105.                         if (read[i] != '<' && read[i] != ' ')
  106.                         {
  107.                             format(string, 1, "%c", read[i]);
  108.                             strins(ObjectXYZ, string, lines);
  109.                             lines++;
  110.                         }
  111.                         else if (read[i] == ' ')
  112.                         {
  113.                             if (CoordType == 1)
  114.                             {
  115.                                 CoordType = 2;
  116.                                 ObjectX = floatstr(ObjectXYZ);
  117.                                 format(ObjectXYZ, 128, ""); // Y
  118.                                 lines = 0;
  119.                             }
  120.                             else if (CoordType == 2)
  121.                             {
  122.                                 CoordType = 3;
  123.                                 ObjectY = floatstr(ObjectXYZ);
  124.                                 format(ObjectXYZ, 128, ""); // Z
  125.                                 lines = 0;
  126.                             }
  127.                         }
  128.                         else if (read[i] == '<')
  129.                         {
  130.                             ObjectZ = floatstr(ObjectXYZ);
  131.                             lines = 0;
  132.                             break;
  133.                         }
  134.                     }
  135.                     reboot = 3;
  136.                     goto WHILELOOP;
  137.                     break;
  138.                 }
  139.                
  140.                 //Gets the object's rotations
  141.                 if (reboot == 3)
  142.                 {
  143.                     if (strfind(read, "<rotation>") == -1) continue;
  144.                     new rotid = strlen("<rotation>");
  145.                     lines = 0;
  146.                     CoordType = 1; // X
  147.                     for(new i = rotid+4; i < 128; i++)
  148.                     {
  149.                         if (read[i] != '<' && read[i] != ' ')
  150.                         {
  151.                             format(string, 1, "%c", read[i]);
  152.                             strins(ObjectRot, string, lines);
  153.                             lines++;
  154.                         }
  155.                         else if (read[i] == ' ')
  156.                         {
  157.                             if (CoordType == 1)
  158.                             {
  159.                                 CoordType = 2;
  160.                                 ObjectrZ = floatstr(ObjectRot);
  161.                                 ObjectrZ = (360 + (ObjectrZ / 0.0174532925));
  162.                                 while (ObjectrZ >= 360) ObjectrZ = ObjectrZ - 360;
  163.                                 while (ObjectrZ < 0) ObjectrZ = ObjectrZ + 360;
  164.                                 format(ObjectRot, 128, ""); // Y
  165.                                 lines = 0;
  166.                             }
  167.                             else if (CoordType == 2)
  168.                             {
  169.                                 CoordType = 3;
  170.                                 ObjectrY = floatstr(ObjectRot);
  171.                                 ObjectrY = (360 + (ObjectrY / 0.0174532925));
  172.                                 while (ObjectrY >= 360) ObjectrY = ObjectrY - 360;
  173.                                 while (ObjectrY < 0) ObjectrY = ObjectY + 360;
  174.                                 format(ObjectRot, 128, ""); // Z
  175.                                 lines = 0;
  176.                             }
  177.                         }
  178.                         else if (read[i] == '<')
  179.                         {
  180.                             ObjectrX = floatstr(ObjectRot);
  181.                             ObjectrX = (360 + (ObjectrX / 0.0174532925));
  182.                             while (ObjectrX >= 360) ObjectrX = ObjectrX - 360;
  183.                             while (ObjectrX < 0) ObjectrX = ObjectrX + 360;
  184.                             lines = 0;
  185.                             break;
  186.                         }
  187.                     }
  188.                     //printf("rotations: %f %f %f", ObjectX, ObjectY, ObjectZ);
  189.                     reboot = 4;
  190.                     goto WHILELOOP;
  191.                     break;
  192.                 }
  193.  
  194.                 //Gets the object's model ID
  195.                 if (reboot == 4)
  196.                 {
  197.                     if (strfind(read, "<model>") == -1) continue;
  198.                     new modid = strlen("<model>");
  199.                     lines = 0;
  200.                     for(new i = modid+4; i < 128; i++)
  201.                     {
  202.                         if (read[i] == '<') break;
  203.                         format(string, 1, "%c", read[i]);
  204.                         strins(ObjectStr, string, lines);
  205.                         lines++;
  206.                     }
  207.                     ObjectModel = strval(ObjectStr);
  208.                     reboot = 1;
  209.                     break;
  210.                 }
  211.             }
  212.            
  213.             format(string, sizeof string, \"\seif_convert\SA-MP\%s.pwn", fn);
  214.             new File:newfile;
  215.             if (!fexist(string)) newfile = fopen(string, io_write);
  216.             else newfile = fopen(string, io_append);
  217.             if (newfile)
  218.             {
  219.                 if (ObjectModel == 0)
  220.                 {
  221.                     printf("|- Objects successfully converted as %s.pwn -|", fn);
  222.                     return 1;
  223.                 }
  224.                 if (times == 0)
  225.                 {
  226.                     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");
  227.                 }
  228.                 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);
  229.                 fwrite(newfile, string);
  230.                 fclose(newfile);
  231.                 times++;
  232.             }
  233.             format(ObjectName, 128, "");
  234.             format(ObjectStr, 128, "");
  235.             ObjectModel = 0;
  236.             ObjectX = 0;
  237.             ObjectY = 0;
  238.             ObjectZ = 0;
  239.             ObjectrX = 0;
  240.             ObjectrY = 0;
  241.             ObjectrZ = 0;
  242.             goto WHILELOOP;
  243.         }
  244.     }
  245.     return 1;
  246. }
  247.  
  248. stock strtok(const string[], &index)
  249. {
  250.     new length = strlen(string);
  251.     while ((index < length) && (string[index] <= ' '))
  252.     {
  253.         index++;
  254.     }
  255.  
  256.     new offset = index;
  257.     new result[128];
  258.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  259.     {
  260.         result[index - offset] = string[index];
  261.         index++;
  262.     }
  263.     result[index - offset] = EOS;
  264.     return result;
  265. }
  266.  
  267. stock longstr(const string[], &idx)
  268. {
  269.     new length = strlen(string);
  270.     while ((idx < length) && (string[idx] <= ' '))
  271.     {
  272.         idx++;
  273.     }
  274.     new offset = idx;
  275.     new result[128];
  276.     while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
  277.     {
  278.         result[idx - offset] = string[idx];
  279.         idx++;
  280.     }
  281.     result[idx - offset] = EOS;
  282.     return result;
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement