Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Copyright (c) 2016 Grosu `mihayy5` Mihaita
- MTA:DayZ Backup System v1.6
- --]]
- local dbType = "SQLite"; --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 = 0; --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!
- {"Wood Pile"},
- {"Bandage"},
- {"Water Bottle"},
- {"Pasta Can"},
- {"Beans Can"},
- {"Burger"},
- {"Box of Matches"},
- {"M911 Mag"},
- {"M9 SD Mag"},
- {"Desert Eagle Mag"},
- {"M911"},
- {"M9 SD"},
- {"Winchester 1866"},
- {"PDW"},
- {"Hunting Knife"},
- {"Morphine"},
- {"Hatchet"},
- {"Pizza"},
- {"Soda Bottle"},
- {"Empty Gas Canister"},
- {"Full Gas Canister"},
- {"Army Backpack"},
- {"Legendary Backpack"},
- {"Mountaion Backpack"},
- {"Roadflare"},
- {"Milk"},
- {"PDW Mag"},
- {"MP5A5 Mag"},
- {"AK Mag"},
- {"M4 Mag"},
- {"Tear Gas"},
- {"Grenade"},
- {"Desert Eagle"},
- {"Sawn-Off Shotgun"},
- {"SPAZ-12 Combat Shotgun"},
- {"MP5A5"},
- {"Watch"},
- {"Medic Kit"},
- {"Heat Pack"},
- {"Lee Enfield"},
- --{"TEC-9"},
- {"AK-47"},
- {"M136 Rocket Launcher"},
- {"Blood Bag"},
- {"GPS"},
- {"Map"},
- {"Toolbox"},
- {"Wire Fence"},
- {"Tire"},
- {"Engine"},
- {"Tank Parts"},
- {"M136 Rocket"},
- {"CZ 550 Mag"},
- {"Lee Enfield Mag"},
- {"M4"},
- {"CZ 550"},
- --{"Heat-Seeking RPG"},
- {"Satchel"},
- {"Infrared Goggles"},
- {"Night Vision Goggles"},
- {"Tent"},
- {"Raw Meat"},
- {"Cooked Meat"},
- {"Camouflage Clothing"},
- {"Terrorist Clothing"},
- {"Policeman Clothing"},
- {"Bat Clothing"},
- {"Ghillie Suit"},
- {"Desert Ghillie Suit"},
- {"Civilian Clothing"},
- {"Survivor Clothing"},
- {"Painkiller"},
- {"Binoculars"},
- {"Empty Water Bottle"},
- {"Empty Soda Cans"},
- {"Scruffy Burgers"},
- {"1866 Slug"},
- {"2Rnd. Slug"},
- {"SPAZ-12 Pellet"},
- {"Assault Pack (ACU)"},
- {"Alice Pack"},
- {"Radio Device"},
- {"Coyote Backpack"},
- {"Sniper Backpack"},
- {"Ghillie Backpack"},
- {"Czech Backpack"},
- {"Shop Tokens"},
- {"Baseball Bat"},
- {"Shovel"},
- {"Golf Club"}
- };
- function noteAdmins(msg)
- for _,v in ipairs(getElementsByType("player")) do
- if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(v)), aclGetGroup("Owner"))) 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");
- dbExec(db, "CREATE TABLE IF NOT EXISTS vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, id)");
- dbExec(db, "CREATE TABLE IF NOT EXISTS tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
- noteAdmins("Database connected to MySQL!");
- elseif (dbType == "SQLite") then
- db = dbConnect("sqlite", "database.db");
- dbExec(db, "CREATE TABLE IF NOT EXISTS vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, id)");
- dbExec(db, "CREATE TABLE IF NOT EXISTS tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
- noteAdmins("Database connected to SQLite!");
- else return noteAdmins("Error: `dbType` wrong attribute!"); end
- 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, "vehicle", 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(veh);
- destroyElement(parent);
- end
- end
- noteAdmins("Vehs deleted!");
- end
- function dTents()
- for _,tent in ipairs(getElementsByType("colshape")) do
- local parent = getElementData(tent, "parent");
- if (parent) then
- destroyElement(tent);
- destroyElement(parent);
- end
- end
- noteAdmins("Tents deleted!");
- end
- addEventHandler("onPlayerCommand", getRootElement(), function(cmd)
- if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Owner"))) then
- if (cmd == "loadtents") then
- dbQuery(load_tents, {}, db, "SELECT * FROM `tents`");
- elseif (cmd == "loadvehicles") then
- dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`");
- elseif (cmd == "loadbackup") then
- dbQuery(load_tents, {}, db, "SELECT * FROM `tents`");
- dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`");
- elseif (cmd == "vehiclebackup") then
- backup_vehs();
- elseif (cmd == "backup") then
- backup_vehs();
- backup_tents();
- elseif (cmd == "tentbackup") then
- backup_tents();
- elseif (cmd == "destroyvehicles") then
- dVehs();
- elseif (cmd == "destroytents") then
- dTents();
- elseif (cmd == "togglebackup") then
- if (isTimer(vehbkTimer) and isTimer(tentbkTimer)) then
- killTimer(vehbkTimer);
- killTimer(tentbkTimer);
- noteAdmins(getPlayerName(source).."#FFFFFF stopped automatic backup!");
- else
- vehbkTimer = setTimer(backup_vehs, 30*60000, 0);
- tentbkTimer = setTimer(backup_tents, 30*60000, 0);
- noteAdmins(getPlayerName(source).."#FFFFFF started automatic backup!");
- end
- end
- end
- end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement