Misunderstood Posted July 26, 2020 Share Posted July 26, 2020 (edited) Hi guys so I'm new to the community and as well as coding, but I'm learning it by myself right now. So I watched this video from this guy and I followed everything in the video. He gave a little assignment at the end of an episode 2 video before, to set "vehicle rotation". I did everything and tried to run my server, I was getting a warning and error. By the way there's a github link in the video to see his "commits" and stuff. Here's the screenshot Regarding to the screenshot of me launching the server, I've done some research about the meaning those words in the warning & the error, Vector3 means for 3d games, about directions and stuff (X, Y, Z) and for boolean it means "True or False" but I'm not sure what they have to do with it. if anyone knows what I'm doing here is wrong please let me know it would be much of appreciation. On 22/07/2020 at 13:33, erisP said: function createVehicleForPlayer(player, command, model) local db = exports.db:getConnection() local x, y, z = getElementPosition(player) local rotX, rotY, rotZ = getElementRotation(player) rotZ = rotZ + 90 -- lets turn the car 90 degrees to the left so the driver door faces us. y = y + 5 dbExec(db, 'INSERT INTO vehicles (model, x, y, z, rotation_x, rotation_y, rotation_z) VALUES (?, ?, ?, ?, ?, ?, ?)', model, x, y, z, rotX, rotY, rotZ) local vehicleObject = createVehicle(model, x, y, z, rotX, rotY, rotZ) dbQuery(function (queryHandle) local results = dbPoll(queryHandle, 0) local vehicle = results[1] setElementData(vehicleObject, 'id', vehicle.id) end, db, 'SELECT id FROM vehicles ORDER BY id DESC LIMIT 1') end addCommandHandler('createvehicle', createVehicleForPlayer, false, false) addCommandHandler('createveh', createVehicleForPlayer, false, false) addCommandHandler('makeveh', createVehicleForPlayer, false, false) function loadAllVehicles(queryHandle) local results = dbPoll(queryHandle, 0) for index, vehicle in pairs(results) do local vehicleObject = createVehicle(vehicle.model, vehicle.x, vehicle.y, vehicle.z, vehicle.rotation_x, vehicle.rotation_y, vehicle.rotation_z) setElementData(vehicleObject, "id", vehicle.id) end end addEventHandler('onResourceStart', resourceRoot, function() local db = exports.db:getConnection() dbQuery(loadAllVehicles, db, 'SELECT * FROM vehicles') end) addEventHandler('onResourceStop', resourceRoot, function() local db = exports.db:getConnection() local vehicles = getElementsByType('vehicle') for index, vehicle in pairs(vehicles) do local id = getElementData(vehicle, 'id') local x, y, z = getElementPosition(vehicle) local rotX, rotY, rotZ = getElementRotation(vehicle) dbExec(db, 'UPDATE vehicles SET x = ?, y = ?, z = ?, rotation_x = ?, rotation_y = ?, rotation_z = ? WHERE id = ?', x, y, z, rotX, rotY, rotZ, id) end end) Edited July 26, 2020 by Misunderstood Link to comment
Discord Moderators Zango Posted July 26, 2020 Discord Moderators Share Posted July 26, 2020 Hello and welcome to MTA. Your code looks fine, looks like you store the rotation correctly. I think the issue is in your database. You might have a row in your "vehicles" table that doesn't contain anything in rotation_x. So your vehicle is not created on line 34 (MTA gives you a warning). But then your code fails because it thinks vehicle_object is created (line 38). So try deleting the "vehicles" table and creating it again. Link to comment
Misunderstood Posted July 28, 2020 Author Share Posted July 28, 2020 On 27/07/2020 at 03:29, Zango said: Hello and welcome to MTA. Your code looks fine, looks like you store the rotation correctly. I think the issue is in your database. You might have a row in your "vehicles" table that doesn't contain anything in rotation_x. So your vehicle is not created on line 34 (MTA gives you a warning). But then your code fails because it thinks vehicle_object is created (line 38). So try deleting the "vehicles" table and creating it again. Thank you Zango, I'll try that. 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