Centauro Posted June 25, 2015 Share Posted June 25, 2015 tengo una duda, como puedo hacer que cuando un resource de restart no se destruyan las cosas que ha creado ese scrip por ejemplo cuando pongo restart al resource se elimina un vehiculo que habia creado, como puedo hacer que no se elimine ? gracias Link to comment
AlFA# Posted June 25, 2015 Share Posted June 25, 2015 tengo una duda, como puedo hacer que cuando un resource de restart no se destruyan las cosas que ha creado ese scrippor ejemplo cuando pongo restart al resource se elimina un vehiculo que habia creado, como puedo hacer que no se elimine ? gracias usa setElementData o una MySQL Link to comment
Centauro Posted June 25, 2015 Author Share Posted June 25, 2015 tengo una duda, como puedo hacer que cuando un resource de restart no se destruyan las cosas que ha creado ese scrippor ejemplo cuando pongo restart al resource se elimina un vehiculo que habia creado, como puedo hacer que no se elimine ? gracias usa setElementData o una MySQL gracias por responder, podrias darme un ejemplo ? Link to comment
AlFA# Posted June 25, 2015 Share Posted June 25, 2015 tengo una duda, como puedo hacer que cuando un resource de restart no se destruyan las cosas que ha creado ese scrippor ejemplo cuando pongo restart al resource se elimina un vehiculo que habia creado, como puedo hacer que no se elimine ? gracias usa setElementData o una MySQL gracias por responder, podrias darme un ejemplo ? Jajaja, yo solo se que es eso, no me digas como hacerlo por que no tengo ni idea tío, lo siento. Link to comment
Centauro Posted June 25, 2015 Author Share Posted June 25, 2015 Jajaja, yo solo se que es eso, no me digas como hacerlo por que no tengo ni idea tío, lo siento. gracias igual, alguien que sepa y me pueda orientar? Link to comment
Tomas Posted June 25, 2015 Share Posted June 25, 2015 if not fileExists ("saving.db") then fileCreate ("saving.db"); outputChatBox("Base de datos creada"); end local db = dbConnect("sqlite", "saving.db") ; dbExec(db, "CREATE TABLE IF NOT EXISTS `elements`(`elemType` TEXT, `id` INT, `x` INT, `y` INT, `z` INT, `rotX` INT, `rotY` INT, `rotZ` INT)") addEventHandler("onResourceStop", resourceRoot, function ( ) for index, value in ipairs ( getElementsByType ( "vehicle", resourceRoot ) ) do local x, y, z = getElementPosition(value) local rx, ry, rz = getElementRotation(value) dbExec( db, "INSERT INTO elements VALUES (?,?,?,?,?,?,?,?)", "vehicle", getElementModel(value), x, y, z, rx, ry, rz ) end for index, value in ipairs ( getElementsByType ( "object", resourceRoot ) ) do local x, y, z = getElementPosition(value) local rx, ry, rz = getElementRotation(value) dbExec( db, "INSERT INTO elements VALUES (?,?,?,?,?,?,?,?)", "object", getElementModel(value), x, y, z, rx, ry, rz ) end end ) addEventHandler("onResourceStart", resourceRoot, function ( ) query = dbQuery( db, "SELECT * FROM elements" ) result = dbPoll( query, -1 ) if result then for _, row in ipairs ( result ) do if row['elemType'] == "vehicle" then model, x, y, z, rx, ry, rz = row['id'], row['x'], row['y'], row['z'], row['rx'], row['ry'], row['rz'] createVehicle(model, x, y, z, rx, ry, rz) elseif row['elemType'] == "object" then id, x, y, z, rx, ry, rz = row['id'], row['x'], row['y'], row['z'], row['rx'], row['ry'], row['rz'] createObject(id, x, y, z, rx, ry, rz) end end end dbExec( db, "DELETE FROM `elements`"); end ) Link to comment
Centauro Posted June 26, 2015 Author Share Posted June 26, 2015 if not fileExists ("saving.db") then fileCreate ("saving.db"); outputChatBox("Base de datos creada"); end local db = dbConnect("sqlite", "saving.db") ; dbExec(db, "CREATE TABLE IF NOT EXISTS `elements`(`elemType` TEXT, `id` INT, `x` INT, `y` INT, `z` INT, `rotX` INT, `rotY` INT, `rotZ` INT)") addEventHandler("onResourceStop", resourceRoot, function ( ) for index, value in ipairs ( getElementsByType ( "vehicle", resourceRoot ) ) do local x, y, z = getElementPosition(value) local rx, ry, rz = getElementRotation(value) dbExec( db, "INSERT INTO elements VALUES (?,?,?,?,?,?,?,?)", "vehicle", getElementModel(value), x, y, z, rx, ry, rz ) end for index, value in ipairs ( getElementsByType ( "object", resourceRoot ) ) do local x, y, z = getElementPosition(value) local rx, ry, rz = getElementRotation(value) dbExec( db, "INSERT INTO elements VALUES (?,?,?,?,?,?,?,?)", "object", getElementModel(value), x, y, z, rx, ry, rz ) end end ) addEventHandler("onResourceStart", resourceRoot, function ( ) query = dbQuery( db, "SELECT * FROM elements" ) result = dbPoll( query, -1 ) if result then for _, row in ipairs ( result ) do if row['elemType'] == "vehicle" then model, x, y, z, rx, ry, rz = row['id'], row['x'], row['y'], row['z'], row['rx'], row['ry'], row['rz'] createVehicle(model, x, y, z, rx, ry, rz) elseif row['elemType'] == "object" then id, x, y, z, rx, ry, rz = row['id'], row['x'], row['y'], row['z'], row['rx'], row['ry'], row['rz'] createObject(id, x, y, z, rx, ry, rz) end end end dbExec( db, "DELETE FROM `elements`"); end ) Tomás gracias, pero ahora loe stoy intentando con un sistema de vehiculos y no me funciona, podrías ayudarme ?, gracias por responder addEventHandler("onResourceStart", resourceRoot, function() db = dbConnect("sqlite", "database.db") dbExec(db, "CREATE TABLE IF NOT EXISTS VehicleList (ID, Account, Model, X, Y, Z, RotZ, Colors, Upgrades, Paintjob, Cost, HP)") end) addEventHandler("onResourceStop", resourceRoot, function ( ) if isElement(theVehicle) then local Owner = getElementData(theVehicle, "Owner") if Owner then for index, value in ipairs ( getElementsByType ( "vehicle", Owner ) ) do local x, y, z = getElementPosition(theVehicle) local _, _, rz = getElementRotation(theVehicle) local r1, g1, b1, r2, g2, b2 = getVehicleColor(theVehicle, true) local color = r1..","..g1..","..b1..","..r2..","..g2..","..b2 upgrade = "" for _, upgradee in ipairs (getVehicleUpgrades(theVehicle)) do if upgrade == "" then upgrade = upgradee else upgrade = upgrade..","..upgradee end end local Paintjob = getVehiclePaintjob(theVehicle) or 3 local id = getElementData(theVehicle, "ID") dbExec(db, "UPDATE VehicleList SET X = ?, Y = ?, Z = ?, RotZ = ?, HP = ?, Colors = ?, Upgrades = ?, Paintjob = ? WHERE Account = ? AND ID = ?", x, y, z, rz, getElementHealth(theVehicle), color, upgrade, Paintjob, getAccountName(getPlayerAccount(Owner)), id) end end end end ) addEventHandler("onResourceStart", resourceRoot, function(id) if getVehicleByID(id) then else local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1) local color = split(data[1]["Colors"], ',') r1 = color[1] or 255 g1 = color[2] or 255 b1 = color[3] or 255 r2 = color[4] or 255 g2 = color[5] or 255 b2 = color[6] or 255 vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"]) setElementData(vehicle, "ID", id) local upd = split(tostring(data[1]["Upgrades"]), ',') for i, upgrade in ipairs(upd) do addVehicleUpgrade(vehicle, upgrade) end local Paintjob = data[1]["Paintjob"] or 3 setVehiclePaintjob(vehicle, Paintjob) setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) if data[1]["HP"] <= 255.5 then data[1]["HP"] = 255 end setElementHealth(vehicle, data[1]["HP"]) setElementData(vehicle, "Owner", source) setElementData(source, "EsteCarro", vehicle) vv[vehicle] = setTimer(function(source) if not isElement(source) then killTimer(vv[source]) vv[source] = nil end if isElement(source) and getElementHealth(source) <= 255 then setElementHealth(source, 255.5) setVehicleDamageProof(source, true) setVehicleEngineState(source, false) end end, 50, 0, vehicle) addEventHandler("onVehicleDamage", vehicle, function(loss) local account = getAccountName(getPlayerAccount(getElementData(source, "Owner"))) setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source) end) addEventHandler("onVehicleEnter", vehicle, function(player) if getElementHealth(source) <= 255.5 then setVehicleEngineState(source, false) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end ) end end ) Link to comment
Recommended Posts