Schönes programm nur stellt sich mir die frage: Ich kann von MTA zu SAMP konvertieren, geht das auch von SAMP zu MTA?
Jo das geht auch, kannst von jedem der 3 Formate in jedes der 3 Formate konvertieren und umgekehrt
Schönes programm nur stellt sich mir die frage: Ich kann von MTA zu SAMP konvertieren, geht das auch von SAMP zu MTA?
Jo das geht auch, kannst von jedem der 3 Formate in jedes der 3 Formate konvertieren und umgekehrt
Moin
Ich habe mir mal einen kleinen Objektkonverter zusammengebaut, aus dem einfachen Grund, da mein Lieblingsonlinekonverter convertffs.com seit einiger Zeit offline ist, und ich super oft reichlich Objekte konvertieren muss.
Da ich gerne minimalistisch Programmiere ist das ganze als Commandline Programm erschienen.
Weiterhin hat mich gestoert dass bei grossen Maps, das Hochladen von grossen Maps ab 5000 Objekten nicht moeglich war, und auch darunter ewigst lange gedauert habe.
Habe mir fuer meine Zwecke daher einen kleinen C basierten Konverter gebastelt, welcher mithilfe von fscanf und sscanf die Werte parst und letztendlich einfach wieder in ein anderes Format bringt, und dann printet.
Aktuell gibt es das ganze als Linux und Windows Version, weiterhin will ich darauf hinweisen dass das Programm Bugs enthalten kann.
Wenn Bugs gefunden werden, bitte eine E-Mail an [email protected] verfassen, oder in diesem Thread hier schreiben.
Auf Effizienz wurde bisher nicht geachtet, da selbst bei knapp 100000 Objekten das Konvertieren im Worst Case, d.h. MTA:SA zu SA:MP CreateObject nur ca. 1.6 Sekunden dauert.
Die Laufzeit des Programs ist nach O-Notation im Best Case ne Laufzeit von O(3n) , und im Worst Case (MTA:SA zu SA:MP) ca. O(6n)
Ziel ist es, neben reinem Objekte Konvertieren, auch das Konvertieren von Fahrzeugen, Peds/Actors, Pickups etc. zu ermoegliche, wie im SA-MP MapConverter Plugin im englischen SA-MP Forum.
Aktuell werden Zeilen, welche Vehicle, Peds oder Pickups enthalten uebersprungen!
Readme
Copyright (C) 2017 Fabian Druschke (Knogle)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/
Compiler settings:
Linux: gcc simpleconverter.c
Windows MinGW: gcc simpleconverter.c
Usage:
Linux: ./a.out foo.map
Windows: a foo.map
Output file output.txt will be written into the same directory.
Alles anzeigen
Ein Beispiel Ablauf
Datei ist converter.exe und wird mit der Inputdatei als Parameter ausgefuehrt.
(Geht auch per Batch datei, z.B. mit Inhalt:
converter.exe input.txt)
converter.exe objects.txt
Ausgabe wird in der Datei output.txt erstellt, das ganze funktioniert zumindest bei mir aktuell zuverlaessig.
Dannach spezifiziert man mit einer Zahl von 1-3 den Inputtyp der Objekte, und dannach wieder mit 1-3 den gewuenschten Output.
Fertig!
XML Parser wurde bisher nicht genutzt, ist wahrscheinlich fuer die Anforderungen overkill.
Weiterhin waere das Programm allein durch die Implementierung eines solchen, locker doppelt so lang.
Beispielinput:
<object id="object (des_ebrigroad07) (1)" breakable="true" interior="0" alpha="255" model="16358" doublesided="false" scale="1" dimension="0" posX="-1135.2" posY="-866.29999" posZ="62.5" rotX="0" rotY="0" rotZ="314"></object>
<object id="object (des_ebrigroad07) (2)" breakable="true" interior="0" alpha="255" model="16358" doublesided="false" scale="1" dimension="0" posX="-1135.3" posY="-866.20001" posZ="72.7" rotX="0" rotY="0" rotZ="313.995"></object>
<object id="object (des_ebrigroad07) (3)" breakable="true" interior="0" alpha="255" model="16358" doublesided="false" scale="1" dimension="0" posX="-1140.6" posY="-871.40002" posZ="66.1" rotX="90" rotY="0" rotZ="313.995"></object>
Output:
CreateObject(16358,-1135.199951,-866.299988,62.500000,0.000000,0.000000,314.000000);// (des_ebrigroad07)
CreateObject(16358,-1135.300049,-866.200012,72.699997,0.000000,0.000000,313.994995);// (des_ebrigroad07)
CreateObject(16358,-1140.599976,-871.400024,66.099998,90.000000,0.000000,313.994995);// (des_ebrigroad07)
Ich hoffe es ist fuer jemanden, wie in der Lizenz bereits erwaehnt, useful Updates folgen woechentlich
Weiterhin habe ich vor auch andere Objektformate abzudecken.
Download:
https://github.com/Knogle/SimpleConverter
Oder Source only:
Benutz einfach eine XML Lib. Wie pugiXML. Kein grund das Rad neuzuerfinden.
Leider habe ich keine Ahnung von C++, nur von C daher kenne ich mich mit pugiXML nicht aus
Habe es geschafft was den Inhalt zu parsen den ich brauche, jedoch wohl ziemlich ineffizient
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str1[32], str2[32], str3[32], str4[32], str5[32], str6[32] ,str7[32], str8[32], str9[32] , strd[32];
float posX,posY,posZ,rotX,rotY,rotZ;
float a,b,c,d,e,f,g,h;
FILE * fp;
fp = fopen ("file.txt", "w+");
fputs("<object id=\"object (cunt_rockgp2_15) (5)\" breakable=\"true\" interior=\"0\" collisions=\"true\" alpha=\"255\" model=\"17033\" doublesided=\"false\" scale=\"1\" dimension=\"0\" posX=\"-1038.4\" posY=\"-951.20001\" posZ=\"-7.1\" rotX=\"23.786\" rotY=\"59.445\" rotZ=\"196.584\"></object>", fp);
char string[]="<object id=\"object (cunt_rockgp2_15) (5)\" breakable=\"true\" interior=\"0\" collisions=\"true\" alpha=\"255\" model=\"17033\" doublesided=\"false\" scale=\"1\" dimension=\"0\" posX=\"-1038.4\" posY=\"-951.20001\" posZ=\"-7.1\" rotX=\"23.786\" rotY=\"59.445\" rotZ=\"196.584\"></object>";
rewind(fp);
char searchchar = '\"';
char replacechar = ' ';
char *valueptr;
valueptr = strchr(string, searchchar);
if(valueptr != NULL)
*valueptr = replacechar;
while (valueptr !=NULL)
{
valueptr = strchr(valueptr + 1, searchchar);
if(valueptr != NULL)
*valueptr = replacechar;
}
searchchar = '=';
replacechar = ' ';
valueptr = strchr(string, searchchar);
if(valueptr != NULL)
*valueptr = replacechar;
while (valueptr !=NULL)
{
valueptr = strchr(valueptr + 1, searchchar);
if(valueptr != NULL)
*valueptr = replacechar;
}
//printf("%s",string);
sscanf(string,"%*s %*s %*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %s %s %*s %*s %*s %*s %*s %*s %s %*s %s %*s %s %*s %s %*s %s %*s %s",str1,str2,str3,str4,str5,str6 ,str7,str8,str9);
printf("str1: %s str2: %s str4: %s str5: %s str6: %s str7: %s str8: %s str9: %s",str1,str2,str4,str5,str6 ,str7,str8,str9);
int t;
t = atoi(str2);
posX = atof(str4);
posY = atof(str5);
posZ = atof(str6);
rotX = atof(str7);
rotY = atof(str8);
rotZ = atof(str9);
printf("\n\n\n %d\n",t);
printf("\n %f",posX);
printf("\n %f",posY);
printf("\n %f",posZ);
printf("\n %f",rotX);
printf("\n %f",rotY);
printf("\n %f",rotZ);
fclose(fp);
return(0);
}
Alles anzeigen
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