Convert Objects into another format
#1

Ahoy friends

Currently i want to convert huge amounts of CreateObjects into MTA Server objects vise versa.
Unfortunately these online converter stuff doesnt work with more than 40000 Objects so i tried to write something in PAWN to realize that.

Код:
#include <a_samp>
#include <sscanf2>
#include <file>





main ()
{
	new str[1024]; 
	new File:example = fopen("createobject.txt", io_read);
	new i=0;
	while(fread(example, str))
	{
		new string[512];
		i++;
		new modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance = 0.0;
		new CreateObjectString[1024];
		format(string, sizeof(string), "%s %s", string, str);
		if(sscanf(string, "ifffffff", modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance))
		format(CreateObjectString,sizeof(CreateObjectString),"<object id="%d" breakable="true" interior="0" collisions="true" alpha="255" model="%d" doublesided="false" scale="1" dimension="0" posX="%f" posY="%f" posZ="%f" rotX="%f" rotY="%f" rotZ="%f"></object>",i, modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ);
		new File:handle = fopen("output.txt", io_write);

		
		if(handle)
		{
			
			fwrite(handle,CreateObjectString);


			fclose(handle);
		}
		else
		{
			print("Failed to open file");
		}
		
		
	}
	fclose(example); 
	printf("%s",string);
	return 0x01;
	
	
}
Unfortunately it doesnt seem to work because of the string length maybe? Is it better to write it in C instead? Is there a similiar sscanf function in C? Maybe someone can help me
Reply
#2

Why don't you just convert the first 40.000 objects, then the next ones and so on?

This is so unnecessary unless you're doing it to learn new things.
Reply
#3

Of course i want to learn new thing as well.

I got around 1.000.000 Objects and i dont want to convert them online again and again when i edit something
It will take hours on convertffs.com
Reply
#4

One million objects, wow. I think there are only about 50k objects in the original game (only 20k unique object models). If we assume that each line in the file is about 0.2 kilobyte then everything together is about 200 megabytes in size. That's a lot. It's going to take ages regardless.

I think your best bet is an XML parser. Most high-level languages will have one built in.
Reply
#5

Yeah i put all maps i made from 2007 until now and put them into one file its really huge
Reply
#6

Thanks for your help but this XML stuff seems to be complicated for me :/
Thats what i have currently
Its working except the sscanf part. Whats my mistake?
I always get 0 for every value

Код:
#include <a_samp>
#include <sscanf2>
#include <file>





main ()
{
	new str[1024]; 
	new File:example = fopen("createobject.txt", io_read);
	new i=0;
	while(fread(example, str))
	{
		new string[512];
		new val;
		i++;
		new modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance = 0.0;
		new CreateObjectString[1024];
		format(string, sizeof(string), "%s %s", string, str);
		sscanf(str, "ifffffff", modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance);
		format(CreateObjectString,sizeof(CreateObjectString),"<object id=\"%d\" breakable=\"true\" interior=\"0\" collisions=\"true\" alpha=\"255\" model=\"%d\" doublesided=\"false\" scale=\"1\" dimension=\"0\" posX=\"%f\" posY=\"%f\" posZ=\"%f\" rotX=\"%f\" rotY=\"%f\" rotZ=\"%f\"></object>",i, modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ);
		new File:handle = fopen("output.txt", io_write);

		
		if(handle)
		{
			
			fwrite(handle,CreateObjectString);


			fclose(handle);
		}
		else
		{
			print("Failed to open file");
		}
		
		
	}
	fclose(example); 
	return 0x01;
	
	
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)