Jump to content

MTA:DayZ 0.7 Source Code!


Tekken

Recommended Posts

  • 2 weeks later...

UPDATE

Changes (26.11.2016):

  • Possible warning when "kilLDayZPlayer" event is triggered.
  • SKS-45 not appearing on the ground after drop.

If you find any bugs make sure to report 'em.

backup.db and teams.db are compatible and no need to delete them.

Link to comment

One more Update:

Fixed a LOT of things and it's a MUST HAVE update.

Removed Arma 2 Like GPS, I will soon release it as a addon.

Databases are compatible.

If you are facing wierd issues with the Sniper Scope make sure "HUD Match ASpect Ratio" it's disabled in your video settings.

Spoiler

mucCV0NENrjFCgiFD8jdf8vB2-AOUGUFn8AtCRSU

 

Edited by Tekken
Link to comment
  • 2 weeks later...

I try to change the respawn time of the vehicle, but this error.

[19:20:44] WARNING: [dayz]\dayz\vehicles.lua:534: Bad argument @ 'getElementData
' [Expected element at argument 1, got boolean]

The settimers I just change the multipliers the same for all. Even the 180000, I changed to the same value as the multiplication of the last settimer.

Spoiler

addEventHandler("onVehicleExplode", root,  function()
	for _,v in pairs(getVehicleOccupants(source)) do
		triggerEvent("kilLDayZPlayer", v);
	end
	local x1,y1,z1 = getElementPosition(source);
	local col = getElementData(source, "parent");
	local id,x,y,z = unpack(getElementData(col, "spawn"));
	setElementData(col, "deadVehicle", true);
	setElementData(source, "isExploded", true);
	if (getElementData(source, "dayzvehicle") == 1) then
		setTimer(respawnDayZVehicle, 30000, 1, id, x, y, z, source, col);
	else
		setTimer(function(col, source)
			if isElement(col) then destroyElement(col); end
			if isElement(source) then destroyElement(source); end
		end, (5*1000), 1, col, source);
	end
	createExplosion((x1+4), (y1+1), z1, 4);
	createExplosion((x1+2), (y1-4), z1, 4);
	createExplosion((x1-1), (y1+5), z1, 4);
	createExplosion((x1-4), y1, (z1-2), 4);
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 453) then
			local col = getElementData(v, "parent");
			if not (getElementData(col, "deadVehicle") or false) then
				if isElementInWater(v) then
					local id,x,y,z = unpack(getElementData(col, "spawn"));
					if (getElementData(v, "dayzvehicle") == 1) then
						setTimer(respawnDayZVehicle, (5*1000), 1, id, x, y, z, v, col);
					else
						setTimer(function(col, v)
							if col then destroyElement(col); end
							if v then destroyElement(v); end
						end, (5*1000), 1, col, v);
					end
				end
			end
		end
	end
end, (30*1000), 0);

 

Am I doing something wrong?

Link to comment

Hi! Can you fix that bug when you kill someone with gun who has it equipped and you take it from him but if you want to use this weapon you must first drop it cause game still think it is equipped? And also can you create a armybox for your gamemode? Cause you have a lot of new weapons and i think you should add doubleclick to your gamemode or at least make it extra content to download.  I hope you understood my broken english.

Link to comment
On 12/18/2016 at 0:46 AM, Lowcafraguw(2.0) said:

Hi! Can you fix that bug when you kill someone with gun who has it equipped and you take it from him but if you want to use this weapon you must first drop it cause game still think it is equipped? And also can you create a armybox for your gamemode? Cause you have a lot of new weapons and i think you should add doubleclick to your gamemode or at least make it extra content to download.  I hope you understood my broken english.

About the bug I will check, and for the double click as I already said no, I don't like it that way that's your business. And you don't have to apologize for your "Bad English", everyone should thank that you tried.

Link to comment
  • 3 weeks later...

I have not changed anything on DAYZ. Only what is in the hidden content.

On 10/12/2016 at 4:04 AM, Tekken said:

May I see your vehicles.lua ?

On 07/12/2016 at 7:36 PM, HueKING said:

I try to change the respawn time of the vehicle, but this error.


[19:20:44] WARNING: [dayz]\dayz\vehicles.lua:534: Bad argument @ 'getElementData
' [Expected element at argument 1, got boolean]

The settimers I just change the multipliers the same for all. Even the 180000, I changed to the same value as the multiplication of the last settimer.

  Hide contents


addEventHandler("onVehicleExplode", root,  function()
	for _,v in pairs(getVehicleOccupants(source)) do
		triggerEvent("kilLDayZPlayer", v);
	end
	local x1,y1,z1 = getElementPosition(source);
	local col = getElementData(source, "parent");
	local id,x,y,z = unpack(getElementData(col, "spawn"));
	setElementData(col, "deadVehicle", true);
	setElementData(source, "isExploded", true);
	if (getElementData(source, "dayzvehicle") == 1) then
		setTimer(respawnDayZVehicle, 30000, 1, id, x, y, z, source, col);
	else
		setTimer(function(col, source)
			if isElement(col) then destroyElement(col); end
			if isElement(source) then destroyElement(source); end
		end, (5*1000), 1, col, source);
	end
	createExplosion((x1+4), (y1+1), z1, 4);
	createExplosion((x1+2), (y1-4), z1, 4);
	createExplosion((x1-1), (y1+5), z1, 4);
	createExplosion((x1-4), y1, (z1-2), 4);
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 453) then
			local col = getElementData(v, "parent");
			if not (getElementData(col, "deadVehicle") or false) then
				if isElementInWater(v) then
					local id,x,y,z = unpack(getElementData(col, "spawn"));
					if (getElementData(v, "dayzvehicle") == 1) then
						setTimer(respawnDayZVehicle, (5*1000), 1, id, x, y, z, v, col);
					else
						setTimer(function(col, v)
							if col then destroyElement(col); end
							if v then destroyElement(v); end
						end, (5*1000), 1, col, v);
					end
				end
			end
		end
	end
end, (30*1000), 0);

 

Am I doing something wrong?

 

Link to comment

I need your entire vehicles.lua to identify the error by it's line in the code.

I think I may know the error and if I'm not mistaken I have fixed it in one of the updates, just download the vehicles.lua from the GitHub and tell be if you get the same error.

Link to comment
13 hours ago, Tekken said:

I need your entire vehicles.lua to identify the error by it's line in the code.

I think I may know the error and if I'm not mistaken I have fixed it in one of the updates, just download the vehicles.lua from the GitHub and tell be if you get the same error.

Yes, I downloaded it yesterday and tried again.
I also tried to remove the last two zeros.

Spoiler

addEventHandler("onVehicleExplode", root,  function()
    for _,v in pairs(getVehicleOccupants(source)) do
        triggerEvent("kilLDayZPlayer", v);
    end
    local x1,y1,z1 = getElementPosition(source);
    local col = getElementData(source, "parent");
    local id,x,y,z = unpack(getElementData(col, "spawn"));
    setElementData(col, "deadVehicle", true);
    setElementData(source, "isExploded", true);
    if (getElementData(source, "dayzvehicle") == 1) then
        setTimer(respawnDayZVehicle, 18000, 1, id, x, y, z, source, col);
    else
        setTimer(function(col, source)
            if isElement(col) then destroyElement(col); end
            if isElement(source) then destroyElement(source); end
        end, (5*600), 1, col, source);
    end
    createExplosion((x1+4), (y1+1), z1, 4);
    createExplosion((x1+2), (y1-4), z1, 4);
    createExplosion((x1-1), (y1+5), z1, 4);
    createExplosion((x1-4), y1, (z1-2), 4);
end);

setTimer(function()
    for _,v in ipairs(getElementsByType("vehicle")) do
        if (getElementModel(v) ~= 453) then
            local col = getElementData(v, "parent");
            if not (getElementData(col, "deadVehicle") or false) then
                if isElementInWater(v) then
                    local id,x,y,z = unpack(getElementData(col, "spawn"));
                    if (getElementData(v, "dayzvehicle") == 1) then
                        setTimer(respawnDayZVehicle, (5*600), 1, id, x, y, z, v, col);
                    else
                        setTimer(function(col, v)
                            if col then destroyElement(col); end
                            if v then destroyElement(v); end
                        end, (5*600), 1, col, v);
                    end
                end
            end
        end
    end
end, (30*600), 0);

 

Leaving from 30 min to 18 seconds and the 5 min to 3 seconds.

And it still gives the same error on the console. I believe if I leave your default (1800000, 5 * 60000, 30 * 60000), after that time I will have the same error on the console. I'll try, wait the 30 minutes to see if it really will.

 

One tip, what do you think uses a multi-weapon ammunition?
Ex:
M4A1 Holo, M4 Mag,
M4A1 CCO, M4 Mag.
Would it be okay to do that?

Edited by HueKING
Link to comment

Yes you can use multi-weapon ammo.

But as I already said 2 times give me the god damn vehicles.lua the entire file so I can identify the error by the line, because it has nothing to do with the setTimer.

Edited by Tekken
Link to comment
On 10/01/2017 at 4:49 AM, Tekken said:

I need your entire vehicles.lua to identify the error by it's line in the code.

I think I may know the error and if I'm not mistaken I have fixed it in one of the updates, just download the vehicles.lua from the GitHub and tell be if you get the same error.

Okay, it's there. But as I said I did not change anything besides the settimer's

Spoiler

local vehicleSpawns = {
	--[[Maverick]]
	{487, -1185.9775390625,26.4111328125,14.1484375},
	{487, -1724.5830078125,2559.3544921875,104.09127807617},
	{487, 615.744140625,850.1572265625,-43.009014129639},
	{487, 232.5283203125,1950.3583984375,17.640625},
	{487, -1050.5859375,1968.033203125,120.66523742676},
	{487, 2821.03515625,2809.6689453125,10.8203125},
	{487, 1949.9912109375,-2631.44140625,13.546875},
	{487, -756.53979492188,-2137.5471191406,26.463499069214},
	--[[Patriot]]
	{470, -1473.5791015625,320.2294921875,7.1875},
	{470, -1373.998046875,460.62109375,7.1875},
	{470, 419.150390625,2186.087890625,39.499450683594},
	{470, 2821.1796875,793.4658203125,10.8984375},
	--[[Bobcat]]
	{422, -2479.6240234375,2223.6669921875,4.84375},
	{422, -92.9951171875,2823.0908203125,76.721649169922},
	{422, -2448.99609375,-1335.8662109375,310.97662353516},
	{422, -173.2470703125,-2635.5341796875,26.608192443848},
	{422, 2108.447265625,-1600.916015625,13.552597045898},
	{422, 2452.7392578125,1607.9833984375,10.8203125},
	{422, -1800.8984375,-1950.9736328125,93.561332702637},
	--[[Sanchez]]
	{468, -812.470703125,-2629.912109375,90.105056762695},
	{468, -1729.8525390625,-1940.3154296875,99.840209960938},
	{468, -2130.90234375,178.4375,35.257678985596},
	{468, -2656.7333984375,1352.4873046875,7.0596733093262},
	{468, -1598.302734375,2694.947265625,55.07092666626},
	{468, -809.96484375,2430.037109375,156.97012329102},
	{468, 2920.38671875,2486.0087890625,10.8203125},
	{468, 505.732421875,-291.8681640625,20.00952911377},
	{468, -428.8828125,-694.8310546875,19.14847946167},
	{468, 1190.41015625,-2109.0341796875,64.738548278809},
	{468, 1658.9716796875,-1069.0224609375,23.906229019165},
	--[[Barracks]]
	{433, 86.486328125,1950.9013671875,17.846803665161},
	{433, 440.185546875,1464.173828125,6.3338670730591},
	--[[Coach]]
	{437, -1971.4619140625,97.4658203125,27.6875},
	{437, 1735.8720703125,1429.0693359375,10.797702789307},
	{437, 2797.1318359375,-1868.8359375,9.8603811264038},
	{437, 1941.900390625,1975.1904296875,7.59375},
	--[[Reefer]]
	{453, 2463.3984375,-2719.638671875,-0.55000001192093},
	{453, -1577.4873046875,182.353515625,-0.53995263576508},
	{453, -806.80859375,2233.7001953125,40.049976348877},
	{453, -127.4453125,-779.6923828125,-0.55000001192093},
	--[[Bike]]
	{509, 194.685546875,-120.2333984375,1.5497757196426},
	{509, 173.0146484375,-95.0634765625,1.5516006946564},
	{509, 2369.9599609375,29.712890625,28.0416431427},
	{509, 710.87109375,-566.7548828125,16.3359375},
	{509, 1109.6025390625,-1667.6689453125,13.615442276001},
	{509, 2014.6689453125,-1113.4013671875,26.203125},
	{509, 2447.41015625,-1967.1845703125,13.546875},
	{509, 2633.7236328125,1835.291015625,11.0234375},
	{509, 1489.3974609375,2681.54296875,10.8203125},
	{509, -2428.5654296875,2280.875,4.984375},
	{509, -2501.0869140625,2224.880859375,4.9861993789673},
	{509, -2142.8515625,-2457.84765625,30.625},
	{509, -2456.078125,-141.115234375,26.112222671509},
	{509, -1881.4453125,954.3837890625,35.171875},
	--[[Police Maverick]]
	{497, -1495.888671875,-2691.40234375,57.325229644775},
	{497, -2688.42578125,1471.634765625,7.1875},
	{497, -1534.28125,2842.9482421875,97.463409423828},
	{497, 2221.8583984375,-1344.396484375,23.984273910522},
};

