Jump to content

How to rename car in MTA DAYZ?


Recommended Posts

Hello,

I want change name of car on my dayz server, but when i change name, and i refresh and restart dayz resource , dont work..

vehiclesTable = {
--{Name,ID,Eng,Tire,Parts,Rot,Glass,Slots,Fuel,FuelPerMinute}
    {"Bullet",541,1,4,1,0,4,38,100,0.4},
    {"Nissan GTR",434,1,4,1,0,4,75,100,0.6},
    {"Sultan",560,1,4,1,0,4,40,100,0.4},
    {"Cheetah",415,1,4,1,0,4,40,100,0.5},
    {"Huntley",579,1,4,1,0,4,80,100,0.3},
    {"Infernus",411,1,4,1,0,4,25,60,0.8},
    {"Buffalo",402,1,4,1,0,4,70,80,0.4},
    {"Elegy",562,1,4,1,0,4,37,80,0.8},
    {"Bobcat",422,1,4,1,0,4,20,80,0.25},
    {"Patriot",470,1,4,1,0,4,40,100,0.1},
    {"Clover",542,1,4,1,0,4,35,45,0.3},
    {"Quadbike",471,1,4,1,0,0,15,30,0.1},
    {"Sanchez",468,1,2,1,0,0,10,30,0.1},
    {"Barracks",433,1,6,1,0,4,550,140,0.5},
    {"Coach",437,1,6,1,0,4,70,140,0.5},
    {"BMX",481,0,0,0,0,0,00,000,0},
    {"Dodo",593,1,3,1,1,4,20,60,0.25},
    {"Maverick",487,1,0,1,1,4,30,60,0.25},
    {"P Maverick",497,1,0,1,1,4,35,60,0.25},
    {"Cargobob",548,1,3,1,1,4,60,160,0.5},
	{"FCR900",521,1,2,1,0,0,10,40,0.1},
    {"Police Car",596,1,4,1,0,4,25,60,0.7},
	{"Reefer",453,1,0,1,0,4,30,60,0.1},
}

--engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(getElementModel(veh))
function getVehicleAddonInfos(ID)
  for _,veh in pairs(vehiclesTable)do
	if ID == veh[2] then
	  return veh[3],veh[4],veh[5],veh[6],veh[7],veh[8],veh[9],veh[10]
	end
  end
end


vehSpawns = {}
vehSpawns["Bullet"] = {
{2802.3544921875,-2514.8000488281,13.201187133789}} --- LS DOCK // Bentley

vehSpawns["Nissan GTR"] = {
{1366.3428955078,-936.65637207031,33.699443817139}} --- //  // Nissan GTR

vehSpawns["Sultan"] = {
{1380.2252197266,-938.10247802734,33.699329376221}} --- //  // N/A

vehSpawns["Cheetah"] = {
{1394.9189453125,-940.55358886719,34.028240203857}} --- //  // N/A

vehSpawns["Huntley"] = {
{1413.2999267578,-946.45135498047,35.167465209961}} --- //  // N/A

vehSpawns["Buffalo"] = {
{759.95074462891,-1353.6612548828,13.092642784119}} --- MILITARY CHASS // Nissan 350z Gold

vehSpawns["Infernus"] = {
{-2770.5048828125,389.94644165039,4.0669059753418}}  --- SF MAIRIE // Frankeinstein

vehSpawns["Elegy"] = {
{-1936.3250732422,245.95481872559,34.051239013672}} --- WANG CAR // Nissan Skyline GT-R34

vehSpawns["Bobcat"] = {
{-2479.6240234375,2223.6669921875,4.84375},
{-92.9951171875,2823.0908203125,76.721649169922},
{-1800.8984375,-1950.9736328125,93.561332702637}}

vehSpawns["Patriot"] = {
{1645.2631835938,-12.926432609558,36.097526550293}, --- LS LV
{2302.8237304688,2767.1262207031,10.393176078796}, --- LV KACC
{-1209.0041503906,15.925883293152,13.722880363464}} --- SF AP

vehSpawns["Clover"] = {}

vehSpawns["Quadbike"] = {
{-1545.8480,628.1342,7.1875,180.2506}}

vehSpawns["Sanchez"] = {
{-428.8828125,-694.8310546875,19.14847946167},
{1190.41015625,-2109.0341796875,64.738548278809},
{1658.9716796875,-1069.0224609375,23.906229019165}}

