Jump to content

Duvida sobre carregamento de tendas e veiculos


Recommended Posts

Boa noite, estou com um seguinte problema, estou configurando um backup de tendas e veiculos para um servidor de dayz, a função dele é salvar toda as tendas e veículos do servidor, vc digita um comando e ele salva, vc digita outro comando e ele carrega, porém se caso houver uma queda no servidor, ele está programado para salvar as tendas, porém ao servidor reiniciar, as tendas não carregam sozinhas, o mesmo para veículos, eu tenho que digitar o comando para poder carregar, e eu queria colocar para que quando o servidor iniciasse novamente, carregasse sem precisar digitar o comando

eu adicionei uma linha para dar carregamento ao dar start na resource, porém não acontece nada, e da o seguinte erro:

 

[2020-02-05 01:14:18] WARNING: BACKUP\backup.Lua:345: Bad argument @ 'dbPoll' [Expected db-query at argument 1, got resource-data]
[2020-02-05 01:14:18] BACKUP restarted successfully
[2020-02-05 01:14:24] ERROR: BACKUP\backup.Lua:346: attempt to get length of local 'p' (a boolean value)

--## Copyright (c) 2015 Grosu `PoWeR` Mihaita.
--## MTA:DayZ Backup System v1.5.

local dbType = "SQLite";  --Here set your db type, "MySQL" or "SQLite" <!>
local dbName = "";        --Your database name <!>
local dbHost = "";		  --Your hostname/IP <!>
local dbUser = "";		  --Username for database <!>
local dbPass = "";		  --Password for database <!>
local dbPort = 1234; 	  --This is an port exemple CHANGE IT <!>

local last_veh_id = 0;	  --Don't edit here <!>
local last_tent_id = 0;   --Don't edit here <!>

local itemsDataTable = { -- If your server have different items be sure you imported your item table here!
	{"M4A1"},
{"M4A1 CCO"},
{"M4A1 CCO SD"},
{"Sa-58P"},
{"Sa-58P CCO"},
{"M4A3 CCO"},
{"M16A4 ACOG"},
{"G36C (Camo)"},
{"M16A2"},
{"FN FAL"},
{"AKS-74U"},
{"AKS (Gold)"},
{"MG36"},
{"Bizon PP-19 SD"},
{"AK-107"},
{"AK-107 GL"},
{"AK-74"},
{"G36C"},
{"Gorro Noel"},
{"G36C SD"},
{"AKS-74 Kobra"},
{"AKM"},
{"RPK"},
{"CZ 550"},
{"SVD CAMO"},
{"M40A3"},
{"DMR"},
{"M24"},
{"M107"},
{"AS50"},
{"KSVK"},
{"Cheytac M200"},
{"M249 SAW"},
{"Mk 48 Mod 0"},
{"M240"},
{"PKM"},
{"PKP"},
{"Double-Barreled Shotgun"},
{"M1014"},
{"Remington 870"},
{"Winchester 1866"},
{"Sawn-Off Shotgun"},
{"PDW"},
{"MP5A5"},
{"MP5SD6"},
{"Machete"},
{"Hatchet"},
{"Crowbar"},
{"Shovel"},
{"Makarov PM"},
{"Makarov SD"},
{"G17"},
{"M1911"},
{"M9"},
{"M9 SD"},
{"Revolver"},
{"Balanced Vest"},
{"Press Vest"},
{"Police Vest"},
{"Light Tactical Vest"},
{"Balistic Vest"},
{"UK Assalt Vest DPM Camo"},
{"UK Assalt Vest DPM Black"},
{"Balistic Plus Vest"},
{"Helmet"},
{"Mossy Helmet"},
{"UN Helmet"},
{"Gorro Noel"},
{"Aviator Helmet"},
{"Gas Mask 1"},
{"Gas Mask 2"},
{"Motorbike Helmet 1"},
{"Motorbike Helmet 2"},
{"Motorbike Helmet 3"},
{"Motorbike Helmet 4"},
{"Skate Helmet"},
{"Tanker Helmet"},
{"Welding Helmet 1"},
{"Welding Helmet 2"},
{"Smersh Backpack"},
{"Courier Bag"},
{"Child Briefcase"},
{"Improvised Backpack"},
{"Assault Pack (ACU)"},
{"Alice Pack"},
{"British Assault Pack"},
{"Taloon Backpack"},
{"Omega Backpack"},
{"Alfa Backpack"},
{"Hunting Backpack"},
{"Camping Backpack"},
{"Drybag Backpack"},
{"Mountain Backpack"},
{"Czech Backpack"},
{"Camping Tactical Backpack"},
{"Coyote Backpack"},
{"Coyote Backpack (Desert)"},
{"Coyote Backpack (Mossy)"},
{"Tactical Backpack"},
{"Eskimo Backpack"},
{"Tiger Backpack"},
{"Noel Backpack"},
{"Canned Spaghetti (Fechado)"},
{"Canned Spaghetti (Aberto)"},
{"Canned Baked Beans (Fechado)"},
{"Canned Baked Beans (Aberto)"},
{"Canned Sardines (Fechado)"},
{"Canned Sardines (Aberto)"},
{"Can of Tactical Bacon (Fechado)"},
{"Can of Tactical Bacon (Aberto)"},
{"Water Bottle"},
{"Burger"},
{"Pizza"},
{"Soda Bottle"},
{"Milk"},
{"Cooked Meat"},
{"Raw Meat"},
{"Antibiotics"},
{"Bandage"},
{"Medic Kit"},
{"Heat Pack"},
{"Painkiller"},
{"Blood Bag"},
{"Morphine"},
{"Engine"},
{"Tire"},
{"Tank Parts"},
{"Scrap Metal"},
{"Steel Sheet"},
{"Empty Gas Canister"},
{"Full Gas Canister"},
{"Stinger"},
{"Wood Pile"},
{"Roadflare"},
{"Wire Fence"},
{"Tent"},
{"Empty Water Bottle"},
{"Empty Soda Cans"},
{"Night Vision Goggles"},
{"Infrared Goggles"},
{"Map"},
{"Box of Matches"},
{"Watch"},
{"GPS"},
{"Toolbox"},
{"Radio Device"},
{"Syringe"},
{"Opener"},
{"Hose"},
{"Tire Repair Kit"},
{"Compass"},
-------
{"30Rnd. STANAG"},
{"FN FAL Mag."},
{"G36 Mag"},
{"30Rnd. AK"},
{"CZ 550 Mag."},
{"SVD Mag."},
{"M24 Mag."},
{"DMR Mag."},
{"10Rnd. M107"},
{"5Rnd. KSVK"},
{"5Rnd. Cheytac M200"},
{"100Rnd. M249 SAW"},
{"100Rnd. M240."},
{"PKM Mag."},
{"2Rnd. Slug"},
{"Bizon Mag"},
{"MG36 Mag."},
{"M1014 Slug"},
{"1866 Slug"},
{"PDW Mag"},
{"AKM Mag."},
{"5Rnd 12.7x99mm NATO"},
{"Sa-58 Mag."},
{"MP5 Mag"},
{"Grenade"},
{"Tear Gas"},
{"Binoculars"},
{"Parachute"},
{"Makarov Mag"},
{"G17 Mag"},
{"M1911 Mag"},
{"M9 Mag"},
{".45 ACP"}
};

