Narutimmy Posted June 30, 2015 Share Posted June 30, 2015 Hola tengo un problemin esto es de un sistema de guardado de autos junto a unas data que se guardan en ellos, el problema es qe no las guardaba y aparte tomaba cordenadas nuevas asi que lo edite pero no estoy seguro que funcione. Antes: function backupAllVehZ() dbExec(db, "DROP TABLE vehicles") kk = dbQuery(db, "CREATE TABLE IF NOT EXISTS vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id)") dbFree ( kk ) local vehicles = getElementsByType("vehicle") id = 0 for i,v in ipairs(vehicles) do local CCOL = getElementData (v,"parent") if CCOL then local model = getElementModel(v) local x, y, z = getElementPosition(v) local rotx, roty, rotz = getElementRotation(v) local slots = getElementData(getElementData(v, "parent"), "MAX_Slots") or 20 local fuel = getElementData(getElementData(v, "parent"), "fuel") local tires = getElementData(getElementData(v, "parent"), "Tire_inVehicle") local engines = getElementData(getElementData(v, "parent"), "Engine_inVehicle") or 0 local parts = getElementData(getElementData(v, "parent"), "Parts_inVehicle") or 0 id = id + 1 sda = dbQuery(db, "INSERT INTO vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) dbFree ( sda ) end end noteAdmins("Vehicle backup done! ["..#vehicles.."]") end function createCars(model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) veh = createVehicle(model, x, y, z, rotx, roty, rotz) vehCol = createColSphere(x, y, z, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", tonumber(slots)) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) setElementData(vehCol, "Tire_inVehicle", tonumber(tires)) setElementData(vehCol, "Engine_inVehicle", tonumber(engines)) setElementData(vehCol, "Parts_inVehicle", tonumber(parts)) setElementData(vehCol, "spawn", {model, x, y, z}) setElementData(vehCol, "fuel", tonumber(fuel)) end Despues function backupAllVehZ() dbExec(db, "DROP TABLE vehicles") kk = dbQuery(db, "CREATE TABLE IF NOT EXISTS vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id)") dbFree ( kk ) local vehicles = getElementsByType("vehicle") id = 0 for i,v in ipairs(vehicles) do local CCOL = getElementData (v,"parent") local VIP = getElementData (v,"VIP") if CCOL then if not VIP then ---local model = getElementModel(v) local model, x, y, z = getElementData(v, "spawn")[1], getElementData(v, "spawn")[2], getElementData(v, "spawn")[3], getElementData(v, "spawn")[4] local rotx, roty, rotz = getElementRotation(v) local slots = getElementData(getElementData(v, "parent"), "MAX_Slots") or 20 local fuel = getElementData(getElementData(v, "parent"), "fuel") local tires = getElementData(getElementData(v, "parent"), "Tire_inVehicle") or 0 local engines = getElementData(getElementData(v, "parent"), "Engine_inVehicle") or 0 local parts = getElementData(getElementData(v, "parent"), "Parts_inVehicle") or 0 id = id + 1 sda = dbQuery(db, "INSERT INTO vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) dbFree ( sda ) end end end noteAdmins("Vehicle backup done! ["..#vehicles.."]") end function createCars(model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) veh = createVehicle(model, x, y, z, rotx, roty, rotz) vehCol = createColSphere(x, y, z, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", tonumber(slots)) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) setElementData(vehCol, "Tire_inVehicle", tonumber(tires)) setElementData(vehCol, "Engine_inVehicle", tonumber(engines)) setElementData(vehCol, "Parts_inVehicle", tonumber(parts)) setElementData(vehCol, "spawn", {model, x, y, z}) setElementData(vehCol, "fuel", tonumber(fuel)) end En pocas palabras lo que quiero es que cuando guarde se guarde lo del a data "spawn" y que al spawnearlo de vuelta se le sete esa data pero no con la posision donde se guardo sino la original, nose si me explico. ejemplo: Su Spawn es en el Punto A, el auto de mueve de lugar al Punto B, yo guardo la ubicacion para reiniciar el sv, entonces ahora el auto al iniciaro Spawnea en el punto B todo bien pero cuando explota se toma la data "spawn" entonces ahora cada que explota y reaparece spawnea en el punto B siempre. Lo que yo quiero es que al guardar se guarde el punto A y B, y que cuando yo lo restaure aparesca en B, pero al Explotar y reaparecer aparesca en A. EDIT; Bueno mientras editaba me lo entendi mejor y croe seria asi no? function backupAllVehZ() dbExec(db, "DROP TABLE vehicles") kk = dbQuery(db, "CREATE TABLE IF NOT EXISTS vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id)") dbFree ( kk ) local vehicles = getElementsByType("vehicle") id = 0 for i,v in ipairs(vehicles) do local CCOL = getElementData (v,"parent") local VIP = getElementData (v,"VIP") if CCOL then if not VIP then ---local model = getElementModel(v) local model, x, y, z = getElementData(v, "spawn")[1], getElementData(v, "spawn")[2], getElementData(v, "spawn")[3], getElementData(v, "spawn")[4] local x2,y2,z2 = getElementPosition(v) local rotx, roty, rotz = getElementRotation(v) local slots = getElementData(getElementData(v, "parent"), "MAX_Slots") or 20 local fuel = getElementData(getElementData(v, "parent"), "fuel") local tires = getElementData(getElementData(v, "parent"), "Tire_inVehicle") or 0 local engines = getElementData(getElementData(v, "parent"), "Engine_inVehicle") or 0 local parts = getElementData(getElementData(v, "parent"), "Parts_inVehicle") or 0 id = id + 1 sda = dbQuery(db, "INSERT INTO vehicles (model, x, y, z,x2,y2,z2, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) dbFree ( sda ) end end end noteAdmins("Vehicle backup done! ["..#vehicles.."]") end function createCars(model, x, y, z,x2,y2,z2 rotx, roty, rotz, slots, fuel, tires, engines, parts, id) veh = createVehicle(model, x2, y2, z2, rotx, roty, rotz) vehCol = createColSphere(x2, y2, z2, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", tonumber(slots)) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) setElementData(vehCol, "Tire_inVehicle", tonumber(tires)) setElementData(vehCol, "Engine_inVehicle", tonumber(engines)) setElementData(vehCol, "Parts_inVehicle", tonumber(parts)) setElementData(vehCol, "spawn", {model, x, y, z}) setElementData(vehCol, "fuel", tonumber(fuel)) end EDIT me tira bolean en el : local model, x, y, z = getElementData(v, "spawn")[1], getElementData(v, "spawn")[2], getElementData(v, "spawn")[3], getElementData(v, "spawn")[4] Link to comment
Sasu Posted June 30, 2015 Share Posted June 30, 2015 No sé si se pueden guardar tablas con la función setElementData, pero puedes transformarlo al formato JSON, así: function backupAllVehZ() dbExec(db, "DROP TABLE vehicles") kk = dbQuery(db, "CREATE TABLE IF NOT EXISTS vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id)") dbFree ( kk ) local vehicles = getElementsByType("vehicle") id = 0 for i,v in ipairs(vehicles) do local CCOL = getElementData (v,"parent") local VIP = getElementData (v,"VIP") if CCOL then if not VIP then ---local model = getElementModel(v) --local model, x, y, z = getElementData(v, "spawn")[1], getElementData(v, "spawn")[2], getElementData(v, "spawn")[3], getElementData(v, "spawn")[4] local model, x, y, z = unpack ( fromJSON ( getElementData(v, "spawn") ) ) local x2,y2,z2 = getElementPosition(v) local rotx, roty, rotz = getElementRotation(v) local slots = getElementData(getElementData(v, "parent"), "MAX_Slots") or 20 local fuel = getElementData(getElementData(v, "parent"), "fuel") local tires = getElementData(getElementData(v, "parent"), "Tire_inVehicle") or 0 local engines = getElementData(getElementData(v, "parent"), "Engine_inVehicle") or 0 local parts = getElementData(getElementData(v, "parent"), "Parts_inVehicle") or 0 id = id + 1 sda = dbQuery(db, "INSERT INTO vehicles (model, x, y, z,x2,y2,z2, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) dbFree ( sda ) end end end noteAdmins("Vehicle backup done! ["..#vehicles.."]") end function createCars(model, x, y, z,x2,y2,z2 rotx, roty, rotz, slots, fuel, tires, engines, parts, id) veh = createVehicle(model, x2, y2, z2, rotx, roty, rotz) vehCol = createColSphere(x2, y2, z2, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", tonumber(slots)) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) setElementData(vehCol, "Tire_inVehicle", tonumber(tires)) setElementData(vehCol, "Engine_inVehicle", tonumber(engines)) setElementData(vehCol, "Parts_inVehicle", tonumber(parts)) setElementData(vehCol, "spawn", toJSON ( { model, x, y, z } ) ) setElementData(vehCol, "fuel", tonumber(fuel)) end (No lo he probado) Link to comment
Narutimmy Posted July 13, 2015 Author Share Posted July 13, 2015 No sé si se pueden guardar tablas con la función setElementData, pero puedes transformarlo al formato JSON, así: function backupAllVehZ() dbExec(db, "DROP TABLE vehicles") kk = dbQuery(db, "CREATE TABLE IF NOT EXISTS vehicles (model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id)") dbFree ( kk ) local vehicles = getElementsByType("vehicle") id = 0 for i,v in ipairs(vehicles) do local CCOL = getElementData (v,"parent") local VIP = getElementData (v,"VIP") if CCOL then if not VIP then ---local model = getElementModel(v) --local model, x, y, z = getElementData(v, "spawn")[1], getElementData(v, "spawn")[2], getElementData(v, "spawn")[3], getElementData(v, "spawn")[4] local model, x, y, z = unpack ( fromJSON ( getElementData(v, "spawn") ) ) local x2,y2,z2 = getElementPosition(v) local rotx, roty, rotz = getElementRotation(v) local slots = getElementData(getElementData(v, "parent"), "MAX_Slots") or 20 local fuel = getElementData(getElementData(v, "parent"), "fuel") local tires = getElementData(getElementData(v, "parent"), "Tire_inVehicle") or 0 local engines = getElementData(getElementData(v, "parent"), "Engine_inVehicle") or 0 local parts = getElementData(getElementData(v, "parent"), "Parts_inVehicle") or 0 id = id + 1 sda = dbQuery(db, "INSERT INTO vehicles (model, x, y, z,x2,y2,z2, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)", model, x, y, z, rotx, roty, rotz, slots, fuel, tires, engines, parts, id) dbFree ( sda ) end end end noteAdmins("Vehicle backup done! ["..#vehicles.."]") end function createCars(model, x, y, z,x2,y2,z2 rotx, roty, rotz, slots, fuel, tires, engines, parts, id) veh = createVehicle(model, x2, y2, z2, rotx, roty, rotz) vehCol = createColSphere(x2, y2, z2, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", tonumber(slots)) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) setElementData(vehCol, "Tire_inVehicle", tonumber(tires)) setElementData(vehCol, "Engine_inVehicle", tonumber(engines)) setElementData(vehCol, "Parts_inVehicle", tonumber(parts)) setElementData(vehCol, "spawn", toJSON ( { model, x, y, z } ) ) setElementData(vehCol, "fuel", tonumber(fuel)) end (No lo he probado) no lo habia podido probar.. no funciona :&% Link to comment
Sasu Posted July 14, 2015 Share Posted July 14, 2015 Fijate si "getElementData(v, "spawn")" devuelve algo. Link to comment
Narutimmy Posted July 17, 2015 Author Share Posted July 17, 2015 Fijate si "getElementData(v, "spawn")" devuelve algo. Te Explico cuando un auto se crea se usa esto: for i, veh in ipairs(pickupSpawns) do local x, y, z = veh[1], veh[2], veh[3] veh = createVehicle(422, x, y, z) vehCol = createColSphere(x, y, z, 2) attachElements(vehCol, veh, 0, 0, 0) setElementData(vehCol, "parent", veh) setElementData(veh, "parent", vehCol) setElementData(vehCol, "vehicle", true) setElementData(vehCol, "MAX_Slots", 20) local tires, engine, parts = getVehicleAddonInfos(getElementModel(veh)) 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", { 422, x, y, z }) setElementData(vehCol, "fuel", 10) end y cuando explota se respawnea usando esos datos: function notifyAboutExplosion() local col = getElementData(source, "parent") if col then local x1, y1, z1 = getElementPosition(source) id, x, y, z = getElementData(col, "spawn")[1], getElementData(col, "spawn")[2], getElementData(col, "spawn")[3], getElementData(col, "spawn")[4] local spawnnormal = getElementData(col, "spawn") if spawnnormal then source = source setTimer(respawnDayZVehicle, 600000, 1, id, x, y, z, source, col, getElementData(col, "MAX_Slots")) ---setTimer(destroyElement,1800000,1,source) setElementData(col, "deadVehicle", true) setElementData(source, "isExploded", true) 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 end end addEventHandler("onVehicleExplode", getRootElement(), notifyAboutExplosion) Osea toma esa data la de "spawn" para obtener el x,y,z que anterior mente se le seteo para crearla... entonces con lo de la db... nose porque arroja nil si si tiene la data.. .ya que si funciona el respwn nose si me explico. ----ARREGLADO Link to comment
Recommended Posts