vehSpawns["Barracks"] = {
{958.93658447266,1740.5233154297,8.6484375}}

vehSpawns["Coach"] = {
{1941.900390625,1975.1904296875,7.59375}}

vehSpawns["BMX"] = {
{2447.41015625,-1967.1845703125,13.546875},
{2633.7236328125,1835.291015625,11.0234375},
{1489.3974609375,2681.54296875,10.8203125},
{-2428.5654296875,2280.875,4.984375},
{-2501.0869140625,2224.880859375,4.9861993789673},
{-2142.8515625,-2457.84765625,30.625},
{-2456.078125,-141.115234375,26.112222671509},
{-1881.4453125,954.3837890625,35.171875}}

vehSpawns["Dodo"] = {
{1282.6152,1323.6509,10.8203,91.4783}}

vehSpawns["Maverick"] = {
{-1495.888671875,-2691.40234375,57.325229644775},
{-2688.42578125,1471.634765625,7.1875},
{-1534.28125,2842.9482421875,97.463409423828},
{2221.8583984375,-1344.396484375,23.984273910522}}

vehSpawns["P Maverick"] = {
{-1354.9009,-580.84528,14.148438},
{-1467.4047,1488.0812,8.2500687},
{-1680.4514160156,707.12536621094,30.6015625}}

vehSpawns["Cargobob"] = {}

vehSpawns["FCR900"] = {}

vehSpawns["Police Car"] = {
{2314.9506835938,2460.3657226563,3.2734375},
{1601.1104736328,-1629.669921875,13.477452278137}}

vehSpawns["Reefer"] = {}


vehSpawns["heliCrash"] = {
{1668.5863037109,1374.9967041016,21.437654495239},
{2098.5642089844,1704.3957519531,10.8203125},
{2619.623046875,2719.6687011719,36.538642883301},
{2684.5500488281,2976.1145019531,30.468614578247},
{1340.0433349609,2762.173828125,9.6257648468018},
{1059.3803710938,2476.6469726563,10.8203125},
{351.47512817383,2498.0131835938,16.484375},
{305.8405456543,1995.2849121094,17.640625},
{-197.40312194824,1660.00390625,26.021810531616},
{-487.56500244141,1745.1920166016,103.99423217773},
{357.06970214844,911.48980712891,20.927375793457},
{-964.11517333984,1477.3618164063,45.632247924805},
{-1192.3334960938,1986.4995117188,136.97402954102},
{-1629.4309082031,2817.1286621094,102.23542785645},
{-2815.6418457031,1154.2999267578,19.366659164429},
{-2437.9560546875,658.18707275391,34.744178771973},
{-2088.3549804688,214.24746704102,35.223037719727},
{-1700.8083496094,745.22015380859,55.8984375},
{-2471.6713867188,-616.88671875,132.55667114258},
{-2561.1608886719,-1093.9577636719,176.85137939453},
{-1954.7072753906,-1623.1284179688,85.941825866699},
{-1687.4962158203,-1916.5522460938,98.976768493652},
{2558.2819824219,224.63208007813,53.962261199951},
{1969.8171386719,221.38452148438,28.411020278931},
{1433.2414550781,-198.97677612305,31.246921539307},
{576.18243408203,-560.12347412109,19.566745758057},
{746.94653320313,-1247.1977539063,13.558763504028},
{1887.3846435547,-1423.9608154297,10.359375},
{1765.8123779297,-2286.7592773438,26.796022415161},
{-395.06204223633,-1283.0047607422,32.639259338379},
}