local hospitalPacks = {
	{-2670.87890625,636.8984375,14.453125},
	{-2637.0556640625,635.03125,14.453125},
	{-1515.669921875,2519.166015625,56.0703125},
	{-1513.888671875,2519.5908203125,56.064819335938},
	{-1528.8955078125,2516.724609375,55.986171722412},
	{2022.1650390625,-1402.6806640625,17.18045425415},
	{2042.7001953125,-1409.4775390625,17.1640625},
	{-316.5478515625,1051.6494140625,20.340259552002},
	{-337.9541015625,1049.490234375,19.739168167114},
	{-331.5849609375,1046.037109375,26.012474060059},
	{-307.0419921875,1045.27734375,26.012474060059},
	{1171.490234375,-1310.560546875,13.986573219299},
	{1171.609375,-1306.556640625,13.996350288391},
	{1158.5048828125,-1326.333984375,31.503561019897},
	{1159.80078125,-1323.9013671875,31.498970031738},
	{1238.7119140625,328.2431640625,19.7555103302},
	{1229.365234375,311.1435546875,24.7578125},
	{-2204.07421875,-2309.58203125,31.375},
	{1615.939453125,1818.0537109375,10.8203125},
	{1601.9443359375,1816.736328125,10.8203125},
	{1590.0166015625,1792.0234375,30.46875},
	{1607.3232421875,1776.7412109375,37.3125},
	{2107.7626953125,926.16015625,10.8203125},
	{2116.12890625,925.7705078125,10.9609375},
	{2122.1865234375,925.3193359375,10.8203125},
};
local patrolPoints = {
	{-1603.2197265625,-2712.736328125,48.9453125},
	{2465.748046875,-2215.55859375,13.546875},
	{2473.439453125,-2215.56640625,13.546875},
	{2480.0732421875,-2216.140625,13.546875},
	{2487.24609375,-2215.5966796875,13.546875},
	{2494.1005859375,-2215.5859375,13.546875},
	{-1686.6728515625,408.9970703125,7.3984375},
	{-1682.34375,412.9384765625,7.3984375},
	{-1680.0263671875,402.3642578125,7.3984375},
	{-1675.84375,406.4677734375,7.3984375},
	{-1670.5615234375,411.8359375,7.3984375},
	{-1666.2392578125,416.2509765625,7.3984375},
	{-1672.7939453125,422.81640625,7.3984375},
	{-1677.20703125,418.46484375,7.3984375},
	{-2410.7021484375,969.9091796875,45.4609375},
	{-2410.744140625,975.220703125,45.4609375},
	{-2410.837890625,980.5302734375,45.4609375},
	{-1329.3046875,2668.5126953125,50.46875},
	{-1328.7314453125,2673.90625,50.0625},
	{-1327.0185546875,2679.3876953125,50.46875},
	{-1327.3798828125,2684.62890625,50.0625},
	{1940.7099609375,-1778.5244140625,13.390598297119},
	{1940.6552734375,-1774.908203125,13.390598297119},
	{1940.630859375,-1771.728515625,13.390598297119},
	{1940.7080078125,-1767.3837890625,13.390598297119},
	{-1477.921875,1868.138671875,32.639846801758},
	{-1466.1552734375,1869.0048828125,32.6328125},
	{-1464.5224609375,1861.3828125,32.639846801758},
	{-1477.4599609375,1860.5205078125,32.6328125},
	{-735.9208984375,2744.0087890625,47.2265625},
	{-739.0439453125,2744.2421875,47.165451049805},
	{377.6953125,2601.1083984375,16.484375},
	{624.5263671875,1676.25390625,6.9921875},
	{620.2958984375,1681.2431640625,6.9921875},
	{616.248046875,1686.4169921875,7.1875},
	{612.783203125,1691.1650390625,7.1875},
	{609.2060546875,1696.201171875,7.1875},
	{605.8505859375,1700.978515625,7.1875},
	{602.27734375,1706.3603515625,7.1875},
	{2141.037109375,2742.734375,10.960174560547},
	{2142.3115234375,2752.6982421875,10.96019744873},
	{2147.9521484375,2752.3203125,10.8203125},
	{2152.60546875,2751.953125,10.8203125},
	{2152.984375,2743.85546875,10.8203125},
	{2147.75,2743.7392578125,10.8203125},
	{-97.6298828125,-1175.0283203125,2.4990689754486},
	{-90.74609375,-1177.853515625,2.2021217346191},
	{-84.75390625,-1163.853515625,2.3359375},
	{-91.5771484375,-1160.5732421875,2.4453125},
	{-1606.525390625,-2717.2138671875,48.9453125},
	{-1609.7109375,-2721.544921875,48.9453125},
	{-1599.83203125,-2708.302734375,48.9453125},
	{-2246.314453125,-2558.8212890625,32.0703125},
	{-2241.3125,-2561.3662109375,32.0703125},
	{-1132.2880859375,-135.0986328125,14.14396572113},
	{-1153.529296875,-156.373046875,14.1484375},
	{-1142.826171875,-145.67578125,14.14396572113},
	{655.611328125,-557.9912109375,16.501491546631},
	{655.6572265625,-572.1728515625,16.501491546631},
	{1601.791015625,2203.90625,11.060997009277},
	{1596.806640625,2203.4345703125,10.8203125},
	{1590.197265625,2203.4853515625,10.8203125},
	{1589.4775390625,2195.43359375,10.8203125},
	{1596.125,2194.294921875,10.8203125},
	{1601.6591796875,2194.3369140625,10.8203125},
	{2206.8466796875,2470.47265625,10.8203125},
	{2206.94140625,2474.75,10.8203125},
	{2206.9267578125,2478.86328125,10.8203125},
	{2198.06640625,2480.6953125,10.8203125},
	{2197.541015625,2475.791015625,10.995170593262},
	{2197.609375,2471.9169921875,10.995170593262},
	{2120.8251953125,915.4833984375,10.8203125},
	{2115.1181640625,915.44140625,10.8203125},
	{2109.076171875,915.4228515625,10.8203125},
	{2109.22265625,924.8779296875,10.9609375},
	{2114.9404296875,924.8857421875,10.9609375},
	{2119.5126953125,925.2861328125,10.9609375},
	{2645.7197265625,1112.7802734375,10.8203125},
	{2639.984375,1112.56640625,10.8203125},
	{2634.828125,1112.3466796875,10.9609375},
	{2634.1826171875,1101.9482421875,10.8203125},
	{2636.7509765625,1101.6748046875,10.8203125},
	{2643.5126953125,1101.81640625,10.8203125},
	{2209.576171875,2469.8251953125,10.8203125},
	{2208.8310546875,2475.09375,10.8203125},
	{1005.078125,-901.7490234375,42.216625213623},
	{993.025390625,-902.474609375,42.222496032715},
};

local heliCrashSites = {
	{-1360.0478515625,-1070.7314453125,160.4069519043},
	{-421.4619140625,-1284.4345703125,33.740924835205},
	{-2357.654296875,-1634.3623046875,483.703125},
	{979.0849609375,160.59375,28.935249328613},
	{-2057.2294921875,2781.73828125,163.12780761719},
	{826.90234375,2803.6259765625,74.863929748535},
	{2577.7060546875,-650.541015625,136.37449645996},
};

local lootItems = {
	["helicrashsides"] = {
		{"Night Vision Goggles",368,1,90,10},
		{"Box of Matches",328,0.4,90,2},
		{"M1911",346,1,90,10},
		{"M9 SD",347,1,90,7},
		{"Winchester 1866",349,1,90,6},
		{"PDW",352,1,90,5.5},
		{"Hunting Knife",335,1,90,4},
		{"Hatchet",339,1,90,3},
		{"Pizza",1582,1,0,2},
		{"Soda Bottle",2647,1,0,2},
		{"Empty Gas Canister",1650,1,0,2},
		{"Roadflare",324,1,90,2},
		{"Milk",2856,1,0,1},
		{"Painkiller",2709,0.5,0,4},
		{"Empty Soda Cans",2673,0.5,0,2},
		{"Scruffy Burgers",2675,0.5,0,3},
		{"Grenade",342,1,0,4},
		{"Parachute",342,1,0,80},
		{"Sawn-Off Shotgun",350,1,90,5},
		{"SPAZ-12 Combat Shotgun",351,1,90,4},
		{"MP5A5",353,1,90,6},
		{"Watch",2710,1,0,4},
		{"Heat Pack",1576,1,0,3},
		{"Wire Fence",933,0.25,0,1},
		{"Lee Enfield",357,1,90,6},
		{"Alice Pack",3026,1,0,4},
		{"Night Vision Goggles",368,1,90,1.5},
		{"Tire",1073,1,0,2},
		{"Morphine",1579,1,0,4},
		{"Camouflage Clothing",1577,1,0,4.5},
		{"Civilian Clothing",1577,1,0,3},
		{"AK-47",355,1,90,7},
		{"GPS",2976,0.15,0,3},
		{"Map",1277,0.8,90,7},
		{"Toolbox",2969,0.5,0,1},
		{"Engine",929,0.3,0,2},
		{"Tent",1279,1,0,4.5},
		{"Ghillie Suit",1577,1,0,0.5},
		{"M4",356,1,90,1},
		{"CZ 550",358,1,90,1.5},
		{"Infrared Goggles",369,1,90,3},
		{"Assault Pack (ACU)",3026,0.5,0,5},
		{"Coyote Backpack",3026,1.3,0,2},
	},
	["hospital"] = {
		{"Medic Kit",2891,0.7,0},
		{"Heat Pack",1576,1,0},
		{"Bandage",1578,0.5,0},
		{"Blood Bag",1580,1,0},
		{"Morphine",1579,1,0},
		{"Blood Bag",1580,1,0},
		{"Medic Kit",2891,0.7,0},
		{"Blood Bag",1580,1,0},
		{"Painkiller",1580,1,0},
	},
};

local backupItemsTable = {
	{"Bandage"},
	{"Painkiller"},
	{"Wood Pile"},
	{"Water Bottle"},
	{"Pasta Can"},
	{"Beans Can"},
	{"Burger"},
	{"Box of Matches"},
	{"PDW"},
	{"Hunting Knife"},
	{"Hatchet"},
	{"Pizza"},
	{"Morphine"},
	{"Soda Bottle"},
	{"Empty Gas Canister"},
	{"Full Gas Canister"},
	{"Roadflare"},
	{"Milk"},
	{"PDW Mag"},
	{"MP5A5 Mag"},
	{"Tear Gas"},
	{"Grenade"},
	{"M1911"},
	{"M1911 Mag"},
	{"M9 SD"},
	{"M9 SD Mag"},
	{"Desert Eagle"},
	{"Desert Eagle Mag"},
	{"MP5A5"},
	{"Watch"},
	{"Medic Kit"},
	{"Heat Pack"},
	{"Blood Bag"},
	{"GPS"},
	{"Map"},
	{"Toolbox"},
	{"Wire Fence"},
	{"Tire"},
	{"Engine"},
	{"Satchel"},
	{"Infrared Goggles"},
	{"Night Vision Goggles"},
	{"Tent"},
	{"Raw Meat"},
	{"Cooked Meat"},
	{"Camouflage Clothing"},
	{"Ghillie Suit"},
	{"Civilian Clothing"},
	{"Survivor Clothing"},
	{"Binoculars"},
	{"Empty Water Bottle"},
	{"Empty Soda Cans"},
	{"Scruffy Burgers"},
	{"Radio Device"},
	{"Baseball Bat"},
	{"Shovel"},
	{"Tank Parts"},
	{"Golf Club"},
	{"Radio Device"},
	{"Parachute"},
	{"M4A1 Holo"},
	{"MK 48 Mod 0"},
	{"MG36"},
	{"PKP"},
	{"AK-107"},
	{"AKS Gold"},
	{"SA-58V ACOG"},
	{"Winchester 1866"},
	{"SPAZ-12 Combat Shotgun"},
	{"Sawn-Off Shotgun"},
	{"AKS-74U"},
	{"SKS-45"},
	{"DMR"},
	{"KVSK"},
	{"AS50"},
	{"CZ550"},
	{"Mosin 9130"},
	{"M24"},
	{"M107"},
	{"SVD Dragunov Camo"},
	{"AKS-74U Mag"},
	{"1866 Slug"},
	{"2Rnd. Slug"},
	{"SPAZ-12 Pellet"},
	{"M4A1 Holo Mag"},
	{"MK 48 Mod 0 Mag"},
	{"MG36 Mag"},
	{"PKP Mag"},
	{"AK-107 Mag"},
	{"AKS Gold Mag"},
	{"SA-58V ACOG Mag"},
	{"DMR Mag"},
	{"AS50 Mag"},
	{"CZ550 Mag"},
	{"Mosin 9130 Mag"},
	{"M24 Mag"},
	{"M107 Mag"},
	{"SVD Dragunov Camo Mag"},
	{"KVSK Mag"},
	{"SKS-45 Mag"}
};

local vehicleAddonsInfo = {
	{422, 4, 1, 1, 25},
	{470, 4, 1, 1, 46},
	{468, 2, 1, 1, 10},
	{433, 6, 1, 1, 70},
	{437, 6, 1, 1, 60},
	{509, 0, 0, 0, 0},
	{487, 0, 1, 1, 20},
	{497, 0, 1, 1, 20},
	{453, 0, 1, 1, 35},
};

