Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- MTA:DayZ Backup System v1.7
- --]]
- local dbType = "-"; --Here set your database type, "MySQL" or "SQLite" <!>
- local dbName = "-"; --Your database name <!>
- local dbHost = "-"; --Your hostname/IP <!>
- local dbUser = "-"; --Username for database <!>
- local dbPass = "-"; --Password for database <!>
- local dbPort = -; --This is an port exemple CHANGE IT <!>
- local last_veh_id = 0; --Don't edit here <!>
- local last_tent_id = 0; --Don't edit here <!>
- local itemsTable = { -- If your server have different items be sure you imported your item table here!
- {"M4"}, {"AK-47"}, {"Lee Enfield"}, {"CZ 550"},
- {"MP5A5"}, {"PDW"}, {"SPAZ-12 Combat Shotgun"},
- {"Sawn-Off Shotgun"}, {"Winchester 1866"},
- {"M9 SD"}, {"M911"}, {"Desert Eagle"},
- {"Binoculars"}, {"Tear Gas"}, {"Grenade"},
- {"Satchel"}, {"Baseball Bat"}, {"Shovel"},
- {"Golf Club"}, {"Hunting Knife"}, {"Hatchet"},
- {"M4 Mag"}, {"AK Mag"}, {"Lee Enfield Mag"},
- {"CZ 550 Mag"}, {"MP5A5 Mag"}, {"PDW Mag"},
- {"SPAZ-12 Pellet"}, {"2Rnd. Slug"}, {"1866 Slug"},
- {"M9 SD Mag"}, {"M911 Mag"}, {"Desert Eagle Mag"},
- {"Water Bottle"}, {"Pasta Can"}, {"Beans Can"},
- {"Burger"}, {"Pizza"},{"Soda Bottle"}, {"Milk"},
- {"Empty Water Bottle"}, {"Empty Soda Cans"},
- {"Scruffy Burgers"}, {"Raw Meat"}, {"Cooked Meat"},
- {"Coyote Backpack"}, {"Czech Backpack"},
- {"Assault Pack (ACU)"}, {"Alice Pack"},
- {"Box of Matches"}, {"Infrared Goggles"},
- {"Night Vision Goggles"}, {"GPS"}, {"Map"},
- {"Toolbox"}, {"Watch"}, {"Radio Device"},
- {"Bandage"}, {"Morphine"}, {"Medic Kit"},
- {"Heat Pack"}, {"Blood Bag"}, {"Painkiller"},
- {"Tire"}, {"Engine"}, {"Tank Parts"},
- {"Camouflage Clothing"}, {"Ghillie Suit"},
- {"Civilian Clothing"}, {"Survivor Clothing"},
- {"Wood Pile"}, {"Empty Gas Canister"},
- {"Full Gas Canister"}, {"Roadflare"},
- {"Wire Fence"}, {"Tent"}
- };
- function noteAdmins(msg)
- for _,v in ipairs(getElementsByType("player")) do
- if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(v)), aclGetGroup("Admin"))) then
- outputChatBox("#FF0000[Backup]: #FFFFFF"..tostring(msg), v, 255, 255, 255, true);
- end
- end
- end
- if (dbType == "MySQL") then
- db = dbConnect("mysql", "dbname="..dbName..";host="..dbHost..";port="..dbPort, dbUser, dbPass, "share=1");
- noteAdmins("Database connected to MySQL!");
- elseif (dbType == "SQLite") then
- db = dbConnect("sqlite", "database.db");
- noteAdmins("Database connected to SQLite!");
- else
- noteAdmins("Error: `dbType` wrong attribute!");
- return;
- end
- dbExec(db, "CREATE TABLE IF NOT EXISTS vehicles(model Int(10), x VARCHAR(60), y VARCHAR(60), z VARCHAR(60), rX VARCHAR(60), rY VARCHAR(60), rZ VARCHAR(60), slots Int(5), fuel VARCHAR(30), engines Int(5), moving Int(5), parts Int(5), items VARCHAR(10000), id Int(5))");
- dbExec(db, "CREATE TABLE IF NOT EXISTS tents(model Int(10), x VARCHAR(60), y VARCHAR(60), z VARCHAR(60), rX VARCHAR(60), rY VARCHAR(60), rZ VARCHAR(60), slots Int(5), scale Int(5), items VARCHAR(10000), id Int(5))");
- function backup_vehs()
- dbExec(db, "DELETE FROM vehicles");
- local vc = 0;
- for _,veh in ipairs(getElementsByType("vehicle")) do
- if (not getElementData(veh, "helicrash") and not getElementData(veh, "isExploded")) then
- local col = getElementData(veh, "parent");
- if (col and getElementType(col) == "colshape") then
- local x, y, z = getElementPosition(veh);
- local rX, rY, rZ = getElementRotation(veh);
- local items = {};
- vc = vc+1;
- for _,item in ipairs(itemsTable) do
- local quantity = getElementData(col, item[1]) or 0;
- if (quantity > 0) then
- table.insert(items, {item[1], quantity});
- end
- end
- dbExec(db, "INSERT INTO vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
- getElementModel(veh), x, y, z, rX, rY, rZ, getElementData(col, "MAX_Slots") or 20, getElementData(col, "fuel") or 0, getElementData(col, "Engine_inVehicle") or 0,
- getElementData(col, "Tire_inVehicle") or 0, getElementData(col, "Parts_inVehicle") or 0, toJSON(items), vc);
- end
- end
- end
- noteAdmins("Vehicles saved ["..vc.."]");
- end
- function backup_tents()
- dbExec(db, "DELETE FROM tents");
- local tc = 0;
- for _,col in ipairs(getElementsByType("colshape")) do
- if (getElementData(col, "tent")) then
- local tent = getElementData(col, "parent");
- local x, y, z = getElementPosition(tent);
- local rX, rY, rZ = getElementRotation(tent);
- local items = {};
- tc = tc+1;
- for _,item in ipairs(itemsTable) do
- local quantity = getElementData(col, item[1]) or 0;
- if (quantity > 0) then
- table.insert(items, {item[1], quantity});
- end
- end
- dbExec(db, "INSERT INTO tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
- getElementModel(tent), x, y, z, rX, rY, rZ, getElementData(col, "MAX_Slots") or 100, getObjectScale(tent), toJSON(items), tc);
- end
- end
- noteAdmins("Tents saved ["..tc.."]");
- end
- function create_veh(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, id)
- local veh = createVehicle(model, x, y, z);
- local vehCol = createColSphere(x+5, y, z, 4);
- setElementRotation(veh, rX, rY, rZ);
- attachElements(vehCol, veh, 0, 0, 0);
- setElementData(vehCol, "parent", veh);
- setElementData(veh, "parent", vehCol);
- setElementData(vehCol, "vehicle", true);
- setElementData(vehCol, "MAX_Slots", tonumber(slots));
- setElementData(vehCol, "Tire_inVehicle", tonumber(moving));
- setElementData(vehCol, "Engine_inVehicle", tonumber(engines));
- setElementData(vehCol, "Parts_inVehicle", tonumber(parts));
- setElementData(vehCol, "spawn", {model, x, y, z});
- setElementData(vehCol, "fuel", tonumber(fuel));
- for _,v in ipairs(fromJSON(items)) do
- setElementData(vehCol, v[1], v[2]);
- end
- end
- function create_tent(model, x, y, z, rX, rY, rZ, slots, scale, items, id)
- local tent = createObject(model, x, y, z);
- local tentCol = createColSphere(x, y, z, 3);
- setElementRotation(tent, rX, rY, rZ);
- setObjectScale(tent, scale);
- attachElements(tentCol, tent, 0, 0, 0);
- setElementData(tentCol, "parent", tent);
- setElementData(tent, "parent", tentCol);
- setElementData(tentCol, "tent", true);
- setElementData(tentCol, "MAX_Slots", slots);
- for _,v in ipairs(fromJSON(items)) do
- setElementData(tentCol, v[1], v[2]);
- end
- end
- function load_vehs(q)
- if (q) then
- local p = dbPoll(q, 0);
- if (#p > 0) then
- for _,d in pairs(p) do
- last_veh_id = d["id"];
- create_veh(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["fuel"], d["engines"], d["moving"], d["parts"], d["items"], d["id"]);
- end
- end
- end
- noteAdmins("Vehicles loaded ["..tonumber(last_veh_id).."]");
- end
- function load_tents(q)
- if (q) then
- local p = dbPoll(q, 0);
- if (#p > 0) then
- for _,d in pairs(p) do
- last_tent_id = d["id"];
- create_tent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"], d["id"]);
- end
- end
- end
- noteAdmins("Tents loaded ["..tonumber(last_tent_id).."]");
- end
- function dVehs()
- for _,veh in ipairs(getElementsByType("vehicle")) do
- local parent = getElementData(veh, "parent");
- if (parent) then
- destroyElement(parent);
- destroyElement(veh);
- end
- end
- noteAdmins("Vehs deleted!");
- end
- function dTents()
- for _,tent in ipairs(getElementsByType("colshape")) do
- local parent = getElementData(tent, "parent");
- if (parent) then
- destroyElement(parent);
- destroyElement(tent);
- end
- end
- noteAdmins("Tents deleted!");
- end
- addEventHandler("onPlayerCommand", getRootElement(), function(cmd)
- if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin"))) then
- if (cmd == "loadtents") then
- dbQuery(load_tents, {}, db, "SELECT * FROM `tents`");
- elseif (cmd == "loadvehs") then
- dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`");
- elseif (cmd == "vehbk") then
- backup_vehs();
- elseif (cmd == "tentbk") then
- backup_tents();
- elseif (cmd == "dvehs") then
- dVehs();
- elseif (cmd == "dtents") then
- dTents();
- elseif (cmd == "togbk") then
- if (isTimer(vehbkTimer) and isTimer(tentbkTimer)) then
- killTimer(vehbkTimer);
- killTimer(tentbkTimer);
- noteAdmins(getPlayerName(source).."#FFFFFF stop la sauvegarde automatique du serveur!");
- else
- vehbkTimer = setTimer(backup_vehs, 30*60000, 0);
- tentbkTimer = setTimer(backup_tents, 30*60000, 0);
- noteAdmins(getPlayerName(source).."#FFFFFF active la sauvegarde automatique du serveur!");
- end
- end
- end
- end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement