DerekSP

SQLite logic error

Recommended Posts

Hello. I have been following a youtube tutorial about MTA coding, and I got to the point where I want to set up a database of parked cars.

I have a /park command that is supposed to write the position and direction of the vehicle a player is in to "vehicles" table in global.db

Here's the code:

function parkVehicle(player, command, model)
	local playerVehicle = getPedOccupiedVehicle(player)
	local db = exports.db:getConnection()
	if playerVehicle then
		local x, y, z = getElementPosition(playerVehicle)
		local d, e, f = getElementRotation(playerVehicle)
		dbExec(db, 'INSERT INTO vehicles (model, x, y, z, d) VALUES (?, ?, ?, ?, ?)', model, x, y, z, d)
		outputChatBox("Vehicle parked")
	else
		outputChatBox("You are not in a vehicle")
	end
end

addCommandHandler('park', parkVehicle, false, false)

The youtube tutorial had this done automatically upon spawning of the vehicle, but I wanted to split it into two commands, but seems like I failed somewhere.

Please, I need any help. I have been checking the code, comparing it to the tutorial, and everything seems like it should work just fine...

Share this post


Link to post

1)Make sure that the resource has the database is running

2)Make sure you have in meta file write the export function correct and type server 

3) Use /debugscipt 3 see errors or warnings that script have 

Share this post


Link to post
Posted (edited)

I can see that you use the "db" resource by exporting, is the function in this resource returning the dbConnection ?

Edited by Gordon_G

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.