· 8 years ago · Aug 13, 2018, 05:44 PM
1local backupItemsTable = {
2{"M4"},
3{"CZ 550"},
4{"Winchester 1866"},
5{"SPAZ-12 Combat Shotgun"},
6{"Sawn-Off Shotgun"},
7{"AK-47"},
8{"Lee Enfield"},
9{"M1911"},
10{"M9 SD"},
11{"PDW"},
12{"MP5A5"},
13{"Desert Eagle"},
14{"Hunting Knife"},
15{"Hatchet"},
16{"Baseball Bat"},
17{"Shovel"},
18{"Golf Club"},
19{"Parachute"},
20{"FlashBang"},
21{"Grenade"},
22{"Binoculars"},
23{"M1911 Mag"},
24{"M9 SD Mag"},
25{"Desert Eagle Mag"},
26{"PDW Mag"},
27{"MP5A5 Mag"},
28{"AK Mag"},
29{"M4 Mag"},
30{"1866 Slug"},
31{"2Rnd. Slug"},
32{"SPAZ-12 Pellet"},
33{"CZ 550 Mag"},
34{"Lee Enfield Mag"},
35{"Water Bottle"},
36{"Pasta Can"},
37{"Beans Can"},
38{"Burger"},
39{"Pizza"},
40{"Soda Bottle"},
41{"Milk"},
42{"Cooked Meat"},
43{"Wood Pile"},
44{"Kora"},
45{"Bandage"},
46{"Roadflare"},
47{"Empty Gas Canister"},
48{"Full Gas Canister"},
49{"Medic Kit"},
50{"Heat Pack"},
51{"Painkiller"},
52{"Morphine"},
53{"Blood Bag"},
54{"Wire Fence"},
55{"Bear Trap"},
56{"Raw Meat"},
57{"Tire"},
58{"Engine"},
59{"Tank Parts"},
60{"Tent"},
61{"Camouflage Clothing"},
62{"Civilian Clothing"},
63{"Woman Clothing"},
64{"Survivor Clothing"},
65{"Ghillie Suit I"},
66{"Ghillie Suit II"},
67{"Ghillie Suit III"},
68{"Ghillie Suit IV"},
69{"Ghillie Suit V"},
70{"Ghillie Suit VI"},
71{"Ghillie Suit VII"},
72{"Ghillie Suit VIII"},
73{"Ghillie Suit IX"},
74{"Ghillie Suit X"},
75{"Lekarz"},
76{"Kombinezon X"},
77{"Empty Water Bottle"},
78{"Empty Soda Cans"},
79{"Scruffy Burgers"},
80{"Basic Pack [10]"}, -- 10
81{"Assault Pack (ACU) [12]"}, -- 12
82{"Small Backpack [16]"}, -- 16
83{"Medic Backpack [18]"}, -- 18
84{"Marines Backpack [24]"}, -- 24
85{"Alice Pack [28]"}, -- 28
86{"Vest Pack [32]"}, -- 32
87{"Medium Backpack [38]"}, -- 38
88{"Big Backpack [44]"}, -- 44
89{"Czech Backpack [58]"}, -- 58
90{"High Backpack [68]"}, -- 68
91{"Military Backpack [76]"}, -- 76
92{"East Backpack [86]"}, -- 86
93{"Coyote Backpack [96]"}, -- 96
94{"The-DayZ Backpack [126]"}, -- 126
95{"Night Vision Goggles"},
96{"Infrared Goggles"},
97{"Map"},
98{"Box of Matches"},
99{"Watch"},
100{"GPS"},
101{"Toolbox"},
102}
103
104local last_tent_id = 0;
105local backupdone = false;
106
107if fileExists("tools/backup.db") then
108 backupdone = true;
109else
110 backupdone = false;
111end
112
113local db = dbConnect("sqlite", "tools/backup.db");
114dbExec(db, "CREATE TABLE IF NOT EXISTS `tents` (model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
115
116function backup()
117 dbExec(db, "DELETE FROM `tents`");
118 local vc,tc = 0, 0;
119 for _,col in ipairs(getElementsByType("colshape")) do
120 if getElementData(col, "tent") then
121 local tent = getElementData(col, "parent");
122 if tent then
123 local x,y,z = getElementPosition(tent);
124 local rX,rY,rZ = getElementRotation(tent);
125 local items = {};
126 tc = tc+1;
127 for _,item in ipairs(backupItemsTable) do
128 local quantity = getElementData(col, item[1]) or 0;
129 if (quantity > 0) then
130 table.insert(items, {item[1], quantity});
131 end
132 end
133 dbExec(db, "INSERT INTO `tents` (model, x, y, z, rX, rY, rZ, slots, scale, items, id) VALUES(?,?,?,?,?,?,?,?,?,?,?)",
134 getElementModel(tent), x, y, z, rX, rY, rZ, getElementData(col, "MAX_Slots") or 100, getObjectScale(tent), toJSON(items), tc);
135 end
136 end
137 end
138 outputDebugString("Backup done ("..tc.." Tents) and ("..vc.." Vehicles)", 3);
139end
140
141function createDayzTent(model, x, y, z, rX, rY, rZ, slots, scale, items)
142 tent = createObject(model, x, y, z);
143 setObjectScale(tent, 1.3)
144 tentCol = createColSphere(x, y, z, 2.7);
145 setElementRotation(tent, rX, rY, rZ);
146 setObjectScale(tent, scale);
147 attachElements(tentCol, tent, 0, 0, 0)
148 setElementData(tentCol, "parent", tent)
149 setElementData(tent, "parent", tentCol)
150 setElementData(tentCol, "tent", true)
151 setElementData(tentCol, "vehicle", true)
152 setElementData(tentCol, "MAX_Slots", 500)
153 for _,v in ipairs(fromJSON(items)) do
154 setElementData(tentCol, v[1], v[2]);
155 end
156end
157
158function loadBackup()
159 local p2 = dbPoll(dbQuery(db, "SELECT * FROM `tents`"), -1);
160 if (#p2 > 0) then
161 for _,d in pairs(p2) do
162 createDayzTent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"]);
163 end
164 end
165end
166
167if not backupdone then
168 backupdone = true;
169else
170 loadBackup();
171end
172setTimer(backup, (10*10000), 0);
173
174addCommandHandler("dobackup", function(player)
175 if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
176 backup();
177 end
178end);