Jump to content

DayZ Vehicle save problem


[SG]Santeri

Recommended Posts

I want ''backupAllVehz'' and ''automat'' function to work automaticly with a timer every 5 sec.

I want ''loadd'' and ''loadAllVehs'' functions do when resource starts. Any help? This script saves and loads DayZ tents and vehicles. They work but they have a command on them, i want remove command and place timer and to loadd and loadAllVehs i want it to load the vehicles/tents on resource start. Thanks :)

Code (backupAllVehz function - vehicle save):

function backupAllVehz(thePlayer) 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Save")) then 
        if fileExists("vehicles.xml") then 
            fileDelete('vehicles.xml') 
        end 
        local vehFile = xmlCreateFile("vehicles.xml", "vehs") 
        if not vehFile then 
        outputChatBox("Saving of vehicles failed.", root, 255, 0, 0, 0) 
            return 
        end 
        local count = 0 
        local vehicles = getElementsByType("vehicle") 
        outputChatBox("Saving of vehicles was initiated!", root, 255, 155, 0) 
        for i,v in ipairs(vehicles) do 
            local currentVeh = xmlCreateChild (vehFile, "veh") 
            local vehicleModel = getElementModel(v) 
            local vehicleX, vehicleY, vehicleZ = getElementPosition(v) 
            local rotX, rotY, rotZ = getElementRotation(v) 
            xmlNodeSetAttribute (currentVeh, "model", vehicleModel) 
            xmlNodeSetAttribute (currentVeh, "x", vehicleX) 
            xmlNodeSetAttribute (currentVeh, "y", vehicleY) 
            xmlNodeSetAttribute (currentVeh, "z", vehicleZ) 
            xmlNodeSetAttribute (currentVeh, "rotx", rotX) 
            xmlNodeSetAttribute (currentVeh, "roty", rotY) 
            xmlNodeSetAttribute (currentVeh, "rotz", rotZ) 
        end 
        xmlSaveFile (vehFile)    
        xmlUnloadFile (vehFile)    
        outputChatBox("Vehicles saved! ("..#vehicles..")!", root, 255, 155, 0) 
    end 
end 
addCommandHandler("save", backupAllVehz) 

Code (loadAllVehs function - load vehicles):

function loadAllVehs(thePlayer) 
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Save")) then 
        local vehFile = xmlLoadFile ("vehicles.xml") 
        if (vehFile) then 
           local veh = xmlNodeGetChildren(vehFile) 
           outputChatBox("Loading of vehicles was initiated!", root, 0, 100, 255) 
           for i,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") 
           local veh = createVehicle(model, x, y, z) 
           vehCol = createColSphere(x, y, z, 2) 
           attachElements(vehCol, veh, 0, 0, 0) 
           setElementData(vehCol, "parent", veh) 
           setElementData(veh, "parent", vehCol) 
           setElementData(vehCol, "vehicle", true) 
           setElementData(vehCol, "MAX_Slots", 30) 
           local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) 
           setElementData(vehCol, "Tire_inVehicle", 4) 
           setElementData(vehCol, "Engine_inVehicle", 1) 
           setElementData(vehCol, "Parts_inVehicle", 3) 
           setElementData(vehCol, "spawn", { 
           model, 
           x, 
           y, 
           z 
           }) 
           setElementData(vehCol, "fuel", 80) 
        end 
        outputChatBox("Vehicles loaded! "..#veh.."!", root, 0, 100, 255) 
    end 
end 
end 
addCommandHandler("load", loadAllVehs) 

Code (automat function - tent save):

function automat(gracz) 
    if gracz and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(gracz)), aclGetGroup("Save")) then 
        outputChatBox("Saving of tents was initiated!",gracz,0,255,0,true) 
    else 
        return 
    end 
      namiot = xmlCreateFile("tents.xml","root") 
      id = 0 
      ilosc = 0 
      for i, col in ipairs(getElementsByType("colshape")) do 
        if col then 
            local tent = getElementData(col, "tent") 
            if tent then 
                local namiotek = getElementData(col, "parent") 
                local x, y, z = getElementPosition(namiotek) 
                local rx, ry, rz = getElementRotation(namiotek) 
                local namiote = xmlCreateChild (namiot,"Namiot") 
                local namiot = xmlCreateChild (namiote,"wsp") 
                local namioti = xmlCreateChild (namiote,"itemy") 
                xmlNodeSetValue (xmlCreateChild ( namiot, "PX"), tostring(x) ) 
                xmlNodeSetValue (xmlCreateChild ( namiot, "PY"), tostring(y) ) 
                xmlNodeSetValue (xmlCreateChild ( namiot, "PZ"), tostring(z) ) 
                xmlNodeSetValue (xmlCreateChild ( namiot, "RX"), tostring(rx) ) 
                xmlNodeSetValue (xmlCreateChild ( namiot, "RY"), tostring(ry) ) 
                xmlNodeSetValue (xmlCreateChild ( namiot, "RZ"), tostring(rz) ) 
                id = 0 
                for i, v in ipairs(tabelazapisu) do 
                    local item = getElementData(col, v[1]) 
                    if item then 
                        if item >= 1 then 
                        itemID = PobierzIDItemu(v[1]) 
                        xmlNodeSetValue (xmlCreateChild ( namioti, tostring(itemID)), tostring(item) ) 
                        end 
                    end 
                end 
            end 
        end 
    end 
