Jump to content

Problemas para converter um mod MySQL para SQlite


Recommended Posts

Fala galera. Estou iniciando a fazer mods no MTA e estou com um problema que pra vocês pede ser facíl de mais, mas para mim está terrivél ! Estou tentando converter um script dp MySQL para sqlite. Já até consegui ele fazer a conexão com a db, mas quando eu tento acrescentar alguma coisa pelo mod dentro do jogo, ele não acrescentar. Alguém pode me ajudar ?

 

 

local connection = dbConnect("sqlite", "database.db")

function mdcLoginServer(username, password)
	local source = client
	dbQuery(
		function (queryHandler)
			local result, numAffectedRows, errorMsg = dbPoll(queryHandler, 0)
			if numAffectedRows > 0 then
				for _, row in ipairs(result) do
 					faction = row["faction"]
 				end
 				triggerClientEvent(source, "loginMdcClient", source, faction)
			else
				exports.ng_info:showBoxS(source, "Hibás felhasználónév vagy jelszó.", "error")
			end
		end,
		connection,
		"SELECT * FROM mdcaccounts WHERE username = ? AND password = ?", username, password
	)
end
addEvent("mdcLoginServer", true)
addEventHandler("mdcLoginServer", getRootElement(), mdcLoginServer)

addEvent("acceptPlayerLogin", true)
addEventHandler("acceptPlayerLogin", getRootElement(), function(player)
	triggerClientEvent(player, "loginMdcClient", player)
end)

function createMdcAccount(thePlayer, command, username, password)
	local faction = getElementData(thePlayer, "char.factionID")
	if faction == 190 then
		if not (username) or not (password) then
			outputChatBox("#4169E1[Use]:#ffffff /" .. command .. " [nome de usuário] [senha]", thePlayer, 208, 101, 29, true)
		else
			local query = dbExec(connection, "INSERT INTO mdcaccounts SET username = ?, password = ?, faction = ?",username,password,faction)
			if query then
				outputChatBox("#4169E1[Brasil PH]:#ffffff Usuário adicionado com sucesso", thePlayer, 208, 101, 29, true)
			else
				outputChatBox("#FF0000[Error]:#ffffff Erro no MySQL", thePlayer, 124, 9, 9, true)
			end
		end
	end
end
addCommandHandler("addmdconta", createMdcAccount)

function deleteMdcAccount(thePlayer, command, username)
	if getElementData(thePlayer, "char.factionID") == 1 then
		if not (username) then
			outputChatBox("[Használat]:#ffffff /" .. command .. " [Felhasználónév]", thePlayer, 208, 101, 29, true)
		else
			local query = dbExec(connection, "DELETE FROM mdcaccounts WHERE username=?",username)
			if query then
				outputChatBox("[Információ]:#ffffff Felhasználó törölve!", thePlayer, 208, 101, 29, true)
			else
				outputChatBox("[Hiba]:#ffffff MySQL Hiba!", thePlayer, 124, 9, 9, true)
			end
		end
	end
end
addCommandHandler("removemdconta", deleteMdcAccount)

--================================================--

local positions = {
  	-- x, y, z, tamanho, nome
  	{1020.9491577148, -957.35943603516, 41.883373260498, 20, "Posto de gasolina do sul"},
  	{1528.837890625, -1674.6318359375, 13.3828125, 50, "polícia"},
  	{1304.6455078125, -1700.59375, 13.546875, 50, "filme"},
  	{1548.044921875, -1789.8291015625, 13.546875, 50, "Prefeitura próxima a ela"},
  	{1477.966796875, -1759.06640625, 13.58437538147, 50, "Prefeitura"},
  	{2102.0439453125, -1782.5283203125, 13.392087936401, 50, "Pizzaria bem empilhada"},
  	{1909.9931640625, -1421.6787109375, 11.533273696899, 100, "Skate Park"},
  	{1012.896484375, -931.2958984375, 42.1796875, 50, "Posto de gasolina do norte"},
  	{1582.197265625, -2165.1767578125, 13.60000038147, 50, "oficina de montagem"},
  	{2227.388671875, -1722.4697265625, 13.555265426636, 20, "ginásio"},
  	{2860.5537109375, -2048.947265625, 10.9375, 30, "Pista de entrada"},
  	{2058.3115234375, -1912.3310546875, 13.546875, 50, "Táxis Bateria"},
  	{1821.87109375, -1684.2158203125, 13.3828125, 50, "Alhambra Club"},
  	{1192.4443359375, -1322.03125, 13.3984375, 50, "hospital"}
}
 