local vehicleFuelInfo = {
	{422, 0.25},
	{470, 0.1},
	{468, 0.1},
	{433, 0.5},
	{437, 0.5},
	{509, 0},
	{487, 0.25},
	{497, 0.25},
	{453, 0.1},
};

local vehicleFuelTable = {
	{422, 80},
	{470, 100},
	{468, 30},
	{433, 140},
	{437, 140},
	{509, 0},
	{487, 60},
	{497, 60},
	{453, 60},
};

local hospitalCol = {};
local dayzVehicles = {};
local repairTimer = {};
local last_veh_id = 0;
local last_tent_id = 0;
local backupdone = false;

addEvent("respawnVehiclesInWater", true);
addEvent("repairVehicle", true);
addEvent("respawnDayZVehicle", true);

if fileExists("tools/backup.db") then
	backupdone = true;
else
	backupdone = false;
end

local db = dbConnect("sqlite", "tools/backup.db");
dbExec(db, "CREATE TABLE IF NOT EXISTS `vehicles` (model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, health, dayz, sx, sy, sz, id)");
dbExec(db, "CREATE TABLE IF NOT EXISTS `tents` (model, x, y, z, rX, rY, rZ, slots, scale, items, id)");

function getVehicleAddonInfos(id)
	for _,v in ipairs(vehicleAddonsInfo) do
		if (v[1] == id) then return v[2], v[3], v[4], v[5]; end
	end
end

function createHeliCrashSite()
	if isElement(cargoCol) then
		destroyElement(getElementData(cargoCol, "parent"));
		destroyElement(cargoCol);
	end
	local nr = math.random(7);
	local x,y,z = heliCrashSites[nr][1], heliCrashSites[nr][2], heliCrashSites[nr][3];
	local cargobob = createVehicle(548, x, y, z);
	setElementHealth(cargobob, 0);
	setElementFrozen(cargobob, true);
	local cargoCol = createColSphere(x, y, z, 3);
	setElementData(cargoCol, "parent", cargobob);
	setElementData(cargoCol, "helicrash", true);
	setElementData(cargoCol, "MAX_Slots", 0);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5]*3.5, math.random(2));
		setElementData(cargoCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(cargoCol, ammoData, math.random(2));
		end
	end
	setTimer(createHeliCrashSite, 3600000, 1);
end

function updateHospitals()
	for i,_ in pairs(hospitalCol) do
		for _,v in ipairs(lootItems["hospital"]) do
			setElementData(hospitalCol[i], v[1], math.random(5));
		end
	end
	setTimer(updateHospitals, 3600000, 1);
end

function createHospitalPacks()
	local number1 = 0;
	for i,v in ipairs(hospitalPacks) do
		number1 = number1+1;
		local x,y,z = v[1], v[2], v[3];
		local object = createObject(1558, x, y, z, nil, nil, nil);
		hospitalCol[i] = createColSphere(x, y, z, 2);
		setElementData(hospitalCol[i], "parent", object);
		setElementData(hospitalCol[i], "hospitalbox", true);
		setElementData(hospitalCol[i], "MAX_Slots", 20);
	end
	updateHospitals();
end

function spawnDayZVehicles()
	for _,v in ipairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	for _,v in ipairs(vehicleSpawns) do
		local x,y,z = v[2], v[3], v[4];
		local veh = createVehicle(v[1], x, y, z);
		local vehCol = createColSphere(x, y, z, 2.5);
		attachElements(vehCol, veh);
		setElementData(vehCol, "parent", veh);
		setElementData(veh, "parent", vehCol);
		setElementData(vehCol, "vehicle", true);
		setElementData(veh, "dayzvehicle", 1);
		local tires,engine,parts,slots = getVehicleAddonInfos(v[1]);
		setElementData(vehCol, "MAX_Slots", tonumber(slots));
		setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
		setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
		setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
		setElementData(vehCol, "spawn", {v[1], x, y, z});
		setElementData(vehCol, "fuel", math.random(5, 20));
		for _,v in ipairs(lootItems["helicrashsides"]) do
			local value =  math.percentChance(v[5], math.random(2));
			setElementData(vehCol, v[1], value);
			local ammoData,_ = getWeaponAmmoType(v[1], true);
			if (ammoData and value > 0) then
				setElementData(vehCol, ammoData, math.random(2));
			end
		end
	end
	backup();
end

addEventHandler("onVehicleExplode", root,  function()
	for _,v in pairs(getVehicleOccupants(source)) do
		triggerEvent("kilLDayZPlayer", v);
	end
	local x1,y1,z1 = getElementPosition(source);
	local col = getElementData(source, "parent");
	local id,x,y,z = unpack(getElementData(col, "spawn"));
	setElementData(col, "deadVehicle", true);
	setElementData(source, "isExploded", true);
	if (getElementData(source, "dayzvehicle") == 1) then
		setTimer(respawnDayZVehicle, 18000, 1, id, x, y, z, source, col);
	else
		setTimer(function(col, source)
			if isElement(col) then destroyElement(col); end
			if isElement(source) then destroyElement(source); end
		end, (5*600), 1, col, source);
	end
	createExplosion((x1+4), (y1+1), z1, 4);
	createExplosion((x1+2), (y1-4), z1, 4);
	createExplosion((x1-1), (y1+5), z1, 4);
	createExplosion((x1-4), y1, (z1-2), 4);
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 453) then
			local col = getElementData(v, "parent");
			if not (getElementData(col, "deadVehicle") or false) then
				if isElementInWater(v) then
					local id,x,y,z = unpack(getElementData(col, "spawn"));
					if (getElementData(v, "dayzvehicle") == 1) then
						setTimer(respawnDayZVehicle, (5*600), 1, id, x, y, z, v, col);
					else
						setTimer(function(col, v)
							if col then destroyElement(col); end
							if v then destroyElement(v); end
						end, (5*600), 1, col, v);
					end
				end
			end
		end
	end
end, (30*600), 0);

function respawnDayZVehicle(id, x, y, z, veh, col)
	if veh then destroyElement(veh); end
	if col then destroyElement(col); end
	local veh = createVehicle(id, x, y, (tonumber(z)+1));
	local vehCol = createColSphere(x, y, z, 4);
	attachElements(vehCol, veh);
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(vehCol, "vehicle", true);
	setElementData(veh, "dayzvehicle", 1);
	local tires,engine,parts,slots = getVehicleAddonInfos(id);
	setElementData(vehCol, "MAX_Slots", tonumber(slots));
	setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
	setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
	setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
	setElementData(vehCol, "spawn", {id, x, y, z});
	setElementData(vehCol, "fuel", 10);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5], math.random(2));
		setElementData(vehCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(vehCol, ammoData, math.random(2));
		end
	end
end
addEventHandler("respawnDayZVehicle", root, respawnDayZVehicle);

function getVehicleMaxFuel(id)
	for _,v in ipairs(vehicleFuelTable) do
		if (id == v[1]) then return v[2]; end
	end
	return false;
end

addEventHandler("onPlayerVehicleEnter", root, function(veh, seat)
	local id = getElementModel(veh);
	setVehicleEngineState(veh, true);
	if (id == 548) then cancelEvent(); end
	if (id == 509) then return; end
	local col = getElementData(veh, "parent");
	local tires,engine,parts,_ = getVehicleAddonInfos(id);
	setElementData(veh, "maxfuel", getVehicleMaxFuel(id));
	setElementData(veh, "needtires", tires);
	setElementData(veh, "needparts", parts);
	setElementData(veh, "needengines", engine);
	setVehicleEngineState(veh, false);
	if (getElementData(col, "Parts_inVehicle") == parts) then
		setElementData(veh, "fplus", 5);
	else
		setElementData(veh, "fplus", 20);
	end
	if (getElementData(col, "Tire_inVehicle") == tires) then
		if (getElementData(col, "Engine_inVehicle") == engine) then
			if (getElementData(col, "fuel") > 0) then
				setVehicleEngineState(veh, true);
				if (seat == 0) then
					bindKey(source, "k", "down", setEngineStateByPlayer);
					outputChatBox("Press [K] to toggle the engine!", source, 255, 255, 255);
				end
			else
				triggerClientEvent(source, "displayClientInfo", source, "Fuel tank is empty!", 22, 255, 0);
				setVehicleEngineState(veh, false);
			end
		else
			triggerClientEvent(source, "displayClientInfo", source, "This veh doesn't have Engine!", 22, 255, 0);
			setVehicleEngineState(veh, false);
		end
	else
		triggerClientEvent(source, "displayClientInfo", source, "Some Tires are missing!", 22, 255, 0);
		setVehicleEngineState(veh, false);
	end
end);

addEventHandler("onPlayerVehicleExit", root, function(veh, seat)
	if (seat == 0) then
		setVehicleEngineState(veh, false);
		unbindKey(source, "k", "down", setEngineStateByPlayer);
	end
end);

function getVehicleFuelRemove(id)
	for _,v in ipairs(vehicleFuelInfo) do
		if (v[1] == id) then return v[2]; end
	end
end

setTimer(function()
	for _,v in pairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 509) then
			if (getVehicleEngineState(v) == true) then
				if (getElementData(getElementData(v, "parent"), "fuel") >= 1) then
					setElementData(getElementData(v, "parent"), "fuel", getElementData(getElementData(v, "parent"), "fuel")-(getVehicleFuelRemove(getElementModel(v))*getElementData(v, "fplus"))/60);
				else
					setVehicleEngineState(v, false);
				end
			end
		end
	end
end, 1000, 0);

addEventHandler("repairVehicle", root, function(veh)
	if repairTimer[veh] then triggerClientEvent(source, "displayClientInfo", source, getVehicleName(veh).." is already in repair!", 255, 22, 0) return; end
	repairTimer[veh] = setTimer(fixDayZVehicle, (1000-(math.floor(getElementHealth(veh))))*120, 1, veh, source);
	setElementFrozen(veh, true);
	setElementFrozen(source, true);
	setPedWeaponSlot(source, 0);
	setElementData(veh, "repairer", source);
	setElementData(source, "repairingvehicle", veh);
	setElementData(source, "repairvehicle", true);
	setPedAnimation(source, "SCRATCHING", "sclng_r", nil, true, false);
	triggerClientEvent(source, "displayClientInfo", source, "Started to repair "..getVehicleName(veh), 22, 255, 0);
end);

function fixDayZVehicle(veh, player)
	setElementHealth(veh, 1000);
	fixVehicle(veh);
	setPedAnimation(player, false);
	setElementFrozen(veh, false);
	setElementFrozen(player, false);
	setElementData(player, "repairvehicle", false);
	repairTimer[veh] = nil;
	setElementData(veh, "repairer", nil);
	setElementData(player, "repairingvehicle", nil);
	triggerClientEvent(player, "displayClientInfo", player, "You repaired "..getVehicleName(veh), 22, 255, 0);
end

addEventHandler("onPlayerQuit", root, function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementData(v, "repairer") and getElementData(v, "repairer") == source) then
			outputDebugString("Vehicle repairer disconnected - destroyed tables", 3);
			killTimer(repairTimer[v]);
			setElementFrozen(v, false);
			repairTimer[v] = nil;
			setElementData(v, "repairer", nil);
		end 
	end
end);

function setEngineStateByPlayer(player)
	local veh = getPedOccupiedVehicle(player);
	if (getElementData(getElementData(veh,"parent"), "fuel") <= 0) then return; end
	if (getVehicleEngineState(veh) == false) then
		setVehicleEngineState(veh, true);
		triggerClientEvent(player, "displayClientInfo", player, "Engine started!", 22, 255, 0);
	else
		setVehicleEngineState(veh, false);
		triggerClientEvent(player, "displayClientInfo", player, "Engine stopped!", 255, 22, 0);
	end
end

function backup()
	dbExec(db, "DELETE FROM `vehicles`");
	dbExec(db, "DELETE FROM `tents`");
	local vc,tc = 0, 0;
	for _,veh in ipairs(getElementsByType("vehicle")) do
		if not getElementData(veh, "helicrash") then
			local col = getElementData(veh, "parent");
			if col then
				local x,y,z = getElementPosition(veh);
				local rX,rY,rZ = getElementRotation(veh);
				local health = getElementHealth(veh);
				if (health < 500) then health = 400; end
				local sx,sy,sz = unpack(getElementData(col, "spawn"));
				local items = {};
				vc = vc+1;
				for _,item in ipairs(backupItemsTable) 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, dayz, health, sx, sy, sz, 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), getElementData(veh, "dayzvehicle") or 0, health, sx, sy, sz, vc);
			end
		end
	end
	for _,col in ipairs(getElementsByType("colshape")) do
		if getElementData(col, "tent") then
			local tent = getElementData(col, "parent");
			if tent then
				local x,y,z = getElementPosition(tent);
				local rX,rY,rZ = getElementRotation(tent);
				local items = {};
				tc = tc+1;
				for _,item in ipairs(backupItemsTable) 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
	end
	outputDebugString("Backup done ("..tc.." Tents) and ("..vc.." Vehicles)", 3);
end

function createDayzVeh(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, dayz, health, sx, sy, sz)
	local veh = createVehicle(model, x, y, z);
	local vehCol = createColSphere((x+5), y, z, 4);
	setElementRotation(veh, rX, rY, rZ);
	attachElements(vehCol, veh);
	setElementHealth(veh, tonumber(health));
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(veh, "dayzvehicle", tonumber(dayz));
	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, sx, sy, sz});
	setElementData(vehCol, "fuel", tonumber(fuel));
	for _,v in ipairs(fromJSON(items)) do
		setElementData(vehCol, v[1], v[2]);
	end
