Jump to content

Problema con sqlite


Anzo

Recommended Posts

Tengo un problema con esto y es que me dice que la columna no existe, pero me marca es el nombre de mi cuenta y no el de la columna y no sé porque, el error que da es éste:

Spoiler

ERROR: Database query failed: no such column: Dk

El 'Dk' es el nombre de la cuenta, no sé porque marca eso pero bueno, aquí dejo lo que tengo para ver si me pueden ayudar:

Spoiler

local timer = 0

addEventHandler("onResourceStart", resourceRoot, function()
	executeSQLQuery( 'CREATE TABLE IF NOT EXISTS playetk (RANGOS, SCORELEVESL, NAMELEVELS)' )
end)

function getNameFromPartt(name)
	if (name) then
		for i,pik in ipairs(getElementsByType("player")) do 
			if string.find(getPlayerName(pik):lower(), tostring(name):lower(),1,true) then
				return pik
			end
		end
	end
	return false
end

function createTopPlayTime_(pik)
	if not isElement(pik) then
		return 
	end
	local top_ = {}
	local create_ = executeSQLQuery("SELECT * FROM playetk")
	for i = 1, #create_ do 
		table.insert(top_, {nametagse = create_[i].NAMELEVELS, scorise = create_[i].SCORELEVESL})
	end
	if #create_ >0 then
		table.sort(top_, function(a,b) return (tonumber(a.scorise) or 0) > (tonumber(b.scorise) or 0) end)
		setTimer(
		function()
			for kz,dates in ipairs(top_) do 
				if (kz == 1) then
					triggerClientEvent(pik,"refreshPlayTime",pik)
				end
				triggerClientEvent(pik, "updatePlayTime",pik, tostring(dates.nametagse), tostring(dates.scorise), tonumber(kz))
				if (kz == 30) then
						table.remove(top_)
					break
				end
			end
		end,300,1)	
	end
end