function noteAdmins(theAlert)
	for _,v in ipairs(getElementsByType("player")) do
		if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(v)), aclGetGroup("Admin"))) then
			outputChatBox("#FF0000[Backup]: #FFFFFF"..tostring(theAlert), v, 255, 255, 255,  true);
		end
	end
end

if (dbType == "MySQL") then
	db = dbConnect("mysql", "dbname="..dbName..";host="..dbHost..";port="..dbPort, dbUser, dbPass, "share=1");
	dbExec(db, "CREATE TABLE IF NOT EXISTS vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, receiver, armorPoints, armorPointsMax, engines, moving, parts, items, id)");
	dbExec(db, "CREATE TABLE IF NOT EXISTS tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
	noteAdmins("Database connected to MySQL!");
elseif (dbType == "SQLite") then
	db = dbConnect("sqlite", "database.db");
	dbExec(db, "CREATE TABLE IF NOT EXISTS vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, receiver, armorPoints, armorPointsMax, engines, moving, parts, items, id)");
	dbExec(db, "CREATE TABLE IF NOT EXISTS tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id)");
	noteAdmins("Database connected to SQLite!");
else
	noteAdmins("Error: `dbType` wrong attribute!");
	return false;
end

function backup_vehs()
	dbExec(db, "DELETE FROM vehicles");
	local vehicleCounter = 0;
	for _,veh in ipairs(getElementsByType("vehicle")) do
		if (not getElementData(veh, "helicrash") and not getElementData(veh, "deadVehicle")) then
			local col = getElementData(veh, "parent");
			if (col and getElementType(col) == "colshape") then
				local model = getElementModel(veh);
				local x, y, z = getElementPosition(veh);
				local rX, rY, rZ = getElementRotation(veh);
				local slots = getElementData(col, "MAX_Slots") or 20;
				local fuel = getElementData(col, "fuel") or 0;
				
				local moving = getElementData(col, "Tire_inVehicle") or 0;
				local engines = getElementData(col, "Engine_inVehicle") or 0;
				local parts = getElementData(col, "Parts_inVehicle") or 0;
				
				local siren = getElementData(col, "Sirene_inVehicle") or 0;
				local receiver = getElementData(col, "receiver") or 0;
				local armorPointsMax = getElementData(col, "armorPointsMax") or 0;
				local armorPoints = getElementData(col, "armorPoints") or 0;
				
				local items = {};
				vehicleCounter = vehicleCounter + 1;
				for _,v in ipairs(itemsDataTable) do
					local quantity = getElementData(col, v[1]) or 0;
					if (quantity > 0) then
						table.insert(items, {v[1], quantity});
					end
				end
				dbExec(db, "INSERT INTO vehicles(model, x, y, z, rX, rY, rZ, slots, fuel, engines, receiver, armorPoints, armorPointsMax, moving, parts, items, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rX, rY, rZ, slots, fuel, engines, receiver, armorPoints, armorPointsMax, moving, parts, toJSON(items), vehicleCounter)
			end
		end
	end
	noteAdmins("Vehicles saved ["..vehicleCounter.."]");
end

function backup_tents()
	dbExec(db, "DELETE FROM tents");
	local tentsCounter = 0;
	for _,col in ipairs(getElementsByType("colshape")) do
		if (getElementData(col, "tent")) then
			local tent = getElementData(col, "parent");
			local x, y, z = getElementPosition(tent);
			local rX, rY, rZ = getElementRotation(tent);
			local model = getElementModel(tent);
			local slots = getElementData(col, "MAX_Slots") or 300;
			local scale = getObjectScale(tent);
			local items = {};
			tentsCounter = tentsCounter + 1;
			for _,v in ipairs(itemsDataTable) do
				local quantity = getElementData(col, v[1]) or 0;
				if (quantity > 0) then
					table.insert(items, {v[1], quantity});
				end
			end
			dbExec(db, "INSERT INTO tents(model, x, y, z, rX, rY, rZ, slots, scale, items, id) VALUES(?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rX, rY, rZ, slots, scale, toJSON(items), tentsCounter)
		end
	end
	noteAdmins("Tendas Salvas ["..tentsCounter.."]");
end
addEventHandler("onResourceStop",getResourceRootElement(),backup_tents)
setTimer(backup_tents,5999000,0)

function create_veh(model, x, y, z, rX, rY, rZ, slots, fuel, receiver, armorPoints, armorPointsMax, engines, moving, parts, items, id)
	local veh = createVehicle(model, x, y, z);
	local vehCol = createColSphere(x, y, z, 2);
	setElementRotation(veh, rX, rY, rZ);
	attachElements(vehCol, veh, 0, 0, 0);
	setElementData(vehCol, "parent", veh);
	setElementData(veh, "parent", vehCol);
	setElementData(vehCol, "vehicle", true);
	setElementData(vehCol, "MAX_Slots", tonumber(slots));
	setElementData(vehCol, "Tire_inVehicle", tonumber(moving));
	setElementData(vehCol, "Engine_inVehicle", tonumber(engines));
	setElementData(vehCol, "Parts_inVehicle", tonumber(parts));
	setElementData(vehCol, "spawn", {model, x, y, z});
	setElementData(vehCol, "fuel", tonumber(fuel));
	setElementData(vehCol, "receiver", tonumber(receiver));
	setElementData(vehCol, "armorPointsMax", tonumber(armorPointsMax));
	setElementData(vehCol, "armorPoints", tonumber(armorPoints));
	
	
	for _,v in ipairs(fromJSON(items)) do
		setElementData(vehCol, v[1], v[2]);
	end
end

function create_tent(model, x, y, z, rX, rY, rZ, slots, scale, items, id)
	local tent = createObject(model, x, y, z);
	local tentCol = createColSphere(x, y, z,  3);
	setElementRotation(tent, rX, rY, rZ);
	setObjectScale(tent, scale);
	attachElements(tentCol, tent, 0, 0, 0);
	setElementData(tentCol, "parent", tent);
	setElementData(tent, "parent", tentCol);
	setElementData(tentCol, "tent", true);
	setElementData(tentCol, "vehicle", true);
	setElementData(tentCol, "MAX_Slots", slots);
	setElementData(tentCol,"visible",true)
	for _,v in ipairs(fromJSON(items)) do
		setElementData(tentCol, v[1], v[2]);
	end
end

function load_vehs(q)
	if (q) then
		local p = dbPoll(q, 0);
		if (#p > 0) then
			for _,d in pairs(p) do
				last_veh_id = d["id"];
				create_veh(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["fuel"],d["receiver"], d["armorPoints"], d["armorPointsMax"], d["engines"], d["moving"], d["parts"], d["items"], d["id"]);
			end
		end
	end
	noteAdmins("Veiculos Carregados!");
end

function load_tents(q)
	if (q) then
		local p = dbPoll(q, 0);
		if (#p > 0) then
			for _,d in pairs(p) do
				last_tent_id = d["id"];
				create_tent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"], d["id"]);
			end
		end
	end 
	noteAdmins("Tendas Carregadas!");
end
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),load_tents)  ----- linha que eu adicionei para carregar as tendas

addEventHandler("onPlayerCommand", root, function(cmd)
	if (isObjectInACLGroup("user."..getAccountName(getPlayerAccount(source)), aclGetGroup("Admin"))) then
		if (cmd == "loadtent") then --carregar tendas
			dbQuery(load_tents, {}, db, "SELECT * FROM `tents`");
		elseif (cmd == "loadcar") then --carregar veiculos
			dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`");
		elseif (cmd == "savecar") then --salvar veiculos
			backup_vehs();
		elseif (cmd == "savetent") then -- salvar tendas
			backup_tents();
		elseif (cmd == "backup") then --start stop backup  a cada 30 minutos
			if (isTimer(vehbkTimer) and isTimer(tentbkTimer)) then
				killTimer(vehbkTimer);
				killTimer(tentbkTimer);
				noteAdmins(getPlayerName(source).."#FFFFFF Backup Automatico Parado!");
			else
				vehbkTimer = setTimer(backup_vehs, 30*60000, 0);
				tentbkTimer = setTimer(backup_tents, 30*60000, 0);
				noteAdmins(getPlayerName(source).."#FFFFFF Backup Automatico Iniciado!");
			end
		end
	end
end);

 

Link to comment

Tente isso :

  • Cole está função abaixo da função loads_tents.
function  start_resource ()
   dbQuery(load_tents, {}, db, "SELECT * FROM `tents`")
   dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`")
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start_resource) 
  • Apenas exemplo Demostrativo de onde colocar : 
function load_vehs(q)
	if (q) then
		local p = dbPoll(q, 0);
		if (#p > 0) then
			for _,d in pairs(p) do
				last_veh_id = d["id"];
				create_veh(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["fuel"],d["receiver"], d["armorPoints"], d["armorPointsMax"], d["engines"], d["moving"], d["parts"], d["items"], d["id"]);
			end
		end
	end
	noteAdmins("Veiculos Carregados!");
end

function load_tents(q)
	if (q) then
		local p = dbPoll(q, 0);
		if (#p > 0) then
			for _,d in pairs(p) do
				last_tent_id = d["id"];
				create_tent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"], d["id"]);
			end
		end
	end 
	noteAdmins("Tendas Carregadas!");
end

function  start_resource ()  --/> AQUI
      dbQuery(load_tents, {}, db, "SELECT * FROM `tents`") --/> AQUI
      dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`") --/> AQUI
end --/> AQUI
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start_resource) --/> AQUI

 

Edited by Angelo Pereira
Link to comment
14 hours ago, Angelo Pereira said:

Tente isso :

  • Cole está função abaixo da função loads_tents.

function  start_resource ()   dbQuery(load_tents, {}, db, "SELECT * FROM `tents`")   dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`")endaddEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start_resource) 
  • Apenas exemplo Demostrativo de onde colocar : 

function load_vehs(q)	if (q) then		local p = dbPoll(q, 0);		if (#p > 0) then			for _,d in pairs(p) do				last_veh_id = d["id"];				create_veh(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["fuel"],d["receiver"], d["armorPoints"], d["armorPointsMax"], d["engines"], d["moving"], d["parts"], d["items"], d["id"]);			end		end	end	noteAdmins("Veiculos Carregados!");endfunction load_tents(q)	if (q) then		local p = dbPoll(q, 0);		if (#p > 0) then			for _,d in pairs(p) do				last_tent_id = d["id"];				create_tent(d["model"], d["x"], d["y"], d["z"], d["rX"], d["rY"], d["rZ"], d["slots"], d["scale"], d["items"], d["id"]);			end		end	end 	noteAdmins("Tendas Carregadas!");endfunction  start_resource ()  --/> AQUI      dbQuery(load_tents, {}, db, "SELECT * FROM `tents`") --/> AQUI      dbQuery(load_vehs, {}, db, "SELECT * FROM `vehicles`") --/> AQUIend --/> AQUIaddEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start_resource) --/> AQUI

 

Testei e deu certo, muito obrigado !!

acho que por ser db não funciona apenas se adicionar o AddEventHandler, mas valeu mano

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...