Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* GTA SA-MP
- * In-game MAP convertor
- * By Roox 2011
- */
- #include <a_samp>
- #define Dialog_Convertor 0
- //----- Change to 0 if you want to disable this MTA type
- #define Support_LUA 1
- #define Support_MTA_Race 1
- #define Support_MTA_DEATHMATCH 1
- #define Support_MTA1 1
- public OnFilterScriptInit()
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp(cmdtext, "/convert", true, 8))
- {
- if(strlen(cmdtext) < 9)
- {
- new string[128];
- format(string, sizeof(string), "Napište název mapy bez koncovky .map\n\nPodporováno:");
- #if Support_LUA
- strcat(string, "\nLua for MTA");
- #endif
- #if Support_MTA_Race
- strcat(string, "\nMTA Race");
- #endif
- #if Support_MTA_DEATHMATCH
- strcat(string, "\nMTA Death Match");
- #endif
- #if Support_MTA1
- strcat(string, "\nMTA 1.0");
- #endif
- ShowPlayerDialog(playerid, Dialog_Convertor, DIALOG_STYLE_INPUT, "Map convertor:", string, "Potvrdit", "Konec");
- }
- else
- {
- PlayerConvertMap(playerid, cmdtext[9]);
- }
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == Dialog_Convertor)
- {
- if(response)
- {
- if(strlen(inputtext) > 0)
- {
- PlayerConvertMap(playerid, inputtext);
- }
- }
- }
- return 1;
- }
- stock PlayerConvertMap(playerid, mapname[])
- {
- new filename[28], pwnfile[28];
- format(filename, sizeof(filename), "%s.map", mapname);
- format(pwnfile, sizeof(pwnfile), "%s.pwn", mapname);
- SendClientMessage(playerid, 0xFFFF00AA, "Map convertor:");
- switch(ConvertMap(filename, pwnfile))
- {
- case -1: SendClientMessage(playerid, 0xFFFFFFAA, "Soubor nebyl nalezen.");
- case 0: SendClientMessage(playerid, 0xFFFFFFAA, "Soubor úspěšně zkonvertován. (Typ mapy: LUA)");
- case 1: SendClientMessage(playerid, 0xFFFFFFAA, "Soubor úspěšně zkonvertován. (Typ mapy: MTA 1.0)");
- case 2: SendClientMessage(playerid, 0xFFFFFFAA, "Soubor úspěšně zkonvertován. (Typ mapy: MTA Death Match)");
- case 3: SendClientMessage(playerid, 0xFFFFFFAA, "Soubor úspěšně zkonvertován. (Typ mapy: MTA Race)");
- case 4: SendClientMessage(playerid, 0xFFFFFFAA, "Tento typ MTA mapy není podporován.");
- }
- return 1;
- }
- stock ConvertMap(filename[], filetowrite[])
- {
- new File:MapFile = fopen(filename, io_read);
- //-----
- new bool:MapDetected = false;
- new MapType = 0;
- //-----
- if(MapFile)
- {
- if(fexist(filetowrite)) fremove(filetowrite);
- new File:PWNFile = fopen(filetowrite, io_write);
- //-----
- fwrite(PWNFile, "#include <a_samp>\n\npublic OnFilterScriptInit()\n{\n");
- //-----
- new strFromFile[258], strtowrite[128];
- while(fread(MapFile, strFromFile, sizeof(strFromFile)))
- {
- StripNewLine(strFromFile);
- if(strcmp(strFromFile, "createObject", true, 12)) // Detecting LUA code
- {
- if(MapDetected == false)
- {
- if(!strcmp(strFromFile, "<map edf:definitions=\"", true, 22)) // MTA 1.0 Map
- {
- #if !Support_MTA1
- fclose(PWNFile);
- fclose(MapFile);
- return 4;
- #else
- MapDetected = true;
- MapType = 1;
- continue;
- #endif
- }
- else if(!strcmp(strFromFile, "<map mod=\"deathmatch\">", true, 21)) // Deathmatch
- {
- #if !Support_MTA_DEATHMATCH
- fclose(PWNFile);
- fclose(MapFile);
- return 4;
- #else
- MapDetected = true;
- MapType = 2;
- continue;
- #endif
- }
- else if(!strcmp(strFromFile, "<map mod=\"race\" version=\"", true, 25)) // Race
- {
- #if !Support_MTA_Race
- fclose(PWNFile);
- fclose(MapFile);
- return 4;
- #else
- MapDetected = true;
- MapType = 3;
- continue;
- #endif
- }
- }
- }
- else
- {
- MapDetected = true;
- #if !Support_LUA
- fclose(PWNFile);
- fclose(MapFile);
- return 4;
- #endif
- }
- if(MapDetected == true)
- {
- new Model = -1, Float:pos[6];
- new PosCount, bool:IsObject;
- switch(MapType)
- {
- case 0: // LUA for MTA
- {
- for(new a = 12; a < strlen(strFromFile); a++)
- {
- if(strFromFile[a] == '(')
- {
- Model = strval(strFromFile[a+1]);
- printf("Model: %d", Model);
- if(Model < 10) a+=2;
- else if(Model < 100) a += 3;
- else if(Model < 1000) a += 4;
- else if(Model < 10000) a += 5;
- else a += 6;
- continue;
- }
- if(Model != -1)
- {
- if(IsCharNumeric(strFromFile[a]))
- {
- if(PosCount < 6) pos[PosCount] = floatstr(strFromFile[a]);
- else continue;
- if(strcmp(strFromFile[a], "0.0", true, 3))
- {
- for(new t = 1; t < 10; t++)
- {
- if(strFromFile[a+t] == ',')
- {
- a += t;
- break;
- }
- }
- }
- else
- {
- a += 2;
- }
- printf("Pos: %f", pos[PosCount]);
- PosCount++;
- }
- }
- }
- format(strtowrite, sizeof(strtowrite), " CreateObject(%d, %f, %f, %f, %f, %f, %f);\r", Model, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
- fwrite(PWNFile, strtowrite);
- }
- case 1, 2: // MTA 1.0 & Death Match
- {
- for(new a = 0; a < strlen(strFromFile); a++)
- {
- if(IsObject == false)
- {
- if(!strcmp(strFromFile[a], "object", true, 6))
- {
- IsObject = true;
- }
- continue;
- }
- else
- {
- new savetovalue = DetectSavingValue(strFromFile, a);
- if(savetovalue == 6)
- {
- a += 7;
- new strfloat[18];
- for(new k = 0; k < 18; k ++)
- {
- if(strFromFile[a+k] != '\"')
- {
- strfloat[k] = strFromFile[a+k];
- }
- else
- {
- a += k;
- break;
- }
- }
- Model = strval(strfloat);
- }
- else if(savetovalue != -1)
- {
- a += 6;
- new strfloat[18];
- for(new k = 0; k < 18; k ++)
- {
- if(strFromFile[a+k] != '\"')
- {
- strfloat[k] = strFromFile[a+k];
- }
- else
- {
- a += k;
- break;
- }
- }
- pos[savetovalue] = floatstr(strfloat);
- }
- }
- }
- if(Model != -1)
- {
- format(strtowrite, sizeof(strtowrite), " CreateObject(%d, %f, %f, %f, %f, %f, %f);\r", Model, pos[0], pos[1], pos[2], pos[3], pos[4], pos[5]);
- fwrite(PWNFile, strtowrite);
- }
- }
- case 3: // MTA Race
- {
- for(new x = 0; x < strlen(strFromFile); x++)
- {
- if(!strcmp(strFromFile[x], "<object", true, 7))
- {
- // <position>
- fread(MapFile, strFromFile, sizeof(strFromFile));
- StripNewLine(strFromFile);
- for(new a = x; a < strlen(strFromFile); a++)
- {
- if(strFromFile[a-1] == '>')
- {
- for(new y = 0; y < 3; y++)
- {
- pos[PosCount] = floatstr(strFromFile[a]);
- PosCount++;
- for(new k = 0; k < 18; k++)
- {
- if(strFromFile[a+k] == ' ' || strFromFile[a+k] == '<')
- {
- a += k+1;
- break;
- }
- }
- }
- }
- }
- // <rotation>
- fread(MapFile, strFromFile, sizeof(strFromFile));
- StripNewLine(strFromFile);
- for(new a = x; a < strlen(strFromFile); a++)
- {
- if(strFromFile[a-1] == '>')
- {
- for(new y = 0; y < 3; y++)
- {
- pos[PosCount] = floatstr(strFromFile[a]);
- PosCount++;
- for(new k = 0; k < 18; k++)
- {
- if(strFromFile[a+k] == ' ' || strFromFile[a+k] == '<')
- {
- a += k+1;
- break;
- }
- }
- }
- }
- }
- for(new a = 3; a < 6; a++) // MTA Race have other rotations :/ Somewhat inaccurate, but works :D
- {
- if(pos[a] != 0.000000)
- {
- // pos[a] = 6.2831 + (pos[a]*0.0174);
- pos[a] = (pos[a]+6.2831)/0.0174;
- }
- }
- // <model>
- fread(MapFile, strFromFile, sizeof(strFromFile));
- StripNewLine(strFromFile);
- for(new a = x; a < strlen(strFromFile); a++)
- {
- if(strFromFile[a-1] == '>')
- {
- for(new y = 0; y < 3; y++)
- {
- Model = strval(strFromFile[a]);
- }
- }
- }
- format(strtowrite, sizeof(strtowrite), " CreateObject(%d, %f, %f, %f, %f, %f, %f);\r", Model, pos[0], pos[1], pos[2], pos[5], pos[4], pos[3]);
- fwrite(PWNFile, strtowrite);
- }
- }
- }
- }
- }
- }
- fwrite(PWNFile, " return 1;\n}");
- fclose(PWNFile);
- }
- else return -1;
- fclose(MapFile);
- return MapType;
- }
- stock StripNewLine(string[])
- {
- new len = strlen(string);
- if(string[0]==0) return ;
- //-----
- if ((string[len - 1] == '\n') || (string[len - 1] == '\r'))
- {
- string[len - 1] = 0;
- if (string[0]==0) return ;
- //-----
- if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
- }
- }
- stock IsCharNumeric(Char[])
- {
- if( Char[0] == '0' || Char[0] == '1' || Char[0] == '2' || Char[0] == '3' || Char[0] == '4' || Char[0] == '5' ||
- Char[0] == '6' || Char[0] == '7' || Char[0] == '8' || Char[0] == '9') return true;
- return false;
- }
- stock DetectSavingValue(string[], a)
- {
- if(!strcmp(string[a], "posX=", true, 5)) return 0;
- else if(!strcmp(string[a], "posY=", true, 5)) return 1;
- else if(!strcmp(string[a], "posZ=", true, 5)) return 2;
- else if(!strcmp(string[a], "rotX=", true, 5)) return 3;
- else if(!strcmp(string[a], "rotY=", true, 5)) return 4;
- else if(!strcmp(string[a], "rotZ=", true, 5)) return 5;
- else if(!strcmp(string[a], "model=", true, 6)) return 6;
- return -1;
- }
Add Comment
Please, Sign In to add comment