function setPlayData(pik,topLevesl,nametagse)
	if not isElement( pik ) then
		return
	end
    if isGuestAccount ( getPlayerAccount ( pik ) ) then return end
	local result = executeSQLQuery("SELECT * FROM `playetk` WHERE `RANGOS`=?", getAccountName(getPlayerAccount( pik )))
	if ( type ( result ) == "table" and #result == 0 ) or not result then
		executeSQLQuery( 'INSERT INTO playetk( RANGOS, SCORELEVESL , NAMELEVELS) VALUES( ?, ?, ? )', getAccountName(getPlayerAccount( pik )), topLevesl, nametags)
	else
		if tonumber ( topLevesl ) < tonumber( result[1]["SCORELEVESL"] ) then topLevesl = result[1]["SCORELEVESL"] else topLevesl = topLevesl end
		executeSQLQuery( 'UPDATE playetk SET SCORELEVESL =?,NAMELEVELS =? WHERE RANGOS =?', topLevesl, nametags, getAccountName(getPlayerAccount( pik )))
	end
end

 

Lo que se supone que hace es crear un top de los jugadores con más tiempo online (o eso es lo que quiero hacer), no sé porque da error ahí si ya intente haciendo otros 'top' pero con nivel y funciona, así lo tengo con los niveles:

Spoiler

addEventHandler("onResourceStart", resourceRoot, function()
	executeSQLQuery( 'CREATE TABLE IF NOT EXISTS nivelek (RANGO, SCORELEVEL, NAMELEVEL)' )
end)

function getNameFromPartLevel(name)
	if (name) then
		for i,peolp in ipairs(getElementsByType("player")) do 
			if string.find(getPlayerName(peolp):lower(), tostring(name):lower(),1,true) then
				return peolp
			end
		end
	end
	return false
end

function createTopNIVELES_(peolp)
	if not isElement(peolp) then
		return 
	end
	local top_niveles = {}
	local create_topLeve = executeSQLQuery("SELECT * FROM nivelek")
	for i = 1, #create_topLeve do 
		table.insert(top_niveles, {nametags = create_topLeve[i].NAMELEVEL, scoris = create_topLeve[i].SCORELEVEL})
	end
	if #create_topLeve >0 then
		table.sort(top_niveles, function(a,b) return (tonumber(a.scoris) or 0) > (tonumber(b.scoris) or 0) end)
		setTimer(
		function()
			for kkej,dates in ipairs(top_niveles) do 
				if (kkej == 1) then
					triggerClientEvent(peolp,"refreshLevels",peolp)
				end
				triggerClientEvent(peolp, "updateLevels",peolp, tostring(dates.nametags), tostring(dates.scoris), tonumber(kkej))
				if (kkej == 30) then
						table.remove(top_niveles)
					break
				end
			end
		end,300,1)	
	end
end





function setLevelData(peolp,topLevel,nametags)
	if not isElement( peolp ) then
		return
	end
    if isGuestAccount ( getPlayerAccount ( peolp ) ) then return end
	local result = executeSQLQuery("SELECT * FROM `nivelek` WHERE `RANGO`=?", getAccountName(getPlayerAccount( peolp )))
	if ( type ( result ) == "table" and #result == 0 ) or not result then
		executeSQLQuery( 'INSERT INTO nivelek( RANGO, SCORELEVEL , NAMELEVEL) VALUES( ?, ?, ? )', getAccountName(getPlayerAccount( peolp )), topLevel, nametags)
	else
		if tonumber ( topLevel ) < tonumber( result[1]["SCORELEVEL"] ) then topLevel = result[1]["SCORELEVEL"] else topLevel = topLevel end
		executeSQLQuery( 'UPDATE nivelek SET SCORELEVEL =?,NAMELEVEL =? WHERE RANGO =?', topLevel, nametags, getAccountName(getPlayerAccount( peolp )))
	end
end

 

Esas son las partes que creo que tienen el error, porque lo demás son solo eventos para cargar el top a la gridlist; como dije con el de niveles intente y me funciona bien, marca a los jugadores de mayor a menor, pero intente haciéndolo con tiempo de juego y da ese error.

Por si necesitan todo el código aquí lo dejo...

Server:

Spoiler

local timer = 0

addEventHandler("onResourceStart", resourceRoot, function()
	executeSQLQuery( 'CREATE TABLE IF NOT EXISTS playetk (RANGOS, SCORELEVESL, NAMELEVELS)' )
end)

function getNameFromPartt(name)
	if (name) then
		for i,pik in ipairs(getElementsByType("player")) do 
			if string.find(getPlayerName(pik):lower(), tostring(name):lower(),1,true) then
				return pik
			end
		end
	end
	return false
end

function createTopPlayTime_(pik)
	if not isElement(pik) then
		return 
	end
	local top_ = {}
	local create_ = executeSQLQuery("SELECT * FROM playetk")
	for i = 1, #create_ do 
		table.insert(top_, {nametagse = create_[i].NAMELEVELS, scorise = create_[i].SCORELEVESL})
	end
	if #create_ >0 then
		table.sort(top_, function(a,b) return (tonumber(a.scorise) or 0) > (tonumber(b.scorise) or 0) end)
		setTimer(
		function()
			for kz,dates in ipairs(top_) do 
				if (kz == 1) then
					triggerClientEvent(pik,"refreshPlayTime",pik)
				end
				triggerClientEvent(pik, "updatePlayTime",pik, tostring(dates.nametagse), tostring(dates.scorise), tonumber(kz))
				if (kz == 30) then
						table.remove(top_)
					break
				end
			end
		end,300,1)	
	end
end





function setPlayData(pik,topLevesl,nametagse)
	if not isElement( pik ) then
		return
	end
    if isGuestAccount ( getPlayerAccount ( pik ) ) then return end
	local result = executeSQLQuery("SELECT * FROM `playetk` WHERE `RANGOS`=?", getAccountName(getPlayerAccount( pik )))
	if ( type ( result ) == "table" and #result == 0 ) or not result then
		executeSQLQuery( 'INSERT INTO playetk( RANGOS, SCORELEVESL , NAMELEVELS) VALUES( ?, ?, ? )', getAccountName(getPlayerAccount( pik )), topLevesl, nametags)
	else
		if tonumber ( topLevesl ) < tonumber( result[1]["SCORELEVESL"] ) then topLevesl = result[1]["SCORELEVESL"] else topLevesl = topLevesl end
		executeSQLQuery( 'UPDATE playetk SET SCORELEVESL =?,NAMELEVELS =? WHERE RANGOS =?', topLevesl, nametags, getAccountName(getPlayerAccount( pik )))
	end
end

exports.scoreboard:addScoreboardColumn("Muertes") 

addEvent("nuevoTiempo",true)
addEventHandler("nuevoTiempo",root,function(scorise,name)
	timer = scorise
	name_sql = getNameFromPartt(name_sql)
	setPlayData(name_sql,sql, name)
end)

addEventHandler("onElementDataChange",root,function(data)
	if (data == "Play Time") and (getElementType(source) == "player") then
		local tiempu = getElementData(source, data)
		setPlayData(source, tonumber(tiempu), string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", ""))
	end
end)

function seTop_()
	createTopPlayTime_( source )
end
addEvent("getTop_",true)
addEventHandler("getTop_",root,seTop_)

Client: 


function updateTimeOnline(nametagse, topLevesl, i)
	if (guiComboBoxGetSelected(Cordex.combobox) == 2) then
	local row = guiGridListAddRow ( Cordex.gridlist[1] )
	guiGridListSetItemText ( Cordex.gridlist[1], row, columna, "" .. i .. ".", false, false )
	guiGridListSetItemText ( Cordex.gridlist[1], row, columna_1, tostring(nametagse), false, false )
	guiGridListSetItemText ( Cordex.gridlist[1], row, columna_2, convertNumber(topLevesl), false, false )
	guiGridListSetColumnTitle(Cordex.gridlist[1], columna_2, "Tiempo en el servidor")
	guiGridListSetItemColor(Cordex.gridlist[1],row,columna, 255,0,0,255)
	guiGridListSetItemColor(Cordex.gridlist[1],row,columna_1, 255,255,255,255)
	guiGridListSetItemColor(Cordex.gridlist[1],row,columna_2, 214,2,252,255)
	end
end
addEvent("updatePlayTime", true)
addEventHandler("updatePlayTime", root, updateTimeOnline)

function refreshing()
	if (guiComboBoxGetSelected(Cordex.combobox) == 2) then
		guiGridListClear(Cordex.gridlist[1])
	end
end
addEvent("refreshPlayTime", true)
addEventHandler("refreshPlayTime", root, refreshing)

Y el "getTop_" es cuando le doy click al botón y debería aparecer la lista

 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...