vehSpawns["BMPCrash"] = {
{-2894.9213867188,-849.17651367188,7.0636882781982},
{-2760.6245117188,-66.711250305176,7.0870037078857},
{-1893.9865722656,1068.4642333984,44.802379608154},
{-1546.9285888672,430.88467407227,6.5984349250793},
{-865.67797851563,1268.0095214844,34.137557983398},
{-1463.6905517578,2320.0720214844,48.253265380859},
{-917.05236816406,2009.609375,60.333110809326},
{1167.3447265625,1849.6843261719,9.7337627410889},
{1074.1408691406,886.91180419922,10.239132881165},
{2805.9201660156,1428.3698730469,10.065545082092},
{1706.3686523438,-569.99542236328,35.975856781006},
{1434.5551757813,-2162.1677246094,12.965801239014},
{-141.65487670898,-1385.9279785156,2.4529638290405},
{-833.41076660156,-2537.2878417969,87.400016784668},
{-1326.4068603516,-1675.7856445313,45.104396820068},
{-1770.8583984375,-2637.6164550781,49.148284912109},
}
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},
{1260.6501464844,-1799.30078125,13.478693008423}, -- Military Camp Verdant Bluff
{1280.0263671875,-1810.7297363281,13.463276863098}, -- Military Camp Verdant Bluff
{1352.2316894531,404.55191040039,19.5546875}, --- MONTGOMERY MILITARY CAMP
{-2752.1530761719,403.74862670898,4.4635558128357}, --- MAIRIE SF
{-2770.8791503906,415.75357055664,4.4786520004272}, --- MAIRIE SF
---HOSPITAL SF---
{-2671.3078613281,625.27618408203,14.859218597412}, -- AMBULANCE MEDIC BOX
{-2641.1657714844,622.57006835938,14.859218597412}, -- AMBULANCE MEDIC BOX
--- HOSPITAL ROOF ---
{-2691.83203125,527.86340332031,48.063758850098},
{-2710.32421875,539.60845947266,48.07857131958},
{-2628.9931640625,490.79647827148,47.9765625},
{-2641.9028320313,490.28616333008,47.9765625},
---AU DESSUS DES DAMSO---
{-1913.7913818359,-489.23870849609,38.234375},
{-1913.5050048828,-501.54971313477,38.234375},
{-1233.2175292969,-22.528776168823,14.1484375}, -- SF AP
{-1227.8767089844,-35.254020690918,14.1484375}, -- SF AP
--- SF ECOLE DRIVING---
{-2017.0971679688,-212.9753112793,35.370311737061},
{-2015.7872314453,-193.4952545166,35.379531860352},
{-2090.9128417969,-276.59533691406,35.370311737061},
{657.61706542969,-1370.1496582031,21.80965423584}, --- Chass Camp
--- LV AP--
{1359.6650390625,1293.8995361328,10.880974769592},  --- Box Medic
{1346.6613769531,1279.7176513672,10.867559432983},  --- Box Medic
{1320.3449707031,1279.3846435547,10.870312690735},  --- Box Medic
{1335.13671875,1292.3052978516,10.878839492798},    --- Box Medic
{-327.33227539063,1547.0480957031,75.5703125}, --- BAYSDIE
}

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},
}

