Problem ist jedoch: Ich schaffe es einfach nicht mit dem MTA XML Format umzugehen
Bei CreateObject habe ich einfach die Kommas ignorieren lassen, aber hier haben wir ja Strings und viele andere Symbole zwischen jedem Float und Integer Wert was das ganze fuer mich unmoeglich macht.
Habe mir auch ein XML Schema gebaut, wenn das ueberhaupt korrekt ist.
Habe leider nie zuvor mit XML gearbeitet.
Wie kann ich es hinkriegen mit einem beliebigen XML Parser, aus der Objektzeile die Werte rauszuparsen? Hat jemand da eventuell ein Beispiel damit ich mich daran orientieren kann?
Danke schonmal vorab.
Will eine offlinevariante von ConvertFFS machen, vorallem bei fetten Dateien geht das Ding nicht
Weiterhin habe ich das Problem dass bei fetten Files mein Programm nicht terminiert.
Weiss jemand warum? Bei kleinen Files kein Problem.
Es wird zwar erfolgreich konvertiert, aber es terminiert dennoch nicht.
#include <stdio.h>
#include <asm-xml.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
{
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]);
}
}
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]);
}
}
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, "%*[^-0123456789]%d%f%f%f%f%f%f%",&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]);
}
}
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);
}
}
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