Ich gruesse euch liebe Community,
Ich habe aktuell ein kleines Programm geschrieben mit welchem ich rasant Objekte in ein anderes Format bringen kann, z.B. CreateObject in MTA:SA Format etc.
Das einzige was ich jetzt nach mehreren Wochen nicht schaffe, ist das Umwandeln von MTA:SA in ein anderes Format, weil ich es einfach nicht Schaffe die Attribute aus so einer .map Datei zu parsen.
Ich habe leider keinerlei Ahnung von XML Parsern da ich erst ein halbes Jahr Informatik bzw. C studiere, und XML Parser maximal kompliziert finde, und als Koenigsdisziplin im programmieren sehe, komme ich so nicht weiter.
Ich habe schon probiert eine Objektzeile mit sscanf aufzuteilen so dass ich am Ende sowas wie
Read String2 |model="17033"|
Read String4 |posX="-1038.4"|
Read String5 |posY="-951.20001"|
Read String6 |posZ="-7.1"|
Read String7 |rotX="23.786"|
Habe, aber auch da weiss ich nicht wie ich die Zahlen da rauskriege.
Hat jemand einen Tipp?
Hier einmal mein ganzes Programm:
#include <stdio.h>
/*
(1) CreateObject
(2) CreateDynamicObject
(3) MTA_SA
*/
int inputtype=0;
int outputtype=0;
objecttype()
{
printf("\nValid Object types\n");
printf("CreateObject: (1)\n");
printf("CreateDynamicObject: (2)\n");
printf("MTA_SA: (3)\n");
}
int main ( int argc, char *argv[] )
{
if ( argc != 2 )
{
printf( "Usage: %s [filename]\n", argv[0] );
}
else
{
FILE *fIn = fopen(argv[1], "r");
if ( fIn == 0 )
{
printf( "Could not open file\n" );
}
else
{
int inputtype=0;
int i=0;
int model = 0, items = 0;
float pos[3] = {0}, rot[3] = {0};
objecttype();
printf("\nSpecify input object type:\n");
scanf("%i",&inputtype);
if(inputtype != 1 || inputtype != 2 || inputtype != 3)
{
objecttype();
}
int outputtype=0;
printf("\nSpecify output object type:\n");
scanf("%i",&outputtype);
if(outputtype != 1 || inputtype != 2 || inputtype != 3)
{
objecttype();
}
if(outputtype == inputtype)
{
printf("You cannot convert objects into the same type!");
}
else
{
printf("\nSimple SA-MP to MTA-SA Object Converter\n");
FILE *fOut = fopen("output.txt", "wb");
if(inputtype == 1)//CreateObject
{
while ((items = fscanf(fIn, "%*[^-0123456789]%d%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*s", &model, &pos[0], &pos[1], &pos[2], &rot[0], &rot[1], &rot[2])) != EOF)
{
if(outputtype == 3)
{
if (items == 7)
{
fprintf(fOut, "<object id=\"object (Konvert)(%d)\" breakable=\"true\" interior=\"0\" collisions=\"true\" alpha=\"255\" model=\"%d\" doublesided=\"false\" scale=\"1\" dimension=\"0\" posX=\"%.7g\" posY=\"%.7g\" posZ=\"%.7g\" rotX=\"%.7g\" rotY=\"%.7g\" rotZ=\"%.7g\"></object>\n", i,model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
i++;
}
}
if(outputtype == 2)
{
if (items == 7)
{
fprintf(fOut, "CreateDynamicObject(%d,%f,%f,%f,%f,%f,%f);// Object (%d)\n",model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2],i);
i++;
}
}
}
}
if(inputtype == 2)//CreateDynamicObject
{
while ((items = fscanf(fIn, "%*[^-0123456789]%d%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*[,]%f%*s", &model, &pos[0], &pos[1], &pos[2], &rot[0], &rot[1], &rot[2])) != EOF)
{
if(outputtype == 3)
{
if (items == 7)
{
fprintf(fOut, "<object id=\"object (Konvert)(%d)\" breakable=\"true\" interior=\"0\" collisions=\"true\" alpha=\"255\" model=\"%d\" doublesided=\"false\" scale=\"1\" dimension=\"0\" posX=\"%.7g\" posY=\"%.7g\" posZ=\"%.7g\" rotX=\"%.7g\" rotY=\"%.7g\" rotZ=\"%.7g\"></object>\n", i,model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
i++;
}
}
if(outputtype == 1)
{
if (items == 7)
{
fprintf(fOut, "CreateObject(%d,%f,%f,%f,%f,%f,%f);// Object (%d)\n",model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2],i);
i++;
}
}
}
}
if(inputtype == 3)//MTA_SA
{
while ((items = fscanf(fIn, "%*[^-0123456789a-zA-Z=<>/ \t \"]\"%d%f%f%f%f%f%f%",&model, &pos[0], &pos[1], &pos[2], &rot[0], &rot[1], &rot[2])) != EOF)
{
if(outputtype == 2)
{
if (items == 7)
{
fprintf(fOut, "CreateDynamicObjectObject(%d,%f,%f,%f,%f,%f,%f);// Object (%d)\n",model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2],i);
i++;
}
}
if(outputtype == 1)
{
if (items == 7)
{
fprintf(fOut, "CreateObject(%d,%f,%f,%f,%f,%f,%f);// Object (%d)\n",model, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2],i);
i++;
}
}
}
}
fclose(fOut);
fclose(fIn);
printf("%d Objekt(e) konvertiert.\n\n",i);
return 0;
}
}
}
}
Alles anzeigen