Jump to content

Any resource to save vehicles?


Recommended Posts

Check this out:

addCommandHandler("savecars", function() --Backup function.
	--You should make an ADMIN rights check.
	if fileExists("settings.xml") then
		fileDelete('settings.xml');
	end
	local cars = xmlCreateFile("settings.xml", "cars");
	for _,v in ipairs(getElementsByType("vehicle")) do
		local TheCar = xmlCreateChild(cars, "car");
		local x,y,z = getElementPosition(v);
		local rotX,rotY,rotZ = getElementRotation(v);
		xmlNodeSetAttribute(TheCar, "model", getElementModel(v));
		xmlNodeSetAttribute(TheCar, "x", x);
		xmlNodeSetAttribute(TheCar, "y", y);
		xmlNodeSetAttribute(TheCar, "z", z);
		xmlNodeSetAttribute(TheCar, "rotx", rotX);
		xmlNodeSetAttribute(TheCar, "roty", rotY);
		xmlNodeSetAttribute(TheCar, "rotz", rotZ);
	end
	outputChatBox("Car backup done!", root, 0, 255, 0, false);
	xmlSaveFile(cars);
	xmlUnloadFile(cars);
end);

addCommandHandler("loadcars", function() --Load function.
	-- You should make an ADMIN rights check.
	local cars = xmlLoadFile("settings.xml");
	if (cars)then
		local veh = xmlNodeGetChildren(cars);
		for _,v in ipairs(veh) do
		   local Model = xmlNodeGetAttribute (v, "model");
		   local X = xmlNodeGetAttribute (v, "x");
		   local Y = xmlNodeGetAttribute (v, "y");
		   local Z = xmlNodeGetAttribute (v, "z");
		   local Rotx = xmlNodeGetAttribute (v, "rotx");
		   local Roty = xmlNodeGetAttribute (v, "roty");
		   local Rotz = xmlNodeGetAttribute (v, "rotz");
		   createVehicle(tonumber(Model), tonumber(X), tonumber(Y), tonumber(Z), tonumber(Rotx), tonumber(Roty), tonumber(Rotz));
		end
	outputChatBox("All cars loaded!", root, 0, 255, 0, false);
	end
end);

 

  • Like 1
Link to comment
  • Scripting Moderators
On 2017-5-23 at 20:51, Tekken said:

Check this out:


addCommandHandler("savecars", function() --Backup function.
	--You should make an ADMIN rights check.
	if fileExists("settings.xml") then
		fileDelete('settings.xml');
	end
	local cars = xmlCreateFile("settings.xml", "cars");
	for _,v in ipairs(getElementsByType("vehicle")) do
		local TheCar = xmlCreateChild(cars, "car");
		local x,y,z = getElementPosition(v);
		local rotX,rotY,rotZ = getElementRotation(v);
		xmlNodeSetAttribute(TheCar, "model", getElementModel(v));
		xmlNodeSetAttribute(TheCar, "x", x);
		xmlNodeSetAttribute(TheCar, "y", y);
		xmlNodeSetAttribute(TheCar, "z", z);
		xmlNodeSetAttribute(TheCar, "rotx", rotX);
		xmlNodeSetAttribute(TheCar, "roty", rotY);
		xmlNodeSetAttribute(TheCar, "rotz", rotZ);
	end
	outputChatBox("Car backup done!", root, 0, 255, 0, false);
	xmlSaveFile(cars);
	xmlUnloadFile(cars);
end);

addCommandHandler("loadcars", function() --Load function.
	-- You should make an ADMIN rights check.
	local cars = xmlLoadFile("settings.xml");
	if (cars)then
		local veh = xmlNodeGetChildren(cars);
		for _,v in ipairs(veh) do
		   local Model = xmlNodeGetAttribute (v, "model");
		   local X = xmlNodeGetAttribute (v, "x");
		   local Y = xmlNodeGetAttribute (v, "y");
		   local Z = xmlNodeGetAttribute (v, "z");
		   local Rotx = xmlNodeGetAttribute (v, "rotx");
		   local Roty = xmlNodeGetAttribute (v, "roty");
		   local Rotz = xmlNodeGetAttribute (v, "rotz");
		   createVehicle(tonumber(Model), tonumber(X), tonumber(Y), tonumber(Z), tonumber(Rotx), tonumber(Roty), tonumber(Rotz));
		end
	outputChatBox("All cars loaded!", root, 0, 255, 0, false);
	end
end);

 

this is too slow, use sqlite instead

Link to comment
  • Scripting Moderators
7 hours ago, Tekken said:

Not that slow, but yeah SQLite it's a lot better, I have this since I've started to do scripts so I just copy/paste it here :)

if he wants to save 5000+ vehicles, sqlite is the best solution to his question

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...