Jump to content

[REL] DayZ Backup system


-Rex-

Recommended Posts

Posted

Hello, everyone, I 've decided to release my system kept shops and vehicles for your DayZ , this works through a SQLite database .

How do I use it?

Well simply to start the resource this restores all shops and cars that have been saved , but to save the stores and vehicles just enough to stop the resource and this began to save All shops and vehicles on your server ( Destroy each store and auto it is storing ) in the database and this will only seconds of network trouble ..

In short , When you start the appeal restores what has been saved and stopping the resource keeps shops and vehicles.

What I can edit ?

Sure, but do not remove the credits .

Need ACL permissions ?

Not necessarily, only need ACL permissions if the database is in an external folder .

You must add the goal this, there are some functions using OOP .

true

The code here

--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
--Proyect: N/A.                                                                                                                              // 
--Developers: -Rex-                                                                                                                      // 
--Testers: "N/A".                                                                                                                                //                                                                                                                      / 
--Information: system kept shops and vehicles for your DayZ Through a SQLite database. 
--Version: 1.0 BETA                                                                          // 
--Rights : You have the right to edit 100 % code , but you have no right to sell or remove the credits of the same , without permission of the author.  // 
--///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  
local inventoryItems = { 
    --Paste your items table of inventory.lua 
    {"AK-74", 3}, 
    {"AKM", 3}, 
    {"AKS-74 Kobra", 3}, 
    {"PKP", 3 }, 
    {"PKM", 3 }, 
    {"L85A2 Holo", 3}, 
    {"L85A2 SUSAT", 3}, 
    {"M16A2", 3}, 
    {"M16A2 M203", 3}, 
    {"M16A4 ACOG", 3}, 
    {"M4A1", 3}, 
    {"M4A1 CCO", 3}, 
    {"M4A1 CCO SD", 3}, 
    {"M4A1 Holo", 3}, 
    {"M4A3 CCO", 3}, 
    {"SA-58 CCO", 3}, 
    {"SA-58P", 3}, 
    {"SA-58V", 3}, 
    {"SA-58V ACOG", 3}, 
    {"M240", 3}, 
    {"MAX_Slots"}, 
} 
  
--The Directory of your database ( Use SQLitebrowser to create one) 
local db = dbConnect( "sqlite", ":sqlitedb/dbData.db" ) 
local cache = {} 
local objeto = {} 
local vehis = {} 
local actual = 0 
local totaltents = 0 
local totalveh = 0 
function onStart( ) 
    local qh = db:query( "CREATE TABLE IF NOT EXISTS tents_backups ( tent_n INTEGER, dato STRING, cantidad INTEGER, posx FLOAT, posy FLOAT, posz FLOAT ) ") 
    local qh2 = db:query( "CREATE TABLE IF NOT EXISTS vehiculos_backups ( modelo INTEGER, maxslots INTEGER, fuel INTEGER, maxfuel INTEGER, ruedas INTEGER, motor INTEGER, deposito INTEGER, posx FLOAT, posy FLOAT, posz FLOAT, rotx FLOAT, roty FLOAT, rotz FLOAT ) ") 
    dbFree( qh ) dbFree( qh2 ) 
    outputServerLog( "Being restored all server data") 
    outputChatBox("Attention! Being restored all server data , please no disconnect !",getRootElement(  )) 
  
    local qee = db:query("SELECT tent_n, posx, posy, posz FROM tents_backups") 
    for ide, valor in pairs( dbPoll( qee, -1 ) ) do 
        if actual ~= valor["tent_n"] then 
            actual = valor["tent_n"] 
            totaltents = totaltents +1 
            local x, y, z = valor["posx"], valor["posy"], valor["posz"]; 
            objeto.tent = createObject(3243, x,y,z) 
            setObjectScale(objeto.tent,1)  
            objeto.tentCol = createColSphere(x,y,z,10) 
            attachElements ( objeto.tentCol, objeto.tent, 0, 0, 0 ) 
            setElementData(objeto.tentCol,"parent",objeto.tent) 
            setElementData(objeto.tent,"parent",objeto.tentCol) 
            setElementData(objeto.tentCol,"tent",true) 
            setElementData(objeto.tentCol,"vehicle",true) 
            setElementData(objeto.tentCol, "MAX_Slots", 100)  
            local qeee = db:query("SELECT dato, cantidad FROM tents_backups WHERE tent_n=?", valor["tent_n"] ) 
            for _, v in pairs( dbPoll( qeee, -1 ) ) do 
                setElementData(objeto.tentCol, v["dato"], tonumber( v["cantidad"] ) ) 
            end 
        end 
    end 
    local qhj = db:query( "SELECT * FROM vehiculos_backups") 
    local vehiclesTable = dbPoll( qhj, -1 ) 
    for t, columna in ipairs( vehiclesTable ) do 
        totalveh = totalveh + 1 
        local modelo, maxsl, fuel, maxfue = columna["modelo"],columna["maxslots"],columna["fuel"],columna["maxfuel"]; 
        local rueda, motor = columna["ruedas"], columna["motor"] 
        local deposito, vehx = columna["deposito"],columna["posx"] 
        local vehy, vehz, vehrx = columna["posy"],columna["posz"],columna["rotx"]; 
        local vehry, vehrz = columna["roty"],columna["rotz"]; 
        vehis.vehic = createVehicle( modelo, vehx, vehy, vehz ) 
        setElementRotation( vehis.vehic, vehrx, vehry, vehrz ) 
        vehis.colS = createColSphere( vehx, vehy, vehz, 4 ) 
        attachElements ( vehis.colS, vehis.vehic, 0, 0, 0 ) 
        setElementData(vehis.colS,"parent",vehis.vehic) 
        setElementData(vehis.vehic,"parent",vehis.colS) 
        setElementData(vehis.colS,"vehicle",true) 
        setElementData(vehis.colS,"MAX_Slots",maxsl) 
        setElementData(vehis.colS,"maxfuel",maxfue) 
        setElementData(vehis.colS,"Tire_inVehicle",rueda) 
        setElementData(vehis.colS,"Engine_inVehicle",motor) 
        setElementData(vehis.colS,"Parts_inVehicle",deposito) 
        setElementData(vehis.colS,"fuel",fuel) 
    end 
    outputChatBox("Se han restaurado "..totaltents.." Tiendas y "..tostring( totalveh ).." Vehiculos!") 