end

function createDayzTent(model, x, y, z, rX, rY, rZ, slots, scale, items)
	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);
	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 loadBackup()
	for _,v in pairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	local p = dbPoll(dbQuery(db, "SELECT * FROM `vehicles`"), -1);
	if (#p > 0) then
		for _,d in pairs(p) do
			createDayzVeh(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["dayz"], d["health"], d["sx"], d["sy"], d["sz"]);
		end
	end
	local p2 = dbPoll(dbQuery(db, "SELECT * FROM `tents`"), -1);
	if (#p2 > 0) then
		for _,d in pairs(p2) do
			createDayzTent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"]);
		end
	end
end

if not backupdone then
	spawnDayZVehicles();
	backupdone = true;
else
	loadBackup();
end
setTimer(backup, (10*60000), 0);

addCommandHandler("dobackup", function(player)
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		backup();
	end
end);

for _,v in ipairs(patrolPoints) do
	local x,y,z = v[1], v[2], v[3];
	patrolCol = createColSphere(x, y, z, 3);
	setElementData(patrolCol, "patrolstation", true);
end

createHeliCrashSite();
createHospitalPacks();

 

 

Link to comment

Try this:

 
local vehicleSpawns = {
	--[[Maverick]]
	{487, -1185.9775390625,26.4111328125,14.1484375},
	{487, -1724.5830078125,2559.3544921875,104.09127807617},
	{487, 615.744140625,850.1572265625,-43.009014129639},
	{487, 232.5283203125,1950.3583984375,17.640625},
	{487, -1050.5859375,1968.033203125,120.66523742676},
	{487, 2821.03515625,2809.6689453125,10.8203125},
	{487, 1949.9912109375,-2631.44140625,13.546875},
	{487, -756.53979492188,-2137.5471191406,26.463499069214},
	--[[Patriot]]
	{470, -1473.5791015625,320.2294921875,7.1875},
	{470, -1373.998046875,460.62109375,7.1875},
	{470, 419.150390625,2186.087890625,39.499450683594},
	{470, 2821.1796875,793.4658203125,10.8984375},
	--[[Bobcat]]
	{422, -2479.6240234375,2223.6669921875,4.84375},
	{422, -92.9951171875,2823.0908203125,76.721649169922},
	{422, -2448.99609375,-1335.8662109375,310.97662353516},
	{422, -173.2470703125,-2635.5341796875,26.608192443848},
	{422, 2108.447265625,-1600.916015625,13.552597045898},
	{422, 2452.7392578125,1607.9833984375,10.8203125},
	{422, -1800.8984375,-1950.9736328125,93.561332702637},
	--[[Sanchez]]
	{468, -812.470703125,-2629.912109375,90.105056762695},
	{468, -1729.8525390625,-1940.3154296875,99.840209960938},
	{468, -2130.90234375,178.4375,35.257678985596},
	{468, -2656.7333984375,1352.4873046875,7.0596733093262},
	{468, -1598.302734375,2694.947265625,55.07092666626},
	{468, -809.96484375,2430.037109375,156.97012329102},
	{468, 2920.38671875,2486.0087890625,10.8203125},
	{468, 505.732421875,-291.8681640625,20.00952911377},
	{468, -428.8828125,-694.8310546875,19.14847946167},
	{468, 1190.41015625,-2109.0341796875,64.738548278809},
	{468, 1658.9716796875,-1069.0224609375,23.906229019165},
	--[[Barracks]]
	{433, 86.486328125,1950.9013671875,17.846803665161},
	{433, 440.185546875,1464.173828125,6.3338670730591},
	--[[Coach]]
	{437, -1971.4619140625,97.4658203125,27.6875},
	{437, 1735.8720703125,1429.0693359375,10.797702789307},
	{437, 2797.1318359375,-1868.8359375,9.8603811264038},
	{437, 1941.900390625,1975.1904296875,7.59375},
	--[[Reefer]]
	{453, 2463.3984375,-2719.638671875,-0.55000001192093},
	{453, -1577.4873046875,182.353515625,-0.53995263576508},
	{453, -806.80859375,2233.7001953125,40.049976348877},
	{453, -127.4453125,-779.6923828125,-0.55000001192093},
	--[[Bike]]
	{509, 194.685546875,-120.2333984375,1.5497757196426},
	{509, 173.0146484375,-95.0634765625,1.5516006946564},
	{509, 2369.9599609375,29.712890625,28.0416431427},
	{509, 710.87109375,-566.7548828125,16.3359375},
	{509, 1109.6025390625,-1667.6689453125,13.615442276001},
	{509, 2014.6689453125,-1113.4013671875,26.203125},
	{509, 2447.41015625,-1967.1845703125,13.546875},
	{509, 2633.7236328125,1835.291015625,11.0234375},
	{509, 1489.3974609375,2681.54296875,10.8203125},
	{509, -2428.5654296875,2280.875,4.984375},
	{509, -2501.0869140625,2224.880859375,4.9861993789673},
	{509, -2142.8515625,-2457.84765625,30.625},
	{509, -2456.078125,-141.115234375,26.112222671509},
	{509, -1881.4453125,954.3837890625,35.171875},
	--[[Police Maverick]]
	{497, -1495.888671875,-2691.40234375,57.325229644775},
	{497, -2688.42578125,1471.634765625,7.1875},
	{497, -1534.28125,2842.9482421875,97.463409423828},
	{497, 2221.8583984375,-1344.396484375,23.984273910522},
};

local hospitalPacks = {
	{-2670.87890625,636.8984375,14.453125},
	{-2637.0556640625,635.03125,14.453125},
	{-1515.669921875,2519.166015625,56.0703125},
	{-1513.888671875,2519.5908203125,56.064819335938},
	{-1528.8955078125,2516.724609375,55.986171722412},
	{2022.1650390625,-1402.6806640625,17.18045425415},
	{2042.7001953125,-1409.4775390625,17.1640625},
	{-316.5478515625,1051.6494140625,20.340259552002},
	{-337.9541015625,1049.490234375,19.739168167114},
	{-331.5849609375,1046.037109375,26.012474060059},
	{-307.0419921875,1045.27734375,26.012474060059},
	{1171.490234375,-1310.560546875,13.986573219299},
	{1171.609375,-1306.556640625,13.996350288391},
	{1158.5048828125,-1326.333984375,31.503561019897},
	{1159.80078125,-1323.9013671875,31.498970031738},
	{1238.7119140625,328.2431640625,19.7555103302},
	{1229.365234375,311.1435546875,24.7578125},
	{-2204.07421875,-2309.58203125,31.375},
	{1615.939453125,1818.0537109375,10.8203125},
	{1601.9443359375,1816.736328125,10.8203125},
	{1590.0166015625,1792.0234375,30.46875},
	{1607.3232421875,1776.7412109375,37.3125},
	{2107.7626953125,926.16015625,10.8203125},
	{2116.12890625,925.7705078125,10.9609375},
	{2122.1865234375,925.3193359375,10.8203125},
};
local patrolPoints = {
	{-1603.2197265625,-2712.736328125,48.9453125},
	{2465.748046875,-2215.55859375,13.546875},
	{2473.439453125,-2215.56640625,13.546875},
	{2480.0732421875,-2216.140625,13.546875},
	{2487.24609375,-2215.5966796875,13.546875},
	{2494.1005859375,-2215.5859375,13.546875},
	{-1686.6728515625,408.9970703125,7.3984375},
	{-1682.34375,412.9384765625,7.3984375},
	{-1680.0263671875,402.3642578125,7.3984375},
	{-1675.84375,406.4677734375,7.3984375},
	{-1670.5615234375,411.8359375,7.3984375},
	{-1666.2392578125,416.2509765625,7.3984375},
	{-1672.7939453125,422.81640625,7.3984375},
	{-1677.20703125,418.46484375,7.3984375},
	{-2410.7021484375,969.9091796875,45.4609375},
	{-2410.744140625,975.220703125,45.4609375},
	{-2410.837890625,980.5302734375,45.4609375},
	{-1329.3046875,2668.5126953125,50.46875},
	{-1328.7314453125,2673.90625,50.0625},
	{-1327.0185546875,2679.3876953125,50.46875},
	{-1327.3798828125,2684.62890625,50.0625},
	{1940.7099609375,-1778.5244140625,13.390598297119},
	{1940.6552734375,-1774.908203125,13.390598297119},
	{1940.630859375,-1771.728515625,13.390598297119},
	{1940.7080078125,-1767.3837890625,13.390598297119},
	{-1477.921875,1868.138671875,32.639846801758},
	{-1466.1552734375,1869.0048828125,32.6328125},
	{-1464.5224609375,1861.3828125,32.639846801758},
	{-1477.4599609375,1860.5205078125,32.6328125},
	{-735.9208984375,2744.0087890625,47.2265625},
	{-739.0439453125,2744.2421875,47.165451049805},
	{377.6953125,2601.1083984375,16.484375},
	{624.5263671875,1676.25390625,6.9921875},
	{620.2958984375,1681.2431640625,6.9921875},
	{616.248046875,1686.4169921875,7.1875},
	{612.783203125,1691.1650390625,7.1875},
	{609.2060546875,1696.201171875,7.1875},
	{605.8505859375,1700.978515625,7.1875},
	{602.27734375,1706.3603515625,7.1875},
	{2141.037109375,2742.734375,10.960174560547},
	{2142.3115234375,2752.6982421875,10.96019744873},
	{2147.9521484375,2752.3203125,10.8203125},
	{2152.60546875,2751.953125,10.8203125},
	{2152.984375,2743.85546875,10.8203125},
	{2147.75,2743.7392578125,10.8203125},
	{-97.6298828125,-1175.0283203125,2.4990689754486},
	{-90.74609375,-1177.853515625,2.2021217346191},
	{-84.75390625,-1163.853515625,2.3359375},
	{-91.5771484375,-1160.5732421875,2.4453125},
	{-1606.525390625,-2717.2138671875,48.9453125},
	{-1609.7109375,-2721.544921875,48.9453125},
	{-1599.83203125,-2708.302734375,48.9453125},
	{-2246.314453125,-2558.8212890625,32.0703125},
	{-2241.3125,-2561.3662109375,32.0703125},
	{-1132.2880859375,-135.0986328125,14.14396572113},
	{-1153.529296875,-156.373046875,14.1484375},
	{-1142.826171875,-145.67578125,14.14396572113},
	{655.611328125,-557.9912109375,16.501491546631},
	{655.6572265625,-572.1728515625,16.501491546631},
	{1601.791015625,2203.90625,11.060997009277},
	{1596.806640625,2203.4345703125,10.8203125},
	{1590.197265625,2203.4853515625,10.8203125},
	{1589.4775390625,2195.43359375,10.8203125},
	{1596.125,2194.294921875,10.8203125},
	{1601.6591796875,2194.3369140625,10.8203125},
	{2206.8466796875,2470.47265625,10.8203125},
	{2206.94140625,2474.75,10.8203125},
	{2206.9267578125,2478.86328125,10.8203125},
	{2198.06640625,2480.6953125,10.8203125},
	{2197.541015625,2475.791015625,10.995170593262},
	{2197.609375,2471.9169921875,10.995170593262},
	{2120.8251953125,915.4833984375,10.8203125},
	{2115.1181640625,915.44140625,10.8203125},
	{2109.076171875,915.4228515625,10.8203125},
	{2109.22265625,924.8779296875,10.9609375},
	{2114.9404296875,924.8857421875,10.9609375},
	{2119.5126953125,925.2861328125,10.9609375},
	{2645.7197265625,1112.7802734375,10.8203125},
	{2639.984375,1112.56640625,10.8203125},
	{2634.828125,1112.3466796875,10.9609375},
	{2634.1826171875,1101.9482421875,10.8203125},
	{2636.7509765625,1101.6748046875,10.8203125},
	{2643.5126953125,1101.81640625,10.8203125},
	{2209.576171875,2469.8251953125,10.8203125},
	{2208.8310546875,2475.09375,10.8203125},
	{1005.078125,-901.7490234375,42.216625213623},
	{993.025390625,-902.474609375,42.222496032715},
};

local heliCrashSites = {
	{-1360.0478515625,-1070.7314453125,160.4069519043},
	{-421.4619140625,-1284.4345703125,33.740924835205},
	{-2357.654296875,-1634.3623046875,483.703125},
	{979.0849609375,160.59375,28.935249328613},
	{-2057.2294921875,2781.73828125,163.12780761719},
	{826.90234375,2803.6259765625,74.863929748535},
	{2577.7060546875,-650.541015625,136.37449645996},
};

local lootItems = {
	["helicrashsides"] = {
		{"Night Vision Goggles",368,1,90,10},
		{"Box of Matches",328,0.4,90,2},
		{"M1911",346,1,90,10},
		{"M9 SD",347,1,90,7},
		{"Winchester 1866",349,1,90,6},
		{"PDW",352,1,90,5.5},
		{"Hunting Knife",335,1,90,4},
		{"Hatchet",339,1,90,3},
		{"Pizza",1582,1,0,2},
		{"Soda Bottle",2647,1,0,2},
		{"Empty Gas Canister",1650,1,0,2},
		{"Roadflare",324,1,90,2},
		{"Milk",2856,1,0,1},
		{"Painkiller",2709,0.5,0,4},
		{"Empty Soda Cans",2673,0.5,0,2},
		{"Scruffy Burgers",2675,0.5,0,3},
		{"Grenade",342,1,0,4},
		{"Parachute",342,1,0,80},
		{"Sawn-Off Shotgun",350,1,90,5},
		{"SPAZ-12 Combat Shotgun",351,1,90,4},
		{"MP5A5",353,1,90,6},
		{"Watch",2710,1,0,4},
		{"Heat Pack",1576,1,0,3},
		{"Wire Fence",933,0.25,0,1},
		{"Lee Enfield",357,1,90,6},
		{"Alice Pack",3026,1,0,4},
		{"Night Vision Goggles",368,1,90,1.5},
		{"Tire",1073,1,0,2},
		{"Morphine",1579,1,0,4},
		{"Camouflage Clothing",1577,1,0,4.5},
		{"Civilian Clothing",1577,1,0,3},
		{"AK-47",355,1,90,7},
		{"GPS",2976,0.15,0,3},
		{"Map",1277,0.8,90,7},
		{"Toolbox",2969,0.5,0,1},
		{"Engine",929,0.3,0,2},
		{"Tent",1279,1,0,4.5},
		{"Ghillie Suit",1577,1,0,0.5},
		{"M4",356,1,90,1},
		{"CZ 550",358,1,90,1.5},
		{"Infrared Goggles",369,1,90,3},
		{"Assault Pack (ACU)",3026,0.5,0,5},
		{"Coyote Backpack",3026,1.3,0,2},
	},
	["hospital"] = {
		{"Medic Kit",2891,0.7,0},
		{"Heat Pack",1576,1,0},
		{"Bandage",1578,0.5,0},
		{"Blood Bag",1580,1,0},
		{"Morphine",1579,1,0},
		{"Blood Bag",1580,1,0},
		{"Medic Kit",2891,0.7,0},
		{"Blood Bag",1580,1,0},
		{"Painkiller",1580,1,0},
	},
};

local backupItemsTable = {
	{"Bandage"},
	{"Painkiller"},
	{"Wood Pile"},
	{"Water Bottle"},
	{"Pasta Can"},
	{"Beans Can"},
	{"Burger"},
	{"Box of Matches"},
	{"PDW"},
	{"Hunting Knife"},
	{"Hatchet"},
	{"Pizza"},
	{"Morphine"},
	{"Soda Bottle"},
	{"Empty Gas Canister"},
	{"Full Gas Canister"},
	{"Roadflare"},
	{"Milk"},
	{"PDW Mag"},
	{"MP5A5 Mag"},
	{"Tear Gas"},
	{"Grenade"},
	{"M1911"},
	{"M1911 Mag"},
	{"M9 SD"},
	{"M9 SD Mag"},
	{"Desert Eagle"},
	{"Desert Eagle Mag"},
	{"MP5A5"},
	{"Watch"},
	{"Medic Kit"},
	{"Heat Pack"},
	{"Blood Bag"},
	{"GPS"},
	{"Map"},
	{"Toolbox"},
	{"Wire Fence"},
	{"Tire"},
	{"Engine"},
	{"Satchel"},
	{"Infrared Goggles"},
	{"Night Vision Goggles"},
	{"Tent"},
	{"Raw Meat"},
	{"Cooked Meat"},
	{"Camouflage Clothing"},
	{"Ghillie Suit"},
	{"Civilian Clothing"},
	{"Survivor Clothing"},
	{"Binoculars"},
	{"Empty Water Bottle"},
	{"Empty Soda Cans"},
	{"Scruffy Burgers"},
	{"Radio Device"},
	{"Baseball Bat"},
	{"Shovel"},
	{"Tank Parts"},
	{"Golf Club"},
	{"Radio Device"},
	{"Parachute"},
	{"M4A1 Holo"},
	{"MK 48 Mod 0"},
	{"MG36"},
	{"PKP"},
	{"AK-107"},
	{"AKS Gold"},
	{"SA-58V ACOG"},
	{"Winchester 1866"},
	{"SPAZ-12 Combat Shotgun"},
	{"Sawn-Off Shotgun"},
	{"AKS-74U"},
	{"SKS-45"},
	{"DMR"},
	{"KVSK"},
	{"AS50"},
	{"CZ550"},
	{"Mosin 9130"},
	{"M24"},
	{"M107"},
	{"SVD Dragunov Camo"},
	{"AKS-74U Mag"},
	{"1866 Slug"},
	{"2Rnd. Slug"},
	{"SPAZ-12 Pellet"},
	{"M4A1 Holo Mag"},
	{"MK 48 Mod 0 Mag"},
	{"MG36 Mag"},
	{"PKP Mag"},
	{"AK-107 Mag"},
	{"AKS Gold Mag"},
	{"SA-58V ACOG Mag"},
	{"DMR Mag"},
	{"AS50 Mag"},
	{"CZ550 Mag"},
	{"Mosin 9130 Mag"},
	{"M24 Mag"},
	{"M107 Mag"},
	{"SVD Dragunov Camo Mag"},
	{"KVSK Mag"},
	{"SKS-45 Mag"}
};

local vehicleAddonsInfo = {
	{422, 4, 1, 1, 25},
	{470, 4, 1, 1, 46},
	{468, 2, 1, 1, 10},
	{433, 6, 1, 1, 70},
	{437, 6, 1, 1, 60},
	{509, 0, 0, 0, 0},
	{487, 0, 1, 1, 20},
	{497, 0, 1, 1, 20},
	{453, 0, 1, 1, 35},
};

local vehicleFuelInfo = {
	{422, 0.25},
	{470, 0.1},
	{468, 0.1},
	{433, 0.5},
	{437, 0.5},
	{509, 0},
	{487, 0.25},
	{497, 0.25},
	{453, 0.1},
};

local vehicleFuelTable = {
	{422, 80},
	{470, 100},
	{468, 30},
	{433, 140},
	{437, 140},
	{509, 0},
	{487, 60},
	{497, 60},
	{453, 60},
};

local hospitalCol = {};
local dayzVehicles = {};
local repairTimer = {};
local last_veh_id = 0;
local last_tent_id = 0;
local backupdone = false;

addEvent("respawnVehiclesInWater", true);
addEvent("repairVehicle", true);
addEvent("respawnDayZVehicle", true);

if fileExists("tools/backup.db") then
	backupdone = true;
else
	backupdone = false;
end

local db = dbConnect("sqlite", "tools/backup.db");
dbExec(db, "CREATE TABLE IF NOT EXISTS `vehicles` (model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, health, dayz, sx, sy, sz, id)");
dbExec(db, "CREATE TABLE IF NOT EXISTS `tents` (model, x, y, z, rX, rY, rZ, slots, scale, items, id)");

function getVehicleAddonInfos(id)
	for _,v in ipairs(vehicleAddonsInfo) do
		if (v[1] == id) then return v[2], v[3], v[4], v[5]; end
	end
end

function createHeliCrashSite()
	if isElement(cargoCol) then
		destroyElement(getElementData(cargoCol, "parent"));
		destroyElement(cargoCol);
	end
	local nr = math.random(7);
	local x,y,z = heliCrashSites[nr][1], heliCrashSites[nr][2], heliCrashSites[nr][3];
	local cargobob = createVehicle(548, x, y, z);
	setElementHealth(cargobob, 0);
	setElementFrozen(cargobob, true);
	local cargoCol = createColSphere(x, y, z, 3);
	setElementData(cargoCol, "parent", cargobob);
	setElementData(cargoCol, "helicrash", true);
	setElementData(cargoCol, "MAX_Slots", 0);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5]*3.5, math.random(2));
		setElementData(cargoCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(cargoCol, ammoData, math.random(2));
		end
	end
	setTimer(createHeliCrashSite, 3600000, 1);
end

function updateHospitals()
	for i,_ in pairs(hospitalCol) do
		for _,v in ipairs(lootItems["hospital"]) do
			setElementData(hospitalCol[i], v[1], math.random(5));
		end
	end
	setTimer(updateHospitals, 3600000, 1);
end

function createHospitalPacks()
	local number1 = 0;
	for i,v in ipairs(hospitalPacks) do
		number1 = number1+1;
		local x,y,z = v[1], v[2], v[3];
		local object = createObject(1558, x, y, z, nil, nil, nil);
		hospitalCol[i] = createColSphere(x, y, z, 2);
		setElementData(hospitalCol[i], "parent", object);
		setElementData(hospitalCol[i], "hospitalbox", true);
		setElementData(hospitalCol[i], "MAX_Slots", 20);
	end
	updateHospitals();
end

function spawnDayZVehicles()
	for _,v in ipairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	for _,v in ipairs(vehicleSpawns) do
		local x,y,z = v[2], v[3], v[4];
		local veh = createVehicle(v[1], x, y, z);
		local vehCol = createColSphere(x, y, z, 2.5);
		attachElements(vehCol, veh);
		setElementData(vehCol, "parent", veh);
		setElementData(veh, "parent", vehCol);
		setElementData(vehCol, "vehicle", true);
		setElementData(veh, "dayzvehicle", 1);
		local tires,engine,parts,slots = getVehicleAddonInfos(v[1]);
		setElementData(vehCol, "MAX_Slots", tonumber(slots));
		setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
		setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
		setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
		setElementData(vehCol, "spawn", {v[1], x, y, z});
		setElementData(vehCol, "fuel", math.random(5, 20));
		for _,v in ipairs(lootItems["helicrashsides"]) do
			local value =  math.percentChance(v[5], math.random(2));
			setElementData(vehCol, v[1], value);
			local ammoData,_ = getWeaponAmmoType(v[1], true);
			if (ammoData and value > 0) then
				setElementData(vehCol, ammoData, math.random(2));
			end
		end
	end
	backup();
end

addEventHandler("onVehicleExplode", root,  function()
	for _,v in pairs(getVehicleOccupants(source)) do
		triggerEvent("kilLDayZPlayer", v);
	end
	local x1,y1,z1 = getElementPosition(source);
	local col = getElementData(source, "parent");
	local id,x,y,z = unpack(getElementData(col, "spawn"));
	setElementData(col, "deadVehicle", true);
	setElementData(source, "isExploded", true);
	if (getElementData(source, "dayzvehicle") == 1) then
		setTimer(respawnDayZVehicle, 18000, 1, id, x, y, z, source, col);
	else
		setTimer(function(col, source)
			if isElement(col) then destroyElement(col); end
			if isElement(source) then destroyElement(source); end
		end, (5*600), 1, col, source);
	end
	createExplosion((x1+4), (y1+1), z1, 4);
	createExplosion((x1+2), (y1-4), z1, 4);
	createExplosion((x1-1), (y1+5), z1, 4);
	createExplosion((x1-4), y1, (z1-2), 4);
end);

setTimer(function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 453) then
			local col = getElementData(v, "parent");
			if col then
				if not (getElementData(col, "deadVehicle") or false) then
					if isElementInWater(v) then
						local id,x,y,z = unpack(getElementData(col, "spawn"));
						if (getElementData(v, "dayzvehicle") == 1) then
							setTimer(respawnDayZVehicle, (5*600), 1, id, x, y, z, v, col);
						else
							setTimer(function(col, v)
								if col then destroyElement(col); end
								if v then destroyElement(v); end
							end, (5*600), 1, col, v);
						end
					end
				end
			end
		end
	end
end, (30*600), 0);

