Jump to content

DayZ Automatic Backup


JanKy

Recommended Posts

Hello guys.

I own a DayZ server and i have a backup system for tents and vehicles and it is only manual and i want it fully automatic like, every 10 minutes.
By the way, big shoutout to the creator of the script, great guy.

Here are the scripts :

needToSave = {
  {"MAX_Slots"},
  {"Tire_inVehicle"},
  {"Engine_inVehicle"},
  {"Parts_inVehicle"},
  {"Tire_inVehicle_HP"},
  {"Engine_inVehicle_HP"},
  {"Parts_inVehicle_HP"},
  {"armorPointsMax"},
  {"armorPoints"},
  {"fuel"},
  {"maxfuel"},
  {"needengine"},
  {"needtires"},
  {"needparts"},
}

function SaveVehicles(player)
  if isElement(player) then
	if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  return
	end
  end
  fileDelete("XVehicles.xml")
  xml = xmlCreateFile("XVehicles.xml","config")
  xmlSaveFile(xml)
  count = 0
  for _,vehCol in pairs(getElementsByType("colshape")) do
	if getElementData(vehCol,"vehicle") and not getElementData(vehCol,"tent") then
	  count = count + 1
	  if getElementData(vehCol,"parent") and isElement(getElementData(vehCol,"parent")) then
		veh = getElementData(vehCol,"parent")
		slots = getElementData(vehCol,"MAX_Slots")
		health = getElementHealth(veh)
		x,y,z = getElementPosition(veh)
		rx,ry,rz = getElementRotation(veh)
		VehInfos = xmlCreateChild(xml,"Veh")
		xmlNodeSetAttribute(VehInfos,"Name",getVehicleName(veh))
		xmlNodeSetAttribute(VehInfos,"ID",getElementModel(veh))
		xmlNodeSetAttribute(VehInfos,"Health",math.floor(health))
		xmlNodeSetAttribute(VehInfos,"X",x)
		xmlNodeSetAttribute(VehInfos,"Y",y)
		xmlNodeSetAttribute(VehInfos,"Z",z)
		xmlNodeSetAttribute(VehInfos,"RX",rx)
		xmlNodeSetAttribute(VehInfos,"RY",ry)
		xmlNodeSetAttribute(VehInfos,"RZ",rz)
		VehItens = xmlCreateChild(VehInfos,"Itens")
		for _,item in pairs(needToSave)do
		  if(tonumber(getElementData(vehCol,item[1])) and getElementData(vehCol,item[1]) >= 1) then
			Item2 = xmlCreateChild(VehItens,"Item")
			xmlNodeSetAttribute(Item2,"Item",item[1])
			xmlNodeSetAttribute(Item2,"Quant",getElementData(vehCol,item[1]) or 0)
		  end
		end
		for _,item in pairs(needToSave)do
		  Item2 = xmlCreateChild(VehItens,"Item")
		  xmlNodeSetAttribute(Item2,"Item",item[1])
		  xmlNodeSetAttribute(Item2,"Quant",getElementData(vehCol,item[1]) or 0)
		end
	  end
	end
  end
  xmlSaveFile(xml)
  xmlUnloadFile(xml)
  if isElement(player) then
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  outputChatBox("Vehicles Saved ["..count.."] #000000- By Victormgons",player,255,0,0,true)
	end
  end
end
addEventHandler("onResourceStop",getResourceRootElement(),SaveVehicles)
setTimer(SaveVehicles,600000,0)

function LoadVehicles(player)
  if isElement(player) then
	if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  return
	end
  end
  xml = xmlLoadFile("XVehicles.xml")
  for i,node in pairs(xmlNodeGetChildren(xml)) do
	x = tonumber(xmlNodeGetAttribute(node,"X"))
	y = tonumber(xmlNodeGetAttribute(node,"Y"))
	z = tonumber(xmlNodeGetAttribute(node,"Z"))
	rx = tonumber(xmlNodeGetAttribute(node,"RX"))
	ry = tonumber(xmlNodeGetAttribute(node,"RY"))
	rz = tonumber(xmlNodeGetAttribute(node,"RZ"))
	veh = createVehicle(tonumber(xmlNodeGetAttribute(node,"ID")),x,y,z,rx,ry,rz)
	vehCol = createColSphere(x,y,z,4)
	setElementData(vehCol,"spawn",{tonumber(xmlNodeGetAttribute(node,"ID")),x,y,z})
	attachElements(vehCol,veh,0,0,0)
	setElementData(vehCol,"parent",veh)
	setElementData(veh,"parent",vehCol)
	setElementData(vehCol,"vehicle",true)
	setElementHealth(veh,tonumber(math.floor(xmlNodeGetAttribute(node,"Health"))))
	for i,Item in pairs(xmlNodeGetChildren(xmlFindChild(node,"Itens",0))) do
	  setElementData(vehCol,xmlNodeGetAttribute(Item,"Item"),tonumber(xmlNodeGetAttribute(Item,"Quant")))
	end
  end
  xmlUnloadFile(xml)
  if isElement(player) then
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  outputChatBox("All Vehicles has been loaded! #000000- By Victormgons",player,255,0,0,true)
	end
  end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),LoadVehicles)