end 
addEventHandler("onResourceStart", getResourceRootElement( getThisResource()), onStart) 
  
local tentNum = 0 
function startBackup(  ) 
    local qhr = db:query( "DROP TABLE tents_backups" ) 
    dbFree( qhr ) 
    local qhrE = db:query( "DROP TABLE vehiculos_backups" ) 
    dbFree( qhrE ) 
    local qh3 = db:query( "CREATE TABLE IF NOT EXISTS tents_backups ( tent_n INTEGER, dato STRING, cantidad INTEGER, posx FLOAT, posy FLOAT, posz FLOAT ) ") 
    dbFree( qh3 ) 
    local qh2 = db:query( "CREATE TABLE IF NOT EXISTS vehiculos_backups ( modelo INTEGER, maxslots INTEGER, fuel INTEGER, maxfuel INTEGER, ruedas INTEGER, motor INTEGER, deposito INTEGER, bateria INTEGER, rotor INTEGER, posx FLOAT, posy FLOAT, posz FLOAT, rotx FLOAT, roty FLOAT, rotz FLOAT ) ") 
    dbFree( qh2 ) 
    outputChatBox("Attention! Being restored all server data , please no disconnect !",getRootElement(  )) 
    --Guardado de tents En la base de datos 
    for i, col in ipairs( getElementsByType("colshape") ) do 
        if col:getData("tent") == true then 
            local x,y,z = getElementPosition( col ) 
            local ta = db:query("SELECT * FROM tents_backups WHERE posx=? AND posy=? AND posz=?", x,y,z ) 
            if #dbPoll( ta, -1 ) == 0 then 
                tentNum = tentNum + 1 
                db:exec("INSERT INTO tents_backups ( tent_n, dato, cantidad, posx, posy, posz ) VALUES ( ?, ?, ?, ?, ?, ? )", tentNum, "",1, x,y,z ) 
            end 
            for _, datot in ipairs( inventoryItems ) do 
                local qh = db:query("SELECT * FROM tents_backups WHERE posx=? AND posy=? AND posz=?", x,y,z ) 
                for _, columna in ipairs( dbPoll( qh, - 1 )) do 
                    local ntent = columna["tent_n"] 
                    if cache["tentguardada_"..tostring(ntent)] then 
                        if cache["tentguardada_"..tostring(ntent)] == true then  
                            break  
                        end 
                    end 
                    local itemD = datot[1]; 
                    local dat = col:getData( itemD ) or 0 
                    if dat and dat >= 1 then 
                        local q = db:query("SELECT * FROM tents_backups WHERE dato=? AND tent_n=?", itemD, tentNum) 
                        local h = #dbPoll( q, -1 ) 
                        if h == 0 then 
                            db:exec("INSERT INTO tents_backups ( tent_n, dato, cantidad, posx, posy, posz ) VALUES ( ?, ?, ?, ?, ?,? )", ntent, itemD, dat, 0,0,0 ) 
                        end 
                    end 
                end 
            end 
            destroyElement(getElementData(col,"parent")) 
            destroyElement(col) 
            cache["tentguardada_"..tostring(tentNum)] = true  
        end 
    end 
    --Vehiculos 
    for _, vehiculo in ipairs( getElementsByType("vehicle") ) do 
        local veh = getElementData( vehiculo,"parent" ) 
        local modelID = getElementModel( vehiculo ) 
        local vehx, vehy, vehz = getElementPosition( vehiculo) 
        local rx, ry, rz = getElementRotation( vehiculo ) 
        if getElementData( veh, "vehicle" ) then         
            totalveh = totalveh + 1      
            local maxSl = getElementData( veh, "MAX_Slots" ) 
            local maxFuel = getElementData( veh, "maxfuel" )  
            local fuel = getElementData( veh, "fuel" ) 
            local ruedas = getElementData( veh, "Tire_inVehicle" )  
            local motor = getElementData( veh, "Engine_inVehicle" )  
            local deposito = getElementData( veh, "Parts_inVehicle" )  
            db:exec( "INSERT INTO vehiculos_backups ( modelo, maxslots, fuel, maxfuel, ruedas, motor, deposito, posx, posy, posz, rotx, roty, rotz ) VALUES ( ?, ?, ?,?,?, ?, ?, ?,?, ?, ?, ?, ? )", modelID, maxSl, fuel, maxFuel, ruedas, motor,  deposito, vehx, vehy, vehz, rx, ry, rz) 
            destroyElement( getElementData( veh,"parent" ) ) 
            destroyElement( veh ) 
        end 
    end 
    outputChatBox("Backup Saved!",getRootElement(  )) 
end 
addEventHandler("onResourceStop", getResourceRootElement( getThisResource()), startBackup) 
  

Any bug or error will not hesitate to let me know.

Sorry my bad english

Leal es quien te ama y respeta tus sentimientos

Paid Scripter, Contact me: https://www.facebook.com/rexscripting/  Estoy retirado.

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