Jump to content

[Ayuda] Error al crear un texto y ID


Homer Simpson

Recommended Posts

Bueno, os explico estoy intentando hacer un sistema en entornos en mi servidor pero tengo 2 problemas y son los siguientes : No detecta la ID y el texto, la ID se inserta en la base de datos pero el texto no. Espero que puedan ayudarme, gracias.

 

local elements = { }

local function loadText( id, text, x, y, z, interior, dimension  )
	local element = createElement( "3dtext" )
	setElementPosition( element, x, y, z )
	setElementInterior( element, interior )
	setElementDimension( element, dimension )
	setElementData( element, "text", tostring( text ) )
	
	elements[ id ] = element
end

addEventHandler( "onResourceStart", resourceRoot,
	function( )

		local result = dbPoll(dbQuery(handler, "SELECT * FROM 3dtext ORDER BY textID ASC" ),-1)
		if result then
			for key, data in ipairs( result ) do
				loadText( data.textID, data.text, data.x, data.y, data.z, data.interior, data.dimension )
			end
		end
	end
)






local function createxto(player,cmd,textID,...)
	if GetElementData(player,"NivelAdmin", 5) then
			local text = table.concat( { ... }, " " )
			local x, y, z = getElementPosition( player )
				local insertid = dbExec ( handler, "INSERT INTO `3dtext`(`text`, `x`, `y`, `z`, `interior`, `dimension`) VALUES (?,?,?,?,?,?)", text, x, y, z, getElementInterior( player ),getElementDimension( player ) )
				if insertid then
					loadText( insertid, text, x, y, z, getElementInterior( player ), getElementDimension( player ) )
					outputChatBox( "Texto creado. (ID " .. insertid .. ")", player, 0, 255, 0 )
				else
					outputDebugString( e )
					outputChatBox( "Error MYSQL.", player, 255, 0, 0 )
				end
			else
				outputChatBox( "Comando: /" .. cmd .. " [texto]", player, 255, 255, 255 )
			end
		end
addCommandHandler("creartextoentorno",createxto)



 

En el debugscript me da el siguiente error : Que en la línea 37 : attempt to concatenate local 'insertid' (a boolean value)

Y así es como se crea  https://imgur.com/2Je5B9T

  • Haha 1
Link to post

Me tomé la libertad de organizar mejor tu código, no está probado pero el código se ve "bien".

local elements = { }

local function loadText(id, text, x, y, z, interior, dimension, saveInDB)
	if id and elements[id] then return false end
	if type(x) ~= "number" or type(y) ~= "number" or type(z) ~= "number" then return false end
	
	if saveInDB then
		if not handler then return false end

		dbExec(handler, "INSERT INTO `3dtext`(`textID`, `text`, `x`, `y`, `z`, `interior`, `dimension`) VALUES (?,?,?,?,?,?,?)", id, text, x, y, z, interior, dimension)
	end
	
	interior = interior or 0
	dimension = dimension or 0
	elements[id] = createElement("3dtext")
	setElementPosition(elements[id], x, y, z)
	setElementInterior(elements[id], interior)
	setElementDimension(elements[id], dimension)
	setElementData(elements[id], "text", tostring(text))
		
	return elements[id]
end

addEventHandler("onResourceStart", resourceRoot,
	function()
		local qh = dbQuery(handler, "SELECT * FROM 3dtext ORDER BY textID ASC")
		local result = qh and dbPoll(qh, -1)
		
		if result then
			for key, data in ipairs(result) do
				loadText(data.textID, data.text, data.x, data.y, data.z, data.interior, data.dimension, false)
			end
		end
	end
)

local function createxto(player, cmd, textID, ...)
	if textID then
		if ((getElementData(player, "NivelAdmin", 5) or 0) == 5) then
			if textID and elements[textID] then
				outputChatBox( "Esta ID ya existe!", player, 255, 0, 0 )
				return
			end
			
			local text = table.concat({ ... }, " ")
			local x, y, z = getElementPosition(player)

			loadText(textID, text, x, y, z, getElementInterior(player), getElementDimension(player), true)
			outputChatBox("Texto creado. (ID " .. textID .. ")", player, 0, 255, 0)
		else
			outputChatBox("No tienes permiso para usar este comando!", player, 255, 255, 255)
		end
	else
		outputChatBox("Comando: /" .. cmd .. " [ID] [texto]", player, 255, 255, 255)
	end
end
addCommandHandler("creartextoentorno", createxto)

 

  • Thanks 1
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.

×
×
  • Create New...