function respawnDayZVehicle(id, x, y, z, veh, col)
	if veh then destroyElement(veh); end
	if col then destroyElement(col); end
	local veh = createVehicle(id, x, y, (tonumber(z)+1));
	local vehCol = createColSphere(x, y, z, 4);
	attachElements(vehCol, veh);
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(vehCol, "vehicle", true);
	setElementData(veh, "dayzvehicle", 1);
	local tires,engine,parts,slots = getVehicleAddonInfos(id);
	setElementData(vehCol, "MAX_Slots", tonumber(slots));
	setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
	setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
	setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
	setElementData(vehCol, "spawn", {id, x, y, z});
	setElementData(vehCol, "fuel", 10);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5], math.random(2));
		setElementData(vehCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(vehCol, ammoData, math.random(2));
		end
	end
end
addEventHandler("respawnDayZVehicle", root, respawnDayZVehicle);

function getVehicleMaxFuel(id)
	for _,v in ipairs(vehicleFuelTable) do
		if (id == v[1]) then return v[2]; end
	end
	return false;
end

addEventHandler("onPlayerVehicleEnter", root, function(veh, seat)
	local id = getElementModel(veh);
	setVehicleEngineState(veh, true);
	if (id == 548) then cancelEvent(); end
	if (id == 509) then return; end
	local col = getElementData(veh, "parent");
	local tires,engine,parts,_ = getVehicleAddonInfos(id);
	setElementData(veh, "maxfuel", getVehicleMaxFuel(id));
	setElementData(veh, "needtires", tires);
	setElementData(veh, "needparts", parts);
	setElementData(veh, "needengines", engine);
	setVehicleEngineState(veh, false);
	if (getElementData(col, "Parts_inVehicle") == parts) then
		setElementData(veh, "fplus", 5);
	else
		setElementData(veh, "fplus", 20);
	end
	if (getElementData(col, "Tire_inVehicle") == tires) then
		if (getElementData(col, "Engine_inVehicle") == engine) then
			if (getElementData(col, "fuel") > 0) then
				setVehicleEngineState(veh, true);
				if (seat == 0) then
					bindKey(source, "k", "down", setEngineStateByPlayer);
					outputChatBox("Press [K] to toggle the engine!", source, 255, 255, 255);
				end
			else
				triggerClientEvent(source, "displayClientInfo", source, "Fuel tank is empty!", 22, 255, 0);
				setVehicleEngineState(veh, false);
			end
		else
			triggerClientEvent(source, "displayClientInfo", source, "This veh doesn't have Engine!", 22, 255, 0);
			setVehicleEngineState(veh, false);
		end
	else
		triggerClientEvent(source, "displayClientInfo", source, "Some Tires are missing!", 22, 255, 0);
		setVehicleEngineState(veh, false);
	end
end);

addEventHandler("onPlayerVehicleExit", root, function(veh, seat)
	if (seat == 0) then
		setVehicleEngineState(veh, false);
		unbindKey(source, "k", "down", setEngineStateByPlayer);
	end
end);

function getVehicleFuelRemove(id)
	for _,v in ipairs(vehicleFuelInfo) do
		if (v[1] == id) then return v[2]; end
	end
end

setTimer(function()
	for _,v in pairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 509) then
			if (getVehicleEngineState(v) == true) then
				if (getElementData(getElementData(v, "parent"), "fuel") >= 1) then
					setElementData(getElementData(v, "parent"), "fuel", getElementData(getElementData(v, "parent"), "fuel")-(getVehicleFuelRemove(getElementModel(v))*getElementData(v, "fplus"))/60);
				else
					setVehicleEngineState(v, false);
				end
			end
		end
	end
end, 1000, 0);

