[Plugin] [REL] XML loader
#21

Oh wow, nice plugin!
Reply
#22

Woow, This is really nice but is it possible to change infromation in the XML document?
Reply
#23

No, with this plugin you can only read them, writing features aren't supported yet but I'm planning to add them in future versions.
Reply
#24

Can I load with this plugin MTA maps?
Reply
#25

Quote:
Originally Posted by Romanius
Can I load with this plugin MTA maps?
Sure you can. I wrote a loading function today actually lol.

Код:
static
    ObjectCount,
    VehicleCount;


new ObjAttr[][] =
{
	"model",
	"posX",
	"posY",
	"posZ",
	"rotX",
	"rotY",
	"rotZ",
	"dimension",
	"interior"
};

stock LoadMapFile(const path[], Float:DrawDistance = 200.0, VehRespawn = 20)
{
	new
	  Str[9][40],
		XML:Map = xml_open(path);
	
	if(Map)
	{
		new
				Objects = xml_get_int(Map, "count(map/object)"),
		 		Vehicle = xml_get_int(Map, "count(map/vehicle)"),
		 		Max = max(Vehicle,Objects);
		
		for(new a=1,b=Max+1; a<b; a++)
		{
			if(Objects != 0 && Objects >= a)
	 		{
 				for(new c=0; c<sizeof(ObjAttr); c++)
   			{
					format(Str[c], sizeof(Str[]), "map/object[%d]/@%s",a,ObjAttr[c]);
				}
				CreateDynamicObject(xml_get_int(Map,Str[0]),xml_get_float(Map,Str[1]),xml_get_float(Map,Str[2]),xml_get_float(Map,Str[3]),xml_get_float(Map,Str[4]),xml_get_float(Map,Str[5]),xml_get_float(Map,Str[6]),xml_get_int(Map,Str[7]),xml_get_int(Map,Str[8]),-1,DrawDistance);
				ObjectCount++;
			}
			if(Vehicle != 0 && Vehicle >= a)
	 		{
 				for(new c=0; c<sizeof(ObjAttr); c++) //Same attributes for vehicles..
   			{
	    		  if(c == 4 || c == 5) continue;
					format(Str[c], sizeof(Str[]), "map/vehicle[%d]/@%s",a,ObjAttr[c]);
				}
				CreateVehicleEx(xml_get_int(Map,Str[0]),xml_get_float(Map,Str[1]),xml_get_float(Map,Str[2]),xml_get_float(Map,Str[3]),xml_get_float(Map,Str[6]),xml_get_int(Map,Str[7]),xml_get_int(Map,Str[8]),-1,-1,VehRespawn);
				VehicleCount++;
			}
		}
  	xml_close(Map);
		return 1;
	}
	printf(" ** Map was not found at path \"%s\".", path);
	return 1;
}
Its not the most efficient thing on the planet, but it gets the job done. At the moment it only supports MTA 1.0.

please note that this example uses incognito's streamer, and my own personal CreateVehicleEx function. You can easily adapt it to any format though.


EDIT: I updated the code, and managed to remove a loop; its still a little slow, so i suggest only using it under OnGameModeInit and OnFilterScriptInit. Please ignore the indentation lol, forums always mess it up :\.
Reply
#26

Quote:
Originally Posted by Zeex
No, with this plugin you can only read them, writing features aren't supported yet but I'm planning to add them in future versions.
Cool, I might use this in my script when it has the writing features. Looks really good at the moment, Good work
Reply
#27

File position? i created 'account.xml' on 'scriptfiles' and not work.
Reply
#28

Quote:
Originally Posted by [TLV
ReVo_ ]
File position? i created 'account.xml' on 'scriptfiles' and not work.
If you used the one on the main page then I think it is.
Код:
.../scriptfiles/players
Reply
#29

No,i put 'profile' in the /scriptfiles/players and not worked.
Reply
#30

I just looked at the example and relised that you put the account.xml into the scriptfiles area and the ../profile is the stuff that is inside the .xml file. Maybe your not loading it right?
Reply
#31

HELP

Unable to connect XML
My code:
Код:
#define LANGUAGE_FILE_XML "Languages.xml"
new XML:LangXML;
forward XMLConnect();
forward XMLExit();
public OnFilterScriptInit()
{
	XMLConnect();
}

public OnFilterScriptExit()
{
  XMLExit();
}

public XMLConnect()
{
    LangXML=xml_open(LANGUAGE_FILE_XML);
	if(!LangXML)
	{
	    SetConsoleTextColors(CONSOLE_RED);
	    printf("XML Bağlantısı Başarısız...");
	    SetConsoleTextColors(CONSOLE_DEFAULT);
		return 1;
	}
	else
	{
		SetConsoleTextColors(CONSOLE_GREEN);
		printf("XML Bağlantısı Başarılı...");
		SetConsoleTextColors(CONSOLE_DEFAULT);
		return 1;
	}
}

public XMLExit()
{
    xml_close(LangXML);
}
Reply
#32

I have made a new version which also has functions for document building/modification, if you want to try it out you can download it here. See include file for functions description. Have fun!
Reply
#33

Zeex nice! But where examples for new version?

I cant use write functions without examples
Reply
#34

Thats actually amazing, nice work
Reply
#35

Maybe create function to parse xml files from sites (like RSS) ? I can help you with this
Reply
#36

XML is better than the files, if yes, why? Is faster, or what? I ask because i do not know XML.
Reply
#37

Quote:
Originally Posted by Tronix
Посмотреть сообщение
XML is better than the files, if yes, why? Is faster, or what? I ask because i do not know XML.
Hi,

XML is a format. And XML files are also files. So you can't say that it is faster than anything.
It depends on the implantation whether something is faster or slower. This implantation should be at least as fast as pawn based INI and XML parsers or even faster. But it COULD be slower than ungeneric, undynamic, specialized file loading and saving code in pawn.

An INI file contains sections, comments and keys containing values:
[player1]
money=100

A XML file contains nested elements:
<root>
<player1>
<money>100</money>
</player1>
</root>

It is up to you which format you think is better to use.
Reply
#38

So in total, it is the same. To read from a file specific key, we need a loop to check a file line by line. The XML is probably just a normal read / write to file. However, the design file is different. Well I'm saying?

I am pole, sorry for my english :P.
Reply
#39

This plugin isn't good for MTA loading. I've got a MTA map with about 5,000 objects and loading with this plugin took 53 seconds. File (fopen, fread) algorithm did this in about 1 second.
Reply
#40

Nice plugin!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)