amiz Posted October 21, 2020 Share Posted October 21, 2020 local db addEventHandler('onResourceStart', getResourceRootElement, function() db = dbConnect('sqlite', '/:global.db') end) function getdbconnection() return db end Link to comment
Moderators Patrick Posted October 21, 2020 Moderators Share Posted October 21, 2020 (edited) Hi! getResourceRootElement is not exists (nil), use resourceRoot instead. By the way, getResourceRootElement is an existing function in MTA, you just forgot the () from the end. And I want to ask you to describe in more detail your question next time. Just pasting the error message here is not enough. Thanks. Edited October 21, 2020 by Patrick Link to comment
amiz Posted October 21, 2020 Author Share Posted October 21, 2020 (edited) dbexec failed no such tables: vehicles but i have created db sqlite and i have put in the right db to read from i just dosent write how can i fix it ? And I cant write changes in db sqlite , I cant click it its grey Edited October 21, 2020 by amiz Link to comment
Tekken Posted October 21, 2020 Share Posted October 21, 2020 Change ‘/:global.db’ to simply ‘global.db’ Link to comment
amiz Posted October 21, 2020 Author Share Posted October 21, 2020 (edited) I have done that local db addEventHandler('onResourceStart', resourceRoot, function() db = dbConnect('sqlite', 'global.db') end) function getdbconnection() return db end Still dosent work vehicles\vehicles .lua:9: dbExec Failed; (1) no such table: vehicles Edited October 21, 2020 by amiz Link to comment
Tekken Posted October 21, 2020 Share Posted October 21, 2020 You don’t give enough information please upload all your code so I can review properly you can send on discord Link to comment
amiz Posted October 21, 2020 Author Share Posted October 21, 2020 vehicles\vehicles.lua:11: Bad argument @ 'createVehicle' [Expected number at argument 1, got nill] dbExec failed; (1) near "exist": syntax error outputChatBox("type") function createVehicleForPlayer(player, command, model) local db = exports.db:getdbconnection() local x ,y ,z = getElementPosition(player) y = 5 dbExec (db, "Create table if not exist vehicles id int, model int, x float, y float, z float") createVehicle(id, model, x, y, z) end addCommandHandler("createvehicle", createVehicleForPlayer, false, false) addCommandHandler("createveh", createVehicleForPlayer, false, false) addCommandHandler("makeveh", createVehicleForPlayer, false, false) Link to comment
Tekken Posted October 21, 2020 Share Posted October 21, 2020 (edited) There’s no id in createVehicle just delete it Edited October 21, 2020 by Tekken Link to comment
amiz Posted October 21, 2020 Author Share Posted October 21, 2020 vehicles\vehicles.lua:9: dbExec failed; (1) near "exist": syntax error outputChatBox("type") function createVehicleForPlayer(player, command, model) local db = exports.db:getdbconnection() local x ,y ,z = getElementPosition(player) y = 5 dbExec (db,"Create table if not exist vehicles id int, model int, x float, y float, z float") createVehicle(model, x, y, z) end addCommandHandler("createvehicle", createVehicleForPlayer, false, false) addCommandHandler("createveh", createVehicleForPlayer, false, false) addCommandHandler("makeveh", createVehicleForPlayer, false, false) Link to comment
Rockyz Posted October 22, 2020 Share Posted October 22, 2020 11 hours ago, amiz said: vehicles\vehicles.lua:9: dbExec failed; (1) near "exist": syntax error outputChatBox("type") function createVehicleForPlayer(player, command, model) local db = exports.db:getdbconnection() local x ,y ,z = getElementPosition(player) y = 5 dbExec (db,"Create table if not exist vehicles id int, model int, x float, y float, z float") createVehicle(model, x, y, z) end addCommandHandler("createvehicle", createVehicleForPlayer, false, false) addCommandHandler("createveh", createVehicleForPlayer, false, false) addCommandHandler("makeveh", createVehicleForPlayer, false, false) I don't know what are you trying to do, but anyways try to replace the db string with this: CREATE TABLE IF NOT EXISTS `vehicles` (id INT, model INT, x FLOAT, y FLOAT, z FLOAT) Link to comment
amiz Posted October 22, 2020 Author Share Posted October 22, 2020 vehicles\vehicles.lua:9: dbExec failed; (1) incomplete input am trying to make a database where my vehicles save, but it dosent work outputChatBox("type") function createVehicleForPlayer(player, command, model) local db = exports.db:getdbconnection() local x ,y ,z = getElementPosition(player) y = 5 dbExec (db, "CREATE TABLE IF NOT EXISTS `vehicles` (id INT, model INT, x FLOAT, y FLOAT, z FLOAT") createVehicle(model, x, y, z) end addCommandHandler("createvehicle", createVehicleForPlayer, false, false) addCommandHandler("createveh", createVehicleForPlayer, false, false) addCommandHandler("makeveh", createVehicleForPlayer, false, false) Link to comment
Tekken Posted October 22, 2020 Share Posted October 22, 2020 Put the dbExec within the ‘db’ resource, as for the creation just do «"table insert", sorry i am on phone and I can’t script but I may send you a working exemple later when I’m home. Link to comment
amiz Posted October 22, 2020 Author Share Posted October 22, 2020 Ok I don't understand exactly, So am just gonna wait when you can response with the proper script cause am a newbie at scriping Link to comment
Tekken Posted October 23, 2020 Share Posted October 23, 2020 Ok here is a simple example local db = dbConnect("sqlite", "database.db") --creating the connection (no need to create the 'database.db' file as the script does it for us); local allVehiclesId = 0; --This is the start ID; if db then -- make sure the db was created! dbExec(db, "CREATE TABLE IF NOT EXISTS `vehicles` (id INT, model INT, x FLOAT, y FLOAT, z FLOAT"); else return print("error db not existing"); --if not print error end function createVehicleForPlayer(player, command, model) local x, y, z = getElementPosition(player); local veh = createVehicle(model, x, y, z); if veh then allVehiclesId = allVehiclesId + 1; --Add the vehicle to the id list; (make sure here is not local variable) dbExec(db, "INSERT INTO `vehicles` (id, model, x, y, z) VALUES(?,?,?,?,?)", allVehiclesId, model, x, y, z); --save to database; end end addCommandHandler("createvehicle", createVehicleForPlayer); --Create command; --This part is a gift; :) function loadSavedVehicles() if db then local p = dbPoll(dbQuery(db, "SELECT * FROM `vehicles`"), -1); --get all vehicles from db; if (#p > 0) then allVehiclesId = 0; --reset id's; for _,v in ipairs(p) do allVehiclesId = allVehiclesId + 1; -- re define id's createVehicle(v["model"], v["x"], v["y"], v["z"]); end end end end addCommandHandler("loadvehicles", loadSavedVehicles); Greetings. Link to comment
amiz Posted October 23, 2020 Author Share Posted October 23, 2020 vehicles\vehicles.lua:6: dbExec failed; (1) incomplete input but I still have errors with the new script Link to comment
Rockyz Posted October 24, 2020 Share Posted October 24, 2020 4 hours ago, amiz said: vehicles\vehicles.lua:6: dbExec failed; (1) incomplete input but I still have errors with the new script You're getting this error because you've missed a bracket on the end of the db string: CREATE TABLE IF NOT EXISTS `vehicles` (id INT, model INT, x FLOAT, y FLOAT, z FLOAT) 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now