addEventHandler("repairVehicle", root, function(veh)
	if repairTimer[veh] then triggerClientEvent(source, "displayClientInfo", source, getVehicleName(veh).." is already in repair!", 255, 22, 0) return; end
	repairTimer[veh] = setTimer(fixDayZVehicle, (1000-(math.floor(getElementHealth(veh))))*120, 1, veh, source);
	setElementFrozen(veh, true);
	setElementFrozen(source, true);
	setPedWeaponSlot(source, 0);
	setElementData(veh, "repairer", source);
	setElementData(source, "repairingvehicle", veh);
	setElementData(source, "repairvehicle", true);
	setPedAnimation(source, "SCRATCHING", "sclng_r", nil, true, false);
	triggerClientEvent(source, "displayClientInfo", source, "Started to repair "..getVehicleName(veh), 22, 255, 0);
end);

function fixDayZVehicle(veh, player)
	setElementHealth(veh, 1000);
	fixVehicle(veh);
	setPedAnimation(player, false);
	setElementFrozen(veh, false);
	setElementFrozen(player, false);
	setElementData(player, "repairvehicle", false);
	repairTimer[veh] = nil;
	setElementData(veh, "repairer", nil);
	setElementData(player, "repairingvehicle", nil);
	triggerClientEvent(player, "displayClientInfo", player, "You repaired "..getVehicleName(veh), 22, 255, 0);
end

addEventHandler("onPlayerQuit", root, function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementData(v, "repairer") and getElementData(v, "repairer") == source) then
			outputDebugString("Vehicle repairer disconnected - destroyed tables", 3);
			killTimer(repairTimer[v]);
			setElementFrozen(v, false);
			repairTimer[v] = nil;
			setElementData(v, "repairer", nil);
		end 
	end
end);

function setEngineStateByPlayer(player)
	local veh = getPedOccupiedVehicle(player);
	if (getElementData(getElementData(veh,"parent"), "fuel") <= 0) then return; end
	if (getVehicleEngineState(veh) == false) then
		setVehicleEngineState(veh, true);
		triggerClientEvent(player, "displayClientInfo", player, "Engine started!", 22, 255, 0);
	else
		setVehicleEngineState(veh, false);
		triggerClientEvent(player, "displayClientInfo", player, "Engine stopped!", 255, 22, 0);
	end
end

function backup()
	dbExec(db, "DELETE FROM `vehicles`");
	dbExec(db, "DELETE FROM `tents`");
	local vc,tc = 0, 0;
	for _,veh in ipairs(getElementsByType("vehicle")) do
		if not getElementData(veh, "helicrash") then
			local col = getElementData(veh, "parent");
			if col then
				local x,y,z = getElementPosition(veh);
				local rX,rY,rZ = getElementRotation(veh);
				local health = getElementHealth(veh);
				if (health < 500) then health = 400; end
				local sx,sy,sz = unpack(getElementData(col, "spawn"));
				local items = {};
				vc = vc+1;
				for _,item in ipairs(backupItemsTable) 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, dayz, health, sx, sy, sz, 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), getElementData(veh, "dayzvehicle") or 0, health, sx, sy, sz, vc);
			end
		end
	end
	for _,col in ipairs(getElementsByType("colshape")) do
		if getElementData(col, "tent") then
			local tent = getElementData(col, "parent");
			if tent then
				local x,y,z = getElementPosition(tent);
				local rX,rY,rZ = getElementRotation(tent);
				local items = {};
				tc = tc+1;
				for _,item in ipairs(backupItemsTable) 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
	end
	outputDebugString("Backup done ("..tc.." Tents) and ("..vc.." Vehicles)", 3);
end

function createDayzVeh(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, dayz, health, sx, sy, sz)
	local veh = createVehicle(model, x, y, z);
	local vehCol = createColSphere((x+5), y, z, 4);
	setElementRotation(veh, rX, rY, rZ);
	attachElements(vehCol, veh);
	setElementHealth(veh, tonumber(health));
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(veh, "dayzvehicle", tonumber(dayz));
	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, sx, sy, sz});
	setElementData(vehCol, "fuel", tonumber(fuel));
	for _,v in ipairs(fromJSON(items)) do
		setElementData(vehCol, v[1], v[2]);
	end
end