lootItems = {
  helicrashsides = {
	{"M4A1",356,1,90,3},
	{"M4A1 CCO",356,1,90,3},
	{"M4A1 CCO SD",356,1,90,3},
	{"FN SCAR",356,1,90,2},
	{"FN SCAR SD",356,1,90,2},
	----------------------------
	{"M107",358,1,90,0.5},
	{"AS50",358,1,90,0.8},
	{"KSVK",358,1,90,0.7},
	{"Cheytac M200",358,1,90,1},
	----------------------------
	{"M249 SAW",355,1,90,1.5},
	{"M240",355,1,90,1.5},
	{"Mk 48 Mod 0",355,1,90,1.5},
	{"PKP",355,1,90,1.5},
	{"PKM",355,1,90,1.5},
    ----------------------------
	{"Balanced Vest",1800,1,0,1},
	{"Press Vest",1481,1,0,2},
	{"Police Vest",1744,1,0,1},
	{"Light Tactical Vest",1759,1,0,2.5},
	----------------------------
	{"Ghillie Helmet",1759,1,0,2.5},
	{"Helmet",1759,1,0,2.5},
	{"Helmet ONU",1759,1,0,2.5},
	
  },
  bmpcrashsides = {
	{"M4A1",356,1,90,3},
	{"AK-74 GP-25",356,1,90,3},
	{"Steyr Aug",356,1,90,3},
	{"M4A1 CCO",356,1,90,3},
	{"AKS Gold",356,1,90,3},
	{"AKS-74 Kobra",356,1,90,3},
	{"M4A1 CCO SD",356,1,90,3},
	{"FN SCAR",356,1,90,2},
	{"Balanced Vest",1800,1,0,1},
	{"FN SCAR SD",356,1,90,2},
	{"Helmet",1759,1,0,2.5},
	{"Helmet ONU",1759,1,0,2.5},
	{"Light Tactical Vest",1759,1,0,2.5},
	
  },    
  hospital = {
	{"Syringe",2000,1,0},
	{"Antibiotics",1919,2.1,0},
	{"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},
	{"Morphine Auto-Injector",14673,1,0},
	{"Blood Bag",1580,1,0},
	{"Medic Kit",2891,0.7,0},
	{"Blood Bag",1580,1,0},
	{"Painkiller",1580,1,0}
  }
}

for i,bpData in pairs(BackpacksTable)do
  table.insert(lootItems.helicrashsides,{bpData[1],bpData[3],1,0,bpData[4][5]})
end

for i,bpData in pairs(BackpacksTable)do
  table.insert(lootItems.bmpcrashsides,{bpData[1],bpData[3],1,0,bpData[4][5]})
end

--*************** NEW Helicrash *******************--
function createHeliCrashSite()
  if cargoCol then
	destroyElement(getElementData(cargoCol,"parent"))
	destroyElement(getElementData(cargoCol,"smoke"))
	destroyElement(cargoCol)
  end
  local item_id = math.random(#vehSpawns["heliCrash"])
  local x,y,z = vehSpawns["heliCrash"][item_id][1],vehSpawns["heliCrash"][item_id][2],vehSpawns["heliCrash"][item_id][3]
  smoke = createObject ( 1946, x, y, z - 1, 0, 0, 90 )  
  cargobob = createObject ( 1945, x, y, z - 1, 0, 0, 90 )
  blowVehicle(cargobob)
  outputChatBox("Spawn Helicrash",getRootElement(),255,255,255,true)
  setElementFrozen(cargobob,true)
  cargoCol = createColSphere(x,y,z,3)
  setElementData(cargoCol,"smoke",smoke)
  setElementData(cargoCol,"parent",cargobob)
  setElementData(cargoCol,"helicrash",true)
  setElementData(cargoCol,"MAX_Slots",0)
  for i,item in ipairs(lootItems.helicrashsides)do
	local value = math.percentChance(item[5] * 3.5,math.random(1,2))
	setElementData(cargoCol,item[1],value)
	local ammoData,weapID = getWeaponAmmoType(item[1])
	if ammoData ~= item[1] then
	  if ammoData and value > 0 then
		minBullets,maxBullets = math.floor(getAmmoPlus(ammoData)/3),getAmmoPlus(ammoData)*2
		ammoQuantity = math.random(minBullets,maxBullets)
		setElementData(cargoCol,ammoData,ammoQuantity)
	  end
	end
  end
  setTimer(createHeliCrashSite,3600000,1)
end
createHeliCrashSite()
--*************** NEW BMPCrash *******************--
function createBMPCrashSite()
  if cargoCol then
	destroyElement(getElementData(cargoCol,"parent"))
	destroyElement(getElementData(cargoCol,"smoke"))
	destroyElement(cargoCol)
  end
  local item_id = math.random(#vehSpawns["BMPCrash"])
  local x,y,z = vehSpawns["BMPCrash"][item_id][1],vehSpawns["BMPCrash"][item_id][2],vehSpawns["BMPCrash"][item_id][3]
  smoke = createObject ( 1946, x, y, z - 1, 0, 0, 90 )  
  cargobob = createObject ( 1944, x, y, z - 1, 0, 0, 90 )
  blowVehicle(cargobob)
  outputChatBox("Spawn BMPCrash",getRootElement(),255,255,255,true)
  setElementFrozen(cargobob,true)
  cargoCol = createColSphere(x,y,z,3)
  setElementData(cargoCol,"smoke",smoke)
  setElementData(cargoCol,"parent",cargobob)
  setElementData(cargoCol,"BMPCrash",true)
  setElementData(cargoCol,"MAX_Slots",0)
  for i,item in ipairs(lootItems.bmpcrashsides)do
	local value = math.percentChance(item[5] * 3.5,math.random(1,2))
	setElementData(cargoCol,item[1],value)
	local ammoData,weapID = getWeaponAmmoType(item[1])
	if ammoData ~= item[1] then
	  if ammoData and value > 0 then
		minBullets,maxBullets = math.floor(getAmmoPlus(ammoData)/3),getAmmoPlus(ammoData)*2
		ammoQuantity = math.random(minBullets,maxBullets)
		setElementData(cargoCol,ammoData,ammoQuantity)
	  end
	end
  end
  setTimer(createBMPCrashSite,1800000,1)
end
createBMPCrashSite()
---------------------------------------------
function updateHospitals()
  for i,box in pairs(hospitalCol)do
	for _,items in ipairs(lootItems.hospital)do
	  setElementData(hospitalCol[i],items[1],math.random(1,5))
	end
  end
  setTimer(updateHospitals,3600000,1)
end
hospitalCol = {}
function createHospitalPacks()
  number1 = 0
  for i,box in ipairs(hospitalPacks)do
	number1 = number1 + 1
	local x,y,z = box[1],box[2],box[3]
	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)
	for _,items in ipairs(lootItems.hospital)do
	  local randomNumber = math.random(1,10)
	  if randomNumber >= 2 then
		setElementData(hospitalCol[i],items[1],math.random(1,5))
	  end
	end
  end
  setTimer(updateHospitals,3600000,1)
end
createHospitalPacks()

patrolCol = {}
for num,patrol in ipairs(patrolPoints) do
  local x,y,z = patrol[1],patrol[2],patrol[3]
  patrolCol[num] = createColSphere(x,y,z,3)
  setElementData(patrolCol[num],"patrolstation",true)
  local rand = math.random(1,15)
  if rand == 1 then
	lts = 100
  elseif rand == 2 or rand == 3 then
	lts = 80
  elseif rand >= 4 or rand <= 6 then
	lts = 60
  elseif rand >= 7 or rand <= 10 then
	lts = 40
  else
	lts = 20
  end
  setElementData(patrolCol[num],"patrollts",lts)
end

function updatepatrol()
  for i,box in pairs(patrolCol) do
	local rand = math.random(1,15)
	if rand == 1 then
	  lts = 100
	elseif rand == 2 or rand == 3 then
	  lts = 80
	elseif rand >= 4 or rand <= 6 then
	  lts = 60
	elseif rand >= 7 or rand <= 10 then
	  lts = 40
	else
	  lts = 20
	end
	setElementData(patrolCol[i],"patrollts",lts)
  end
end
setTimer(updatepatrol,10800000,0)

spawnedVehs = {}
function isVehSpawned(num)
  for _, numm in pairs(spawnedVehs)do
	if numm == num then
	  return true
	end
  end
  return false
end

function spawnDayZVehicles()
  for i,vehs in pairs(vehiclesTable)do
	spawnedVehs = {}
	count = math.random(0,#vehSpawns[vehs[1]])
	for i=1,count do
	  num = math.random(1,#vehSpawns[vehs[1]])
	  if not isVehSpawned(num) then
		table.insert(spawnedVehs,num)
		x,y,z = vehSpawns[vehs[1]][num][1],vehSpawns[vehs[1]][num][2],vehSpawns[vehs[1]][num][3]
		veh = createVehicle(vehs[2],x,y,z)
		vehCol = createColSphere(x,y,z,4)
		attachElements(vehCol,veh,0,0,0)
		setElementData(vehCol,"parent",veh)
		setElementData(veh,"parent",vehCol)
		setElementData(vehCol,"vehicle",true)
		setElementData(vehCol,"MAX_Slots",vehs[8])
		engRand = math.random(0,vehs[3])
		tireRand = math.random(0,vehs[4])
		partRand = math.random(0,vehs[5])
		rotorRand = math.random(0,vehs[6])
		glaRand = math.random(0,vehs[7])
		setElementData(vehCol,"Engine_inVehicle",engRand)
		setElementData(vehCol,"Tire_inVehicle",tireRand)
		setElementData(vehCol,"Parts_inVehicle",partRand)
		setElementData(vehCol,"Rotor_inVehicle",rotorRand)
		setElementData(vehCol,"Glass_inVehicle",glaRand)
		setElementData(vehCol,"spawn",{vehs[2],x,y,z})
		setElementData(vehCol,"fuel",10)
		setElementData(vehCol,"ProtectionPercent",0)
		setElementData(vehCol,"maxfuel",vehs[9])
		setElementData(vehCol,"needengines",vehs[3])
		setElementData(vehCol,"needtires",vehs[4])
		setElementData(vehCol,"needparts",vehs[5])
		setElementData(vehCol,"needrotor",vehs[6])
		setElementData(vehCol,"needglass",vehs[7])
		if tireRand >= 1 then
		  setElementData(vehCol,"TireState",math.random(0,100))
		else
		  setElementData(vehCol,"TireState",100)
		end
		if engRand >= 1 then
		  setElementData(vehCol,"EngineState",math.random(0,100))
		else
		  setElementData(vehCol,"EngineState",100)
		end
		if rotorRand >= 1 then
		  setElementData(vehCol,"RotorState",math.random(0,100))
		else
		  setElementData(vehCol,"RotorState",100)
		end
		if partRand >= 1 then
		  setElementData(vehCol,"PartsState",math.random(0,100))
		else
		  setElementData(vehCol,"PartsState",100)
		end
	  end
	end
  end
end

function notifyAboutExplosion()
  occupants = getVehicleOccupants(source) or {}
  for _,peds in pairs(occupants)do
	removePedFromVehicle(peds)
  end
  local col = getElementData(source,"parent")
  if col and getElementData(col,"helicrash") then return end
  id,x,y,z = getElementData(col,"spawn")[1],getElementData(col,"spawn")[2],getElementData(col,"spawn")[3],getElementData(col,"spawn")[4]
  setTimer(respawnDayZVehicle,120000,1,id,x,y,z,source,col)
  setElementData(col,"deadVehicle",true)
  setElementData(source,"isExploded",true)
  x1,y1,z1 = getElementPosition(source)
  createExplosion(x1+1,y1+1,z1,4)
  createExplosion(x1-1,y1-1,z1,4)
  createExplosion(x1+1,y1-1,z1,4)
  createExplosion(x1-1,y1+1,z1,4)
end
addEventHandler("onVehicleExplode",getRootElement(),notifyAboutExplosion)

function respawnVehiclesInWater(vehiclesInWater)
  for i,veh in ipairs(getElementsByType("vehicle"))do
	if isElementInWater(veh) and getVehicleType(veh) ~= "Boat" then
	  local col = getElementData(veh,"parent")
	  id,x,y,z = getElementData(col,"spawn")[1],getElementData(col,"spawn")[2],getElementData(col,"spawn")[3],getElementData(col,"spawn")[4]
	  respawnDayZVehicle(id,x,y,z,veh,col)
	end
  end
end
setTimer(respawnVehiclesInWater,120000,0)

function respawnDayZVehicle(id,x,y,z,veh,col)
  destroyElement(veh)
  destroyElement(col)
  local engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(id)
  veh = createVehicle(id,x,y,z)
  vehCol = createColSphere(x,y,z,4)
  attachElements(vehCol,veh,0,0,0)
  setElementData(vehCol,"parent",veh)
  setElementData(veh,"parent",vehCol)
  setElementData(vehCol,"vehicle",true)
  setElementData(vehCol,"MAX_Slots",slots)
  engRand = math.random(0,engine)
  tireRand = math.random(0,tires)
  partRand = math.random(0,parts)
  rotorRand = math.random(0,rotor)
  glaRand = math.random(0,glass)
  setElementData(vehCol,"Engine_inVehicle",engRand)
  setElementData(vehCol,"Tire_inVehicle",tireRand)
  setElementData(vehCol,"Parts_inVehicle",partRand)
  setElementData(vehCol,"Rotor_inVehicle",rotorRand)
  setElementData(vehCol,"Glass_inVehicle",glaRand)
  setElementData(vehCol,"spawn",{id,x,y,z})
  setElementData(vehCol,"fuel",10)
  setElementData(vehCol,"ProtectionPercent",0)
  setElementData(vehCol,"maxfuel",fuel)
  setElementData(vehCol,"needengines",engine)
  setElementData(vehCol,"needtires",tires)
  setElementData(vehCol,"needparts",parts)
  setElementData(vehCol,"needrotor",rotor)
  setElementData(vehCol,"needglass",glass)
  if tireRand >= 1 then
	setElementData(vehCol,"TireState",math.random(0,100))
  else
	setElementData(vehCol,"TireState",100)
  end
  if engRand >= 1 then
	setElementData(vehCol,"EngineState",math.random(0,100))
  else
	setElementData(vehCol,"EngineState",100)
  end
  if rotorRand >= 1 then
	setElementData(vehCol,"RotorState",math.random(0,100))
  else
	setElementData(vehCol,"RotorState",100)
  end
  if partRand >= 1 then
	setElementData(vehCol,"PartsState",math.random(0,100))
  else
	setElementData(vehCol,"PartsState",100)
	local randomNumber = math.random(1,10)
	if randomNumber == 5 then
	  setElementData(vehCol,items[1],1)
	end
  end
end

function spawnVehiclePack(ps,cmd)
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(ps)),aclGetGroup("Console")) then
	spawnDayZVehicles()
	outputChatBox("Vehicles has been spawned!",ps,255,0,0,true)
  end
end
addCommandHandler("svp",spawnVehiclePack)

function onPlayerEnterDayzVehicle(veh,seat)
  if seat == 0 then
	setVehicleEngineState(veh,false)
	outputChatBox("Press 'K' to turn the engine on/off!",source,255,255,255)
  end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),onPlayerEnterDayzVehicle)

