Itashi Posted May 27, 2020 Share Posted May 27, 2020 Hello guys I just wanna know what I messed up in my script I'm facing this error for hours!! ERROR: vehicles/vehicles.Lua:35: attempt to call global 'SetElementData' (a nil value) and here is my whole code: function createVehicleForPlayer(player, command, model) local db = exports.db:getConnection() local x, y, z = getElementPosition(player) y = y + 5 dbExec(db, 'INSERT INTO vehicles (model, x, y, z) VALUES (?, ?, ?, ?)', model, x, y, z) local vehicleObject = createVehicle(model, x, y, z) outputChatBox ( "Command Syntax: /makeveh [module id]", getRootElement(), 255, 255, 0, true ) dbQuery(function (queryHandle) local results = dbPoll(queryHandle, 0) local result = results[1] SetElementData(vehicleObject, "id", vehicle.id) end, db, 'SELECT id FROM vehicles ORDER BY id DESC LIMIT 1') end 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) 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 vehicles = getElementByType('vehicle') for index, vehicle in pairs(vehicles) do local id = getElementData(vehicle, 'id') local x, y, z = getElementPosition(vehicle) dbExec(db, 'UPDATE vehicles SET x = ?, y = ?, z = ? WHERE id = ?', x, y, z, id) end end) Link to comment
Moderators Patrick Posted May 27, 2020 Moderators Share Posted May 27, 2020 It's setElementData and not SetElementData. 1 Link to comment
Itashi Posted May 27, 2020 Author Share Posted May 27, 2020 1 hour ago, Patrick said: It's setElementData and not SetElementData. Thanks amigo alot do you think that you can help me more with some stuff? I'm just chillin and trying to learn more MTA:SA development if yes here is my discord: Itashi#2850 Link to comment
Moderators Patrick Posted May 27, 2020 Moderators Share Posted May 27, 2020 4 minutes ago, Itashi said: Thanks amigo alot do you think that you can help me more with some stuff? I'm just chillin and trying to learn more MTA:SA development if yes here is my discord: Itashi#2850 Sorry, I don't give personal help in PMs for others, but you can join to our discord server, there you can talk with others in the scripting channels. https://discord.com/invite/mtasa 1 Link to comment
Itashi Posted May 27, 2020 Author Share Posted May 27, 2020 3 minutes ago, Patrick said: Sorry, I don't give personal help in PMs for others, but you can join to our discord server, there you can talk with others in the scripting channels. https://discord.com/invite/mtasa lmao I didn't saw that you are a staff here! thanks so much for your help it took me more than 3 hours without any result... and here you go gave me the answer! thanks again you can close this 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