addCommandHandler("savevehs",SaveVehicles)
addCommandHandler("loadvehs",LoadVehicles)
function SaveTents(player)
  if isElement(player) then
	if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  return
	end
  end
  fileDelete("XTents.xml")
  xml = xmlCreateFile("XTents.xml","config")
  xmlSaveFile(xml)
  count = 0
  for _,tentCol in pairs(getElementsByType("colshape")) do
	if getElementData(tentCol,"tent") then
	  count = count + 1
	  Tent = getElementData(tentCol,"parent")
	  x,y,z = getElementPosition(Tent)
	  rx,ry,rz = getElementRotation(Tent)
	  TentInfos = xmlCreateChild(xml,"Tent")
	  xmlNodeSetAttribute(TentInfos,"ID",getElementModel(Tent))
	  xmlNodeSetAttribute(TentInfos,"Scale",getObjectScale(Tent))
	  xmlNodeSetAttribute(TentInfos,"Slots",getElementData(tentCol,"MAX_Slots"))
	  xmlNodeSetAttribute(TentInfos,"X",x)
	  xmlNodeSetAttribute(TentInfos,"Y",y)
	  xmlNodeSetAttribute(TentInfos,"Z",z)
	  xmlNodeSetAttribute(TentInfos,"RX",rx)
	  xmlNodeSetAttribute(TentInfos,"RY",ry)
	  xmlNodeSetAttribute(TentInfos,"RZ",rz)
	  xmlNodeSetAttribute(TentInfos,"Visible",tostring(getElementData(tentCol,"visible") or false))
	  TentItens = xmlCreateChild(TentInfos,"Itens")
	  for _,item in pairs(needToSave) do
		if getElementData(tentCol,item[1]) and getElementData(tentCol,item[1]) >= 1 then
		  Item2 = xmlCreateChild(TentItens,"Item")
		  xmlNodeSetAttribute(Item2,"Item",item[1])
		  xmlNodeSetAttribute(Item2,"Quant",getElementData(tentCol,item[1]))
		end
	  end
	end
  end
  xmlSaveFile(xml)
  xmlUnloadFile(xml)
  if isElement(player) then
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  outputChatBox("Tents Saved ["..count.."] #000000- By Victormgons",player,255,0,0,true)
	end
  end
end
addEventHandler("onResourceStop",getResourceRootElement(),SaveTents)
setTimer(SaveTents,600000,0)

function LoadTents(player)
  if isElement(player) then
	if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  return
	end
  end
  xml = xmlLoadFile("XTents.xml")
  for i,node in pairs(xmlNodeGetChildren(xml)) do
	ID = tonumber(xmlNodeGetAttribute(node,"ID"))
	Scale = tonumber(xmlNodeGetAttribute(node,"Scale"))
	Slots = tonumber(xmlNodeGetAttribute(node,"Slots"))
	x = tonumber(xmlNodeGetAttribute(node,"X"))
	y = tonumber(xmlNodeGetAttribute(node,"Y"))
	z = tonumber(xmlNodeGetAttribute(node,"Z"))
	rx = tonumber(xmlNodeGetAttribute(node,"RX"))
	ry = tonumber(xmlNodeGetAttribute(node,"RY"))
	rz = tonumber(xmlNodeGetAttribute(node,"RZ"))
	visible = xmlNodeGetAttribute(node,"Visible")
	tent = createObject(ID,x,y,z,rx,ry,rz)
	setObjectScale(tent,Scale)
	tentCol = createColSphere(x,y,z,4)
	attachElements(tentCol,tent,0,0,0)
	setElementData(tentCol,"parent",tent)
	setElementData(tent,"parent",tentCol)
	setElementData(tentCol,"tent",true)
	setElementData(tentCol,"vehicle",true)
	if visible == "true" then vis = true else vis = false end
	setElementData(tentCol,"visible",vis)
	setElementData(tentCol,"MAX_Slots",Slots)
	for i,Item in pairs(xmlNodeGetChildren(xmlFindChild(node,"Itens",0))) do
	  setElementData(tentCol,xmlNodeGetAttribute(Item,"Item"),tonumber(xmlNodeGetAttribute(Item,"Quant")))
	end
  end
  xmlUnloadFile(xml)
  if isElement(player) then
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup("Admin"))then
	  outputChatBox("All tents has been saved! #000000- By Victormgons",player,255,0,0,true)
	end
  end
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),LoadTents)

addCommandHandler("savetents",SaveTents)
addCommandHandler("loadtents",LoadTents)

Thanks in advance.

  • Like 1
Link to comment

Can you not use setTimer?  It might work as you could time each function or maybe even the whole script to save....  I have played a couple servers with auto save and believe they use a similar method.  (You may want to freeze players while there is a save as it can cause lags)

  • Like 1
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...