function onPlayerExitDayzVehicle(veh,seat)
  if seat == 0 then
	setVehicleEngineState(veh,false)
  end
end
addEventHandler("onPlayerVehicleExit",getRootElement(),onPlayerExitDayzVehicle)

function getVehicleFuelRemove(veh,col)
  engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(getElementModel(veh))
  partstate = getElementData(col,"PartsState")
  if partstate < 10 then
	damaged = 2.3
  elseif partstate < 20 then
	damaged = 2
  elseif partstate < 40 then
	damaged = 1.7
  elseif partstate < 60 then
	damaged = 1.4
  elseif partstate < 80 then
	damaged = 1.1
  else
	damaged = 1
  end
  if getElementData(col,"Parts_inVehicle") == 0 then
	return fuelpm * 2.5
  else
	return fuelpm * damaged
  end
end

function setVehiclesFuelPerMinute()
  for i,veh in ipairs(getElementsByType("vehicle"))do
	if getVehicleEngineState(veh)== true then
	  vehCol = getElementData(veh,"parent")
	  if getElementData(vehCol,"fuel")>= 0 then
		setElementData(vehCol,"fuel",getElementData(vehCol,"fuel")- getVehicleFuelRemove(veh,vehCol))
	  else
		setVehicleEngineState(veh,false)
	  end
	end
  end