for k,v in ipairs(positions) do
   local x,y,z = v[1], v[2], v[3]
   local marker = createMarker(x,y,z-1, "cylinder", v[4], 255,255,255,0)
   setElementData(marker, "marker.ZoneName", v[5])
   setElementData(marker, "marker.isZoneCamera", true)
end

--================================================--

function sendMessageToPoliceG(text, number)
	for k, v in ipairs(getElementsByType("player")) do
		if getElementData(v, "char.factionID") == 190 then
			outputChatBox("[PMESP]:#ffffff "..text, v, 208, 101, 29, true)
		end
	end
end
addEvent("sendMessageToPoliceG", true)
addEventHandler("sendMessageToPoliceG", getRootElement(), sendMessageToPoliceG)

function createBackupBlipServer(vehicle)
		for k, v in ipairs(getElementsByType("player")) do
			local count = getElementData(v, "groupCount")
			if count then
				for i=0, count-1 do
			local group = getElementData(v, "group_" .. i .. "")
				if group == 1 or group == 2 or group == 3 or group == 14 or group == 8 or group == 15 then
					triggerClientEvent(root, "createBackupBlipClient", root, vehicle)
								end
						end
				end
		end
end
addEvent("createBackupBlipServer", true)
addEventHandler("createBackupBlipServer", getRootElement(), createBackupBlipServer)

function destroyBlipServer(vehicle)
		for k, v in ipairs(getElementsByType("player")) do
			local count = getElementData(v, "groupCount")
			if count then
				for i=0, count-1 do
			local group = getElementData(v, "group_" .. i .. "")
				if group == 1 or group == 2 or group == 3 then
					triggerClientEvent(root, "destroyBlipClient", root, vehicle)
								end
						end
				end
		end
end
addEvent("destroyBlipServer", true)
addEventHandler("destroyBlipServer", getRootElement(), destroyBlipServer)

function createDutyBlipServer(vehicle)
		for k, v in ipairs(getElementsByType("player")) do
			local count = getElementData(v, "groupCount")
			if count then
				for i=0, count-1 do
			local group = getElementData(v, "group_" .. i .. "")
				if group == 1 or group == 2 or group == 3 then
					triggerClientEvent(root, "createDutyBlipClient", root, vehicle)
								end
						end
				end
		end
end
addEvent("createDutyBlipServer", true)
addEventHandler("createDutyBlipServer", getRootElement(), createDutyBlipServer)

function addTicket(charactername, price, jail, reason)
	 local insertSQL = dbExec(connection, "INSERT INTO mdctickets SET targetname = ?, price = ?, jailtime =?, reason =?",charactername, price, jail, reason)
end
addEvent("addTicket", true)
addEventHandler("addTicket", getRootElement(), addTicket)

function deleteFromTickets(id)
	 local insertSQL = dbExec(connection, "DELETE FROM mdctickets WHERE id=?",id)
end
addEvent("deleteFromTickets", true)
addEventHandler("deleteFromTickets", getRootElement(), deleteFromTickets)

function addWantedPerson(charactername, reason, description)
	 local insertSQL = dbExec(connection, "INSERT INTO mdcwantedpersons SET charactername = ?, reason = ?, description = ?",charactername, reason, description)
end
addEvent("addWantedPerson", true)
addEventHandler("addWantedPerson", getRootElement(), addWantedPerson)

