Jump to content

SQLite logic error


DerekSP

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...

Link to comment

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.
×
×
  • Create New...