end
setTimer(setVehiclesFuelPerMinute,20000,0)

repairTimer = {}
function repairVehicle(veh)
  if repairTimer[veh] then
	triggerClientEvent(source,"displayClientInfo",source,"Vehicle",getVehicleName(veh).." is currently being repaired!",255,22,0)
	return
  end
  local health = math.floor(getElementHealth(veh))
  repairTimer[veh] = setTimer(fixVehicleDayZ,(1000 - health)*120,1,veh,source)
  setElementFrozen(veh,true)
  setElementData(veh,"repairer",source)
  setElementData(source,"repairingvehicle",veh)
  setPedAnimation(source,"SCRATCHING","sclng_r",-1,true,false)
  triggerClientEvent(source,"displayClientInfo",source,"Vehicle","You started to repair "..getVehicleName(veh),22,255,0)
end
addEvent("repairVehicle",true)
addEventHandler("repairVehicle",getRootElement(),repairVehicle)

function fixVehicleDayZ(veh,player)
  local FL,RL,FR,RR = getVehicleWheelStates(veh)
  setElementHealth(veh,1000)
  fixVehicle(veh)
  setVehicleWheelStates(veh,FL,RL,FR,RR)
  setPedAnimation(player,false)
  setElementFrozen(veh,false)
  repairTimer[veh] = nil
  setElementData(veh,"repairer",nil)
  setElementData(player,"repairingvehicle",nil)
  triggerClientEvent(player,"displayClientInfo",player,"Vehicle","You finished repairing "..getVehicleName(veh),22,255,0)
end

function stopFixxingWhileMoving()
  local veh = getElementData(source,"repairingvehicle")
  setPedAnimation(source)
  setElementFrozen(veh,false)
  setElementData(veh,"repairer",nil)
  setElementData(source,"repairingvehicle",nil)
  triggerClientEvent(source,"displayClientInfo",source,"Vehicle","You stopped repairing "..getVehicleName(veh),255,22,0)
  killTimer(repairTimer[veh])
  repairTimer[veh] = nil
end
addEvent("onClientMovesWhileAnimation",true)
addEventHandler("onClientMovesWhileAnimation",getRootElement(),stopFixxingWhileMoving)

function debugFixxing()
  for i,veh in ipairs(getElementsByType("vehicle"))do
	if getElementData(veh,"repairer")== source then
	  outputDebugString("Vehicle repairer disconnected - destroyed tables")
	  killTimer(repairTimer[veh])
	  setElementFrozen(veh,false)
	  repairTimer[veh] = nil
	  setElementData(veh,"repairer",nil)
	end
  end
end
addEventHandler("onPlayerQuit",getRootElement(),debugFixxing)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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