function deleteFromWantedPersons(id)
	 local insertSQL = dbExec(connection, "DELETE FROM mdcwantedpersons WHERE id=?",id)
end
addEvent("deleteFromWantedPersons", true)
addEventHandler("deleteFromWantedPersons", getRootElement(), deleteFromWantedPersons)

function addWantedCar(modelname,numberplate,reason)
	 local insertSQL = dbExec(connection, "INSERT INTO mdcwantedcars SET modelname = ?, numberplate = ?, reason = ?",modelname,numberplate,reason)
	 triggerEvent("getKorozottKocsik", root)
end
addEvent("addWantedCar", true)
addEventHandler("addWantedCar", getRootElement(), addWantedCar)

function deleteFromWantedCars(id)
	 local insertSQL = dbExec(connection, "DELETE FROM mdcwantedcars WHERE id=?",id)
	 triggerEvent("getKorozottKocsik", root)
end
addEvent("deleteFromWantedCars", true)
addEventHandler("deleteFromWantedCars", getRootElement(), deleteFromWantedCars)

function getTicketsServer(playerSource)
	local tickets = {}
	tickets = {}
	local QueryEredmeny = dbPoll ( dbQuery( connection, "SELECT * FROM mdctickets"), -1 )
	if (QueryEredmeny) then
		for k, v in ipairs(QueryEredmeny) do
			tickets[#tickets + 1] = {v["targetname"], v["price"], v["jailtime"], v["reason"], v["id"]}
		end
		triggerClientEvent(root, "getTicketsClient", root, tickets)
	end
end
addEvent("getTicketsServer", true)
addEventHandler("getTicketsServer", getRootElement(), getTicketsServer)

function getWantedCarsServer(playerSource)
	local wantedcars = {}
	wantedcars = {}
	local QueryEredmeny = dbPoll ( dbQuery( connection, "SELECT * FROM mdcwantedcars"), -1 )
	if (QueryEredmeny) then
		for k, v in ipairs(QueryEredmeny) do
			wantedcars[#wantedcars + 1] = {v["modelname"], v["numberplate"], v["reason"], v["id"]}
		end
		triggerClientEvent(root, "getWantedCarsClient", root, wantedcars)
	end
end
addEvent("getWantedCarsServer", true)
addEventHandler("getWantedCarsServer", getRootElement(), getWantedCarsServer)

function getWantedPersonsServer(playerSource)
	local wantedpersons = {}
	wantedpersons = {}
	local QueryEredmeny = dbPoll ( dbQuery( connection, "SELECT * FROM mdcwantedpersons"), -1 )
	if (QueryEredmeny) then
		for k, v in ipairs(QueryEredmeny) do
			wantedpersons[#wantedpersons + 1] = {v["charactername"], v["reason"], v["id"], v["description"]}
		end
		triggerClientEvent(root, "getWantedPersonsClient", root, wantedpersons)
	end
end
addEvent("getWantedPersonsServer", true)
addEventHandler("getWantedPersonsServer", getRootElement(), getWantedPersonsServer)

--[[CCTV]]--

--[[local pdcamera = createObject ( 2606, 253.8818359375, 114.7880859375, 1009.3209228516, 0, 0, 90)
setElementData(pdcamera,"cctv:allowed",true)
setElementInterior(pdcamera,10)
setElementDimension(pdcamera,2)

local pdmarker = createMarker(255.431640625, 114.466796875, 1007.813659668, "cylinder", 1, 202, 84, 84, 170)
setElementInterior(pdmarker,10)
setElementDimension(pdmarker,2)
setElementData(pdmarker,"visibleName","\nJobb klikk a kamerákra.",true)
setElementData(pdmarker,"marker:name","#ca5454[CCTV]\n#ffffffHasználata:\n#acd373[BAL KLIKK] #ffffff- Kamera panel megnyitása\n#acd373[BACKSPACE] #ffffff- Kilépés a panelből",true)
setElementData(pdmarker,"visiblePedName","Használat:")
setElementData(pdmarker,"nameEnabled",true)]]--

 

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