xmlSaveFile(namiot) 
xmlUnloadFile(namiot) 
if gracz then 
    outputChatBox("Tents saved!",gracz,0,255,0,true) 
end 
end 
addCommandHandler("save",automat) 

Code (loadd function - tent load):

function loadd(player,cmd,nazwa) 
    if player and isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Save")) then 
        local xml = xmlLoadFile ( "tents.xml" ) 
        pobierzinfo = xmlNodeGetChildren ( xml ) 
        for i,nam in pairs(pobierzinfo ) do 
            wsp = xmlFindChild(nam,"wsp",0) 
            item = xmlFindChild(nam,"itemy",0) 
            px = xmlFindChild(wsp,"PX",0) 
            py = xmlFindChild(wsp,"PY",0) 
            pz = xmlFindChild(wsp,"PZ",0) 
            rx = xmlFindChild(wsp,"RX",0) 
            ry = xmlFindChild(wsp,"RY",0) 
            rz = xmlFindChild(wsp,"RZ",0) 
            local pxx = xmlNodeGetValue ( px ) 
            local pyy = xmlNodeGetValue ( py ) 
            local pzz = xmlNodeGetValue ( pz ) 
            local rxx = xmlNodeGetValue ( rx ) 
            local ryy = xmlNodeGetValue ( ry ) 
            local rzz = xmlNodeGetValue ( rz ) 
            ilosc = ilosc + 1 
            tent = createObject(3243, pxx, pyy, pzz, rxx, ryy, rzz) 
            setObjectScale(tent, 1) 
            tentCol = createColSphere(pxx, pyy, pzz,  3) 
            attachElements(tentCol, tent, 0, 0, 0) 
            setElementData(tentCol, "parent", tent) 
            setElementData(tent, "parent", tentCol) 
            setElementData(tentCol, "tent", true) 
            setElementData(tentCol, "vehicle", true) 
            setElementData(tentCol, "MAX_Slots", 150) 
            local itemX = xmlNodeGetChildren(item) 
            for i,it in ipairs(itemX) do 
                local wartosc = xmlNodeGetValue (it) 
                local nazwa = xmlNodeGetName(it) 
                item = PobierzItemID(nazwa) 
                setElementData(tentCol, tostring(item), tonumber(wartosc)) 
            end  
        end 
        end 
    else 
        local xml = xmlLoadFile ( "tents.xml" ) 
        pobierzinfo = xmlNodeGetChildren ( xml ) 
        for i,nam in pairs(pobierzinfo ) do 
            wsp = xmlFindChild(nam,"wsp",0) 
            item = xmlFindChild(nam,"itemy",0) 
            px = xmlFindChild(wsp,"PX",0) 
            py = xmlFindChild(wsp,"PY",0) 
            pz = xmlFindChild(wsp,"PZ",0) 
            rx = xmlFindChild(wsp,"RX",0) 
            ry = xmlFindChild(wsp,"RY",0) 
            rz = xmlFindChild(wsp,"RZ",0) 
            local pxx = xmlNodeGetValue ( px ) 
            local pyy = xmlNodeGetValue ( py ) 
            local pzz = xmlNodeGetValue ( pz ) 
            local rxx = xmlNodeGetValue ( rx ) 
            local ryy = xmlNodeGetValue ( ry ) 
            local rzz = xmlNodeGetValue ( rz ) 
            ilosc = ilosc + 1 
            tent = createObject(3243, pxx, pyy, pzz, rxx, ryy, rzz) 
            outputChatBox("Loaded in the tent!",player) 
            setObjectScale(tent, 1) 
            tentCol = createColSphere(pxx, pyy, pzz,  3) 
            attachElements(tentCol, tent, 0, 0, 0) 
            setElementData(tentCol, "parent", tent) 
            setElementData(tent, "parent", tentCol) 
            setElementData(tentCol, "tent", true) 
            setElementData(tentCol, "vehicle", true) 
            setElementData(tentCol, "MAX_Slots", 150) 
            local itemX = xmlNodeGetChildren(item) 
            for i,it in ipairs(itemX) do 
                local wartosc = xmlNodeGetValue (it) 
                local nazwa = xmlNodeGetName(it) 
                item = PobierzItemID(nazwa) 
                setElementData(tentCol, tostring(item), tonumber(wartosc)) 
            end  
        end 
    end 
end 
addCommandHandler("load",loadd) 

Link to comment

Just add these lines at the end of your code ( can be any lua file of the same resource but make sure its server sided).

  
local dc = { } 
local t = getElementsByType ("player") 
  
for i=1, #t do 
dc[getPlayerSerial(t[i])] = true 
  
loadAllVehs (t[i]) 
loadd ( t[i]) 
end 
  
addEventHandler("onPlayerJoin",root, 
function () 
if dc[getPlayerSerial(source)] then return end 
dc[getPlayerSerial(source)] = true 
loadAllVehs(source) 
loadd (source) 
end) 
  

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...