function createDayzTent(model, x, y, z, rX, rY, rZ, slots, scale, items)
	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);
	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 loadBackup()
	for _,v in pairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	local p = dbPoll(dbQuery(db, "SELECT * FROM `vehicles`"), -1);
	if (#p > 0) then
		for _,d in pairs(p) do
			createDayzVeh(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["dayz"], d["health"], d["sx"], d["sy"], d["sz"]);
		end
	end
	local p2 = dbPoll(dbQuery(db, "SELECT * FROM `tents`"), -1);
	if (#p2 > 0) then
		for _,d in pairs(p2) do
			createDayzTent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"]);
		end
	end
end

if not backupdone then
	spawnDayZVehicles();
	backupdone = true;
else
	loadBackup();
end
setTimer(backup, (10*60000), 0);

addCommandHandler("dobackup", function(player)
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		backup();
	end
end);

for _,v in ipairs(patrolPoints) do
	local x,y,z = v[1], v[2], v[3];
	patrolCol = createColSphere(x, y, z, 3);
	setElementData(patrolCol, "patrolstation", true);
end

createHeliCrashSite();
createHospitalPacks();

 

Link to comment
6 hours ago, Tekken said:

Try this:

Spoiler



local vehicleSpawns = {
	--[[Maverick]]
	{487, -1185.9775390625,26.4111328125,14.1484375},
	{487, -1724.5830078125,2559.3544921875,104.09127807617},
	{487, 615.744140625,850.1572265625,-43.009014129639},
	{487, 232.5283203125,1950.3583984375,17.640625},
	{487, -1050.5859375,1968.033203125,120.66523742676},
	{487, 2821.03515625,2809.6689453125,10.8203125},
	{487, 1949.9912109375,-2631.44140625,13.546875},
	{487, -756.53979492188,-2137.5471191406,26.463499069214},
	--[[Patriot]]
	{470, -1473.5791015625,320.2294921875,7.1875},
	{470, -1373.998046875,460.62109375,7.1875},
	{470, 419.150390625,2186.087890625,39.499450683594},
	{470, 2821.1796875,793.4658203125,10.8984375},
	--[[Bobcat]]
	{422, -2479.6240234375,2223.6669921875,4.84375},
	{422, -92.9951171875,2823.0908203125,76.721649169922},
	{422, -2448.99609375,-1335.8662109375,310.97662353516},
	{422, -173.2470703125,-2635.5341796875,26.608192443848},
	{422, 2108.447265625,-1600.916015625,13.552597045898},
	{422, 2452.7392578125,1607.9833984375,10.8203125},
	{422, -1800.8984375,-1950.9736328125,93.561332702637},
	--[[Sanchez]]
	{468, -812.470703125,-2629.912109375,90.105056762695},
	{468, -1729.8525390625,-1940.3154296875,99.840209960938},
	{468, -2130.90234375,178.4375,35.257678985596},
	{468, -2656.7333984375,1352.4873046875,7.0596733093262},
	{468, -1598.302734375,2694.947265625,55.07092666626},
	{468, -809.96484375,2430.037109375,156.97012329102},
	{468, 2920.38671875,2486.0087890625,10.8203125},
	{468, 505.732421875,-291.8681640625,20.00952911377},
	{468, -428.8828125,-694.8310546875,19.14847946167},
	{468, 1190.41015625,-2109.0341796875,64.738548278809},
	{468, 1658.9716796875,-1069.0224609375,23.906229019165},
	--[[Barracks]]
	{433, 86.486328125,1950.9013671875,17.846803665161},
	{433, 440.185546875,1464.173828125,6.3338670730591},
	--[[Coach]]
	{437, -1971.4619140625,97.4658203125,27.6875},
	{437, 1735.8720703125,1429.0693359375,10.797702789307},
	{437, 2797.1318359375,-1868.8359375,9.8603811264038},
	{437, 1941.900390625,1975.1904296875,7.59375},
	--[[Reefer]]
	{453, 2463.3984375,-2719.638671875,-0.55000001192093},
	{453, -1577.4873046875,182.353515625,-0.53995263576508},
	{453, -806.80859375,2233.7001953125,40.049976348877},
	{453, -127.4453125,-779.6923828125,-0.55000001192093},
	--[[Bike]]
	{509, 194.685546875,-120.2333984375,1.5497757196426},
	{509, 173.0146484375,-95.0634765625,1.5516006946564},
	{509, 2369.9599609375,29.712890625,28.0416431427},
	{509, 710.87109375,-566.7548828125,16.3359375},
	{509, 1109.6025390625,-1667.6689453125,13.615442276001},
	{509, 2014.6689453125,-1113.4013671875,26.203125},
	{509, 2447.41015625,-1967.1845703125,13.546875},
	{509, 2633.7236328125,1835.291015625,11.0234375},
	{509, 1489.3974609375,2681.54296875,10.8203125},
	{509, -2428.5654296875,2280.875,4.984375},
	{509, -2501.0869140625,2224.880859375,4.9861993789673},
	{509, -2142.8515625,-2457.84765625,30.625},
	{509, -2456.078125,-141.115234375,26.112222671509},
	{509, -1881.4453125,954.3837890625,35.171875},
	--[[Police Maverick]]
	{497, -1495.888671875,-2691.40234375,57.325229644775},
	{497, -2688.42578125,1471.634765625,7.1875},
	{497, -1534.28125,2842.9482421875,97.463409423828},
	{497, 2221.8583984375,-1344.396484375,23.984273910522},
};
local hospitalPacks = {
	{-2670.87890625,636.8984375,14.453125},
	{-2637.0556640625,635.03125,14.453125},
	{-1515.669921875,2519.166015625,56.0703125},
	{-1513.888671875,2519.5908203125,56.064819335938},
	{-1528.8955078125,2516.724609375,55.986171722412},
	{2022.1650390625,-1402.6806640625,17.18045425415},
	{2042.7001953125,-1409.4775390625,17.1640625},
	{-316.5478515625,1051.6494140625,20.340259552002},
	{-337.9541015625,1049.490234375,19.739168167114},
	{-331.5849609375,1046.037109375,26.012474060059},
	{-307.0419921875,1045.27734375,26.012474060059},
	{1171.490234375,-1310.560546875,13.986573219299},
	{1171.609375,-1306.556640625,13.996350288391},
	{1158.5048828125,-1326.333984375,31.503561019897},
	{1159.80078125,-1323.9013671875,31.498970031738},
	{1238.7119140625,328.2431640625,19.7555103302},
	{1229.365234375,311.1435546875,24.7578125},
	{-2204.07421875,-2309.58203125,31.375},
	{1615.939453125,1818.0537109375,10.8203125},
	{1601.9443359375,1816.736328125,10.8203125},
	{1590.0166015625,1792.0234375,30.46875},
	{1607.3232421875,1776.7412109375,37.3125},
	{2107.7626953125,926.16015625,10.8203125},
	{2116.12890625,925.7705078125,10.9609375},
	{2122.1865234375,925.3193359375,10.8203125},
};
local patrolPoints = {
	{-1603.2197265625,-2712.736328125,48.9453125},
	{2465.748046875,-2215.55859375,13.546875},
	{2473.439453125,-2215.56640625,13.546875},
	{2480.0732421875,-2216.140625,13.546875},
	{2487.24609375,-2215.5966796875,13.546875},
	{2494.1005859375,-2215.5859375,13.546875},
	{-1686.6728515625,408.9970703125,7.3984375},
	{-1682.34375,412.9384765625,7.3984375},
	{-1680.0263671875,402.3642578125,7.3984375},
	{-1675.84375,406.4677734375,7.3984375},
	{-1670.5615234375,411.8359375,7.3984375},
	{-1666.2392578125,416.2509765625,7.3984375},
	{-1672.7939453125,422.81640625,7.3984375},
	{-1677.20703125,418.46484375,7.3984375},
	{-2410.7021484375,969.9091796875,45.4609375},
	{-2410.744140625,975.220703125,45.4609375},
	{-2410.837890625,980.5302734375,45.4609375},
	{-1329.3046875,2668.5126953125,50.46875},
	{-1328.7314453125,2673.90625,50.0625},
	{-1327.0185546875,2679.3876953125,50.46875},
	{-1327.3798828125,2684.62890625,50.0625},
	{1940.7099609375,-1778.5244140625,13.390598297119},
	{1940.6552734375,-1774.908203125,13.390598297119},
	{1940.630859375,-1771.728515625,13.390598297119},
	{1940.7080078125,-1767.3837890625,13.390598297119},
	{-1477.921875,1868.138671875,32.639846801758},
	{-1466.1552734375,1869.0048828125,32.6328125},
	{-1464.5224609375,1861.3828125,32.639846801758},
	{-1477.4599609375,1860.5205078125,32.6328125},
	{-735.9208984375,2744.0087890625,47.2265625},
	{-739.0439453125,2744.2421875,47.165451049805},
	{377.6953125,2601.1083984375,16.484375},
	{624.5263671875,1676.25390625,6.9921875},
	{620.2958984375,1681.2431640625,6.9921875},
	{616.248046875,1686.4169921875,7.1875},
	{612.783203125,1691.1650390625,7.1875},
	{609.2060546875,1696.201171875,7.1875},
	{605.8505859375,1700.978515625,7.1875},
	{602.27734375,1706.3603515625,7.1875},
	{2141.037109375,2742.734375,10.960174560547},
	{2142.3115234375,2752.6982421875,10.96019744873},
	{2147.9521484375,2752.3203125,10.8203125},
	{2152.60546875,2751.953125,10.8203125},
	{2152.984375,2743.85546875,10.8203125},
	{2147.75,2743.7392578125,10.8203125},
	{-97.6298828125,-1175.0283203125,2.4990689754486},
	{-90.74609375,-1177.853515625,2.2021217346191},
	{-84.75390625,-1163.853515625,2.3359375},
	{-91.5771484375,-1160.5732421875,2.4453125},
	{-1606.525390625,-2717.2138671875,48.9453125},
	{-1609.7109375,-2721.544921875,48.9453125},
	{-1599.83203125,-2708.302734375,48.9453125},
	{-2246.314453125,-2558.8212890625,32.0703125},
	{-2241.3125,-2561.3662109375,32.0703125},
	{-1132.2880859375,-135.0986328125,14.14396572113},
	{-1153.529296875,-156.373046875,14.1484375},
	{-1142.826171875,-145.67578125,14.14396572113},
	{655.611328125,-557.9912109375,16.501491546631},
	{655.6572265625,-572.1728515625,16.501491546631},
	{1601.791015625,2203.90625,11.060997009277},
	{1596.806640625,2203.4345703125,10.8203125},
	{1590.197265625,2203.4853515625,10.8203125},
	{1589.4775390625,2195.43359375,10.8203125},
	{1596.125,2194.294921875,10.8203125},
	{1601.6591796875,2194.3369140625,10.8203125},
	{2206.8466796875,2470.47265625,10.8203125},
	{2206.94140625,2474.75,10.8203125},
	{2206.9267578125,2478.86328125,10.8203125},
	{2198.06640625,2480.6953125,10.8203125},
	{2197.541015625,2475.791015625,10.995170593262},
	{2197.609375,2471.9169921875,10.995170593262},
	{2120.8251953125,915.4833984375,10.8203125},
	{2115.1181640625,915.44140625,10.8203125},
	{2109.076171875,915.4228515625,10.8203125},
	{2109.22265625,924.8779296875,10.9609375},
	{2114.9404296875,924.8857421875,10.9609375},
	{2119.5126953125,925.2861328125,10.9609375},
	{2645.7197265625,1112.7802734375,10.8203125},
	{2639.984375,1112.56640625,10.8203125},
	{2634.828125,1112.3466796875,10.9609375},
	{2634.1826171875,1101.9482421875,10.8203125},
	{2636.7509765625,1101.6748046875,10.8203125},
	{2643.5126953125,1101.81640625,10.8203125},
	{2209.576171875,2469.8251953125,10.8203125},
	{2208.8310546875,2475.09375,10.8203125},
	{1005.078125,-901.7490234375,42.216625213623},
	{993.025390625,-902.474609375,42.222496032715},
};
local heliCrashSites = {
	{-1360.0478515625,-1070.7314453125,160.4069519043},
	{-421.4619140625,-1284.4345703125,33.740924835205},
	{-2357.654296875,-1634.3623046875,483.703125},
	{979.0849609375,160.59375,28.935249328613},
	{-2057.2294921875,2781.73828125,163.12780761719},
	{826.90234375,2803.6259765625,74.863929748535},
	{2577.7060546875,-650.541015625,136.37449645996},
};
local lootItems = {
	["helicrashsides"] = {
		{"Night Vision Goggles",368,1,90,10},
		{"Box of Matches",328,0.4,90,2},
		{"M1911",346,1,90,10},
		{"M9 SD",347,1,90,7},
		{"Winchester 1866",349,1,90,6},
		{"PDW",352,1,90,5.5},
		{"Hunting Knife",335,1,90,4},
		{"Hatchet",339,1,90,3},
		{"Pizza",1582,1,0,2},
		{"Soda Bottle",2647,1,0,2},
		{"Empty Gas Canister",1650,1,0,2},
		{"Roadflare",324,1,90,2},
		{"Milk",2856,1,0,1},
		{"Painkiller",2709,0.5,0,4},
		{"Empty Soda Cans",2673,0.5,0,2},
		{"Scruffy Burgers",2675,0.5,0,3},
		{"Grenade",342,1,0,4},
		{"Parachute",342,1,0,80},
		{"Sawn-Off Shotgun",350,1,90,5},
		{"SPAZ-12 Combat Shotgun",351,1,90,4},
		{"MP5A5",353,1,90,6},
		{"Watch",2710,1,0,4},
		{"Heat Pack",1576,1,0,3},
		{"Wire Fence",933,0.25,0,1},
		{"Lee Enfield",357,1,90,6},
		{"Alice Pack",3026,1,0,4},
		{"Night Vision Goggles",368,1,90,1.5},
		{"Tire",1073,1,0,2},
		{"Morphine",1579,1,0,4},
		{"Camouflage Clothing",1577,1,0,4.5},
		{"Civilian Clothing",1577,1,0,3},
		{"AK-47",355,1,90,7},
		{"GPS",2976,0.15,0,3},
		{"Map",1277,0.8,90,7},
		{"Toolbox",2969,0.5,0,1},
		{"Engine",929,0.3,0,2},
		{"Tent",1279,1,0,4.5},
		{"Ghillie Suit",1577,1,0,0.5},
		{"M4",356,1,90,1},
		{"CZ 550",358,1,90,1.5},
		{"Infrared Goggles",369,1,90,3},
		{"Assault Pack (ACU)",3026,0.5,0,5},
		{"Coyote Backpack",3026,1.3,0,2},
	},
	["hospital"] = {
		{"Medic Kit",2891,0.7,0},
		{"Heat Pack",1576,1,0},
		{"Bandage",1578,0.5,0},
		{"Blood Bag",1580,1,0},
		{"Morphine",1579,1,0},
		{"Blood Bag",1580,1,0},
		{"Medic Kit",2891,0.7,0},
		{"Blood Bag",1580,1,0},
		{"Painkiller",1580,1,0},
	},
};
local backupItemsTable = {
	{"Bandage"},
	{"Painkiller"},
	{"Wood Pile"},
	{"Water Bottle"},
	{"Pasta Can"},
	{"Beans Can"},
	{"Burger"},
	{"Box of Matches"},
	{"PDW"},
	{"Hunting Knife"},
	{"Hatchet"},
	{"Pizza"},
	{"Morphine"},
	{"Soda Bottle"},
	{"Empty Gas Canister"},
	{"Full Gas Canister"},
	{"Roadflare"},
	{"Milk"},
	{"PDW Mag"},
	{"MP5A5 Mag"},
	{"Tear Gas"},
	{"Grenade"},
	{"M1911"},
	{"M1911 Mag"},
	{"M9 SD"},
	{"M9 SD Mag"},
	{"Desert Eagle"},
	{"Desert Eagle Mag"},
	{"MP5A5"},
	{"Watch"},
	{"Medic Kit"},
	{"Heat Pack"},
	{"Blood Bag"},
	{"GPS"},
	{"Map"},
	{"Toolbox"},
	{"Wire Fence"},
	{"Tire"},
	{"Engine"},
	{"Satchel"},
	{"Infrared Goggles"},
	{"Night Vision Goggles"},
	{"Tent"},
	{"Raw Meat"},
	{"Cooked Meat"},
	{"Camouflage Clothing"},
	{"Ghillie Suit"},
	{"Civilian Clothing"},
	{"Survivor Clothing"},
	{"Binoculars"},
	{"Empty Water Bottle"},
	{"Empty Soda Cans"},
	{"Scruffy Burgers"},
	{"Radio Device"},
	{"Baseball Bat"},
	{"Shovel"},
	{"Tank Parts"},
	{"Golf Club"},
	{"Radio Device"},
	{"Parachute"},
	{"M4A1 Holo"},
	{"MK 48 Mod 0"},
	{"MG36"},
	{"PKP"},
	{"AK-107"},
	{"AKS Gold"},
	{"SA-58V ACOG"},
	{"Winchester 1866"},
	{"SPAZ-12 Combat Shotgun"},
	{"Sawn-Off Shotgun"},
	{"AKS-74U"},
	{"SKS-45"},
	{"DMR"},
	{"KVSK"},
	{"AS50"},
	{"CZ550"},
	{"Mosin 9130"},
	{"M24"},
	{"M107"},
	{"SVD Dragunov Camo"},
	{"AKS-74U Mag"},
	{"1866 Slug"},
	{"2Rnd. Slug"},
	{"SPAZ-12 Pellet"},
	{"M4A1 Holo Mag"},
	{"MK 48 Mod 0 Mag"},
	{"MG36 Mag"},
	{"PKP Mag"},
	{"AK-107 Mag"},
	{"AKS Gold Mag"},
	{"SA-58V ACOG Mag"},
	{"DMR Mag"},
	{"AS50 Mag"},
	{"CZ550 Mag"},
	{"Mosin 9130 Mag"},
	{"M24 Mag"},
	{"M107 Mag"},
	{"SVD Dragunov Camo Mag"},
	{"KVSK Mag"},
	{"SKS-45 Mag"}
};
local vehicleAddonsInfo = {
	{422, 4, 1, 1, 25},
	{470, 4, 1, 1, 46},
	{468, 2, 1, 1, 10},
	{433, 6, 1, 1, 70},
	{437, 6, 1, 1, 60},
	{509, 0, 0, 0, 0},
	{487, 0, 1, 1, 20},
	{497, 0, 1, 1, 20},
	{453, 0, 1, 1, 35},
};
local vehicleFuelInfo = {
	{422, 0.25},
	{470, 0.1},
	{468, 0.1},
	{433, 0.5},
	{437, 0.5},
	{509, 0},
	{487, 0.25},
	{497, 0.25},
	{453, 0.1},
};
local vehicleFuelTable = {
	{422, 80},
	{470, 100},
	{468, 30},
	{433, 140},
	{437, 140},
	{509, 0},
	{487, 60},
	{497, 60},
	{453, 60},
};
local hospitalCol = {};
local dayzVehicles = {};
local repairTimer = {};
local last_veh_id = 0;
local last_tent_id = 0;
local backupdone = false;
addEvent("respawnVehiclesInWater", true);
addEvent("repairVehicle", true);
addEvent("respawnDayZVehicle", true);
if fileExists("tools/backup.db") then
	backupdone = true;
else
	backupdone = false;
end
local db = dbConnect("sqlite", "tools/backup.db");
dbExec(db, "CREATE TABLE IF NOT EXISTS `vehicles` (model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, health, dayz, sx, sy, sz, id)");
dbExec(db, "CREATE TABLE IF NOT EXISTS `tents` (model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
function getVehicleAddonInfos(id)
	for _,v in ipairs(vehicleAddonsInfo) do
		if (v[1] == id) then return v[2], v[3], v[4], v[5]; end
	end
end
function createHeliCrashSite()
	if isElement(cargoCol) then
		destroyElement(getElementData(cargoCol, "parent"));
		destroyElement(cargoCol);
	end
	local nr = math.random(7);
	local x,y,z = heliCrashSites[nr][1], heliCrashSites[nr][2], heliCrashSites[nr][3];
	local cargobob = createVehicle(548, x, y, z);
	setElementHealth(cargobob, 0);
	setElementFrozen(cargobob, true);
	local cargoCol = createColSphere(x, y, z, 3);
	setElementData(cargoCol, "parent", cargobob);
	setElementData(cargoCol, "helicrash", true);
	setElementData(cargoCol, "MAX_Slots", 0);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5]*3.5, math.random(2));
		setElementData(cargoCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(cargoCol, ammoData, math.random(2));
		end
	end
	setTimer(createHeliCrashSite, 3600000, 1);
end
function updateHospitals()
	for i,_ in pairs(hospitalCol) do
		for _,v in ipairs(lootItems["hospital"]) do
			setElementData(hospitalCol[i], v[1], math.random(5));
		end
	end
	setTimer(updateHospitals, 3600000, 1);
end
function createHospitalPacks()
	local number1 = 0;
	for i,v in ipairs(hospitalPacks) do
		number1 = number1+1;
		local x,y,z = v[1], v[2], v[3];
		local object = createObject(1558, x, y, z, nil, nil, nil);
		hospitalCol[i] = createColSphere(x, y, z, 2);
		setElementData(hospitalCol[i], "parent", object);
		setElementData(hospitalCol[i], "hospitalbox", true);
		setElementData(hospitalCol[i], "MAX_Slots", 20);
	end
	updateHospitals();
end
function spawnDayZVehicles()
	for _,v in ipairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	for _,v in ipairs(vehicleSpawns) do
		local x,y,z = v[2], v[3], v[4];
		local veh = createVehicle(v[1], x, y, z);
		local vehCol = createColSphere(x, y, z, 2.5);
		attachElements(vehCol, veh);
		setElementData(vehCol, "parent", veh);
		setElementData(veh, "parent", vehCol);
		setElementData(vehCol, "vehicle", true);
		setElementData(veh, "dayzvehicle", 1);
		local tires,engine,parts,slots = getVehicleAddonInfos(v[1]);
		setElementData(vehCol, "MAX_Slots", tonumber(slots));
		setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
		setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
		setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
		setElementData(vehCol, "spawn", {v[1], x, y, z});
		setElementData(vehCol, "fuel", math.random(5, 20));
		for _,v in ipairs(lootItems["helicrashsides"]) do
			local value =  math.percentChance(v[5], math.random(2));
			setElementData(vehCol, v[1], value);
			local ammoData,_ = getWeaponAmmoType(v[1], true);
			if (ammoData and value > 0) then
				setElementData(vehCol, ammoData, math.random(2));
			end
		end
	end
	backup();
end
addEventHandler("onVehicleExplode", root,  function()
	for _,v in pairs(getVehicleOccupants(source)) do
		triggerEvent("kilLDayZPlayer", v);
	end
	local x1,y1,z1 = getElementPosition(source);
	local col = getElementData(source, "parent");
	local id,x,y,z = unpack(getElementData(col, "spawn"));
	setElementData(col, "deadVehicle", true);
	setElementData(source, "isExploded", true);
	if (getElementData(source, "dayzvehicle") == 1) then
		setTimer(respawnDayZVehicle, 18000, 1, id, x, y, z, source, col);
	else
		setTimer(function(col, source)
			if isElement(col) then destroyElement(col); end
			if isElement(source) then destroyElement(source); end
		end, (5*600), 1, col, source);
	end
	createExplosion((x1+4), (y1+1), z1, 4);
	createExplosion((x1+2), (y1-4), z1, 4);
	createExplosion((x1-1), (y1+5), z1, 4);
	createExplosion((x1-4), y1, (z1-2), 4);
end);
setTimer(function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 453) then
			local col = getElementData(v, "parent");
			if col then
				if not (getElementData(col, "deadVehicle") or false) then
					if isElementInWater(v) then
						local id,x,y,z = unpack(getElementData(col, "spawn"));
						if (getElementData(v, "dayzvehicle") == 1) then
							setTimer(respawnDayZVehicle, (5*600), 1, id, x, y, z, v, col);
						else
							setTimer(function(col, v)
								if col then destroyElement(col); end
								if v then destroyElement(v); end
							end, (5*600), 1, col, v);
						end
					end
				end
			end
		end
	end
end, (30*600), 0);
function respawnDayZVehicle(id, x, y, z, veh, col)
	if veh then destroyElement(veh); end
	if col then destroyElement(col); end
	local veh = createVehicle(id, x, y, (tonumber(z)+1));
	local vehCol = createColSphere(x, y, z, 4);
	attachElements(vehCol, veh);
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(vehCol, "vehicle", true);
	setElementData(veh, "dayzvehicle", 1);
	local tires,engine,parts,slots = getVehicleAddonInfos(id);
	setElementData(vehCol, "MAX_Slots", tonumber(slots));
	setElementData(vehCol, "Tire_inVehicle", math.random(0, tires));
	setElementData(vehCol, "Engine_inVehicle", math.random(0, engine));
	setElementData(vehCol, "Parts_inVehicle", math.random(0, parts));
	setElementData(vehCol, "spawn", {id, x, y, z});
	setElementData(vehCol, "fuel", 10);
	for _,v in ipairs(lootItems["helicrashsides"]) do
		local value =  math.percentChance(v[5], math.random(2));
		setElementData(vehCol, v[1], value);
		local ammoData,_ = getWeaponAmmoType(v[1], true);
		if (ammoData and value > 0) then
			setElementData(vehCol, ammoData, math.random(2));
		end
	end
end
addEventHandler("respawnDayZVehicle", root, respawnDayZVehicle);
function getVehicleMaxFuel(id)
	for _,v in ipairs(vehicleFuelTable) do
		if (id == v[1]) then return v[2]; end
	end
	return false;
end
addEventHandler("onPlayerVehicleEnter", root, function(veh, seat)
	local id = getElementModel(veh);
	setVehicleEngineState(veh, true);
	if (id == 548) then cancelEvent(); end
	if (id == 509) then return; end
	local col = getElementData(veh, "parent");
	local tires,engine,parts,_ = getVehicleAddonInfos(id);
	setElementData(veh, "maxfuel", getVehicleMaxFuel(id));
	setElementData(veh, "needtires", tires);
	setElementData(veh, "needparts", parts);
	setElementData(veh, "needengines", engine);
	setVehicleEngineState(veh, false);
	if (getElementData(col, "Parts_inVehicle") == parts) then
		setElementData(veh, "fplus", 5);
	else
		setElementData(veh, "fplus", 20);
	end
	if (getElementData(col, "Tire_inVehicle") == tires) then
		if (getElementData(col, "Engine_inVehicle") == engine) then
			if (getElementData(col, "fuel") > 0) then
				setVehicleEngineState(veh, true);
				if (seat == 0) then
					bindKey(source, "k", "down", setEngineStateByPlayer);
					outputChatBox("Press [K] to toggle the engine!", source, 255, 255, 255);
				end
			else
				triggerClientEvent(source, "displayClientInfo", source, "Fuel tank is empty!", 22, 255, 0);
				setVehicleEngineState(veh, false);
			end
		else
			triggerClientEvent(source, "displayClientInfo", source, "This veh doesn't have Engine!", 22, 255, 0);
			setVehicleEngineState(veh, false);
		end
	else
		triggerClientEvent(source, "displayClientInfo", source, "Some Tires are missing!", 22, 255, 0);
		setVehicleEngineState(veh, false);
	end
end);
addEventHandler("onPlayerVehicleExit", root, function(veh, seat)
	if (seat == 0) then
		setVehicleEngineState(veh, false);
		unbindKey(source, "k", "down", setEngineStateByPlayer);
	end
end);
function getVehicleFuelRemove(id)
	for _,v in ipairs(vehicleFuelInfo) do
		if (v[1] == id) then return v[2]; end
	end
end
setTimer(function()
	for _,v in pairs(getElementsByType("vehicle")) do
		if (getElementModel(v) ~= 509) then
			if (getVehicleEngineState(v) == true) then
				if (getElementData(getElementData(v, "parent"), "fuel") >= 1) then
					setElementData(getElementData(v, "parent"), "fuel", getElementData(getElementData(v, "parent"), "fuel")-(getVehicleFuelRemove(getElementModel(v))*getElementData(v, "fplus"))/60);
				else
					setVehicleEngineState(v, false);
				end
			end
		end
	end
end, 1000, 0);
addEventHandler("repairVehicle", root, function(veh)
	if repairTimer[veh] then triggerClientEvent(source, "displayClientInfo", source, getVehicleName(veh).." is already in repair!", 255, 22, 0) return; end
	repairTimer[veh] = setTimer(fixDayZVehicle, (1000-(math.floor(getElementHealth(veh))))*120, 1, veh, source);
	setElementFrozen(veh, true);
	setElementFrozen(source, true);
	setPedWeaponSlot(source, 0);
	setElementData(veh, "repairer", source);
	setElementData(source, "repairingvehicle", veh);
	setElementData(source, "repairvehicle", true);
	setPedAnimation(source, "SCRATCHING", "sclng_r", nil, true, false);
	triggerClientEvent(source, "displayClientInfo", source, "Started to repair "..getVehicleName(veh), 22, 255, 0);
end);
function fixDayZVehicle(veh, player)
	setElementHealth(veh, 1000);
	fixVehicle(veh);
	setPedAnimation(player, false);
	setElementFrozen(veh, false);
	setElementFrozen(player, false);
	setElementData(player, "repairvehicle", false);
	repairTimer[veh] = nil;
	setElementData(veh, "repairer", nil);
	setElementData(player, "repairingvehicle", nil);
	triggerClientEvent(player, "displayClientInfo", player, "You repaired "..getVehicleName(veh), 22, 255, 0);
end
addEventHandler("onPlayerQuit", root, function()
	for _,v in ipairs(getElementsByType("vehicle")) do
		if (getElementData(v, "repairer") and getElementData(v, "repairer") == source) then
			outputDebugString("Vehicle repairer disconnected - destroyed tables", 3);
			killTimer(repairTimer[v]);
			setElementFrozen(v, false);
			repairTimer[v] = nil;
			setElementData(v, "repairer", nil);
		end 
	end
end);
function setEngineStateByPlayer(player)
	local veh = getPedOccupiedVehicle(player);
	if (getElementData(getElementData(veh,"parent"), "fuel") <= 0) then return; end
	if (getVehicleEngineState(veh) == false) then
		setVehicleEngineState(veh, true);
		triggerClientEvent(player, "displayClientInfo", player, "Engine started!", 22, 255, 0);
	else
		setVehicleEngineState(veh, false);
		triggerClientEvent(player, "displayClientInfo", player, "Engine stopped!", 255, 22, 0);
	end
end
function backup()
	dbExec(db, "DELETE FROM `vehicles`");
	dbExec(db, "DELETE FROM `tents`");
	local vc,tc = 0, 0;
	for _,veh in ipairs(getElementsByType("vehicle")) do
		if not getElementData(veh, "helicrash") then
			local col = getElementData(veh, "parent");
			if col then
				local x,y,z = getElementPosition(veh);
				local rX,rY,rZ = getElementRotation(veh);
				local health = getElementHealth(veh);
				if (health < 500) then health = 400; end
				local sx,sy,sz = unpack(getElementData(col, "spawn"));
				local items = {};
				vc = vc+1;
				for _,item in ipairs(backupItemsTable) 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, dayz, health, sx, sy, sz, 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), getElementData(veh, "dayzvehicle") or 0, health, sx, sy, sz, vc);
			end
		end
	end
	for _,col in ipairs(getElementsByType("colshape")) do
		if getElementData(col, "tent") then
			local tent = getElementData(col, "parent");
			if tent then
				local x,y,z = getElementPosition(tent);
				local rX,rY,rZ = getElementRotation(tent);
				local items = {};
				tc = tc+1;
				for _,item in ipairs(backupItemsTable) 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
	end
	outputDebugString("Backup done ("..tc.." Tents) and ("..vc.." Vehicles)", 3);
end
function createDayzVeh(model, x, y, z, rX, rY, rZ, slots, fuel, engines, moving, parts, items, dayz, health, sx, sy, sz)
	local veh = createVehicle(model, x, y, z);
	local vehCol = createColSphere((x+5), y, z, 4);
	setElementRotation(veh, rX, rY, rZ);
	attachElements(vehCol, veh);
	setElementHealth(veh, tonumber(health));
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(veh, "dayzvehicle", tonumber(dayz));
	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, sx, sy, sz});
	setElementData(vehCol, "fuel", tonumber(fuel));
	for _,v in ipairs(fromJSON(items)) do
		setElementData(vehCol, v[1], v[2]);
	end
end
function createDayzTent(model, x, y, z, rX, rY, rZ, slots, scale, items)
	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);
	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 loadBackup()
	for _,v in pairs(getElementsByType("vehicle")) do
		local col = getElementData(v, "parent");
		if col then
			destroyElement(col);
		end
		destroyElement(v);
	end
	local p = dbPoll(dbQuery(db, "SELECT * FROM `vehicles`"), -1);
	if (#p > 0) then
		for _,d in pairs(p) do
			createDayzVeh(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["dayz"], d["health"], d["sx"], d["sy"], d["sz"]);
		end
	end
	local p2 = dbPoll(dbQuery(db, "SELECT * FROM `tents`"), -1);
	if (#p2 > 0) then
		for _,d in pairs(p2) do
			createDayzTent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"]);
		end
	end
end
if not backupdone then
	spawnDayZVehicles();
	backupdone = true;
else
	loadBackup();
end
setTimer(backup, (10*60000), 0);
addCommandHandler("dobackup", function(player)
	if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then
		backup();
	end
end);
for _,v in ipairs(patrolPoints) do
	local x,y,z = v[1], v[2], v[3];
	patrolCol = createColSphere(x, y, z, 3);
	setElementData(patrolCol, "patrolstation", true);
end
createHeliCrashSite();
createHospitalPacks();

 

 

Now no vehicle is spawned. :(

[18:55:38] WARNING: [DayZ]/dayz/vehicles.lua:534: Bad argument @ 'getElementData

 

Edited by HueKING
Link to comment

Disregard the previous answer. The error does not appear on the console, but does not respawn the vehicles in time.

 

19 minutes ago, HueKING said:

Disregard the previous answer. The error does not appear on the console, but does not respawn the vehicles in time.

 

Resolved. I had to delete the backup generated in the tools folder. Respawn normally now.
Thank you, dude, great job of yours. I was having a problem with another GM when knocking down vehicles in the water.

Edited by HueKING
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...