Jump to content

ERROR


Recommended Posts

ERROR: admin\server\admin_server.lua:1282: attempt to concatenate local 'name' (a nil value)
 

		if ( text ~= "" ) then
			outputServerLog ( "ADMIN: Resource \'" .. name .. "\' " .. text .. " by " .. getAdminNameForLog ( source )  ) ---- Line Error
			for id, player in ipairs(getElementsByType("player")) do
				triggerClientEvent ( player, "aClientLog", root, text  )
			end

 

Link to comment
2 hours ago, yToPzz said:

ERROR: admin\server\admin_server.lua:1282: attempt to concatenate local 'name' (a nil value)
 

		if ( text ~= "" ) then
			outputServerLog ( "ADMIN: Resource \'" .. name .. "\' " .. text .. " by " .. getAdminNameForLog ( source )  ) ---- Line Error
			for id, player in ipairs(getElementsByType("player")) do
				triggerClientEvent ( player, "aClientLog", root, text  )
			end

 

Nessa situação precisamos ver a variavel ou o elemento name antes desta linha que você definiu na função, se possivel mande a função completa...

Link to comment
17 hours ago, FelipeX said:

Nessa situação precisamos ver a variavel ou o elemento name antes desta linha que você definiu na função, se possivel mande a função completa...

addEvent ( "aResource", true )
addEventHandler ( "aResource", root, function ( name, action )
	if checkClient( "command."..action, source, 'aResource', action ) then return end
	local pname = getPlayerName ( source )
	if ( hasObjectPermissionTo ( client or source, "command."..action ) ) then
		local text = ""
		if ( action == "start" ) then
			if ( startResource ( getResourceFromName ( name ), true ) ) then
				text = "started"
			end
		elseif ( action == "restart" ) then
			if ( getResourceState ( getResourceFromName ( name ) ) == "running" ) then
				if ( restartResource ( getResourceFromName ( name ) ) ) then text = "restarted" end
			end
		elseif ( action == "stop" ) then
			if ( stopResource ( getResourceFromName ( name ) ) ) then
				text = "stopped"
			end
		elseif ( action == "delete" ) then
			if ( deleteResource ( getResourceFromName ( name ) ) ) then
				text = "deleted"
			end
		elseif ( action == "stopall" ) then
			if ( stopAllResources ( ) ) then
				text = "All Stopped"
			end
		end
isso tudo está acima da linha que enviei anteriormente
Link to comment
On 26/01/2023 at 15:31, yToPzz said:
addEvent ( "aResource", true )
addEventHandler ( "aResource", root, function ( name, action )
	if checkClient( "command."..action, source, 'aResource', action ) then return end
	local pname = getPlayerName ( source )
	if ( hasObjectPermissionTo ( client or source, "command."..action ) ) then
		local text = ""
		if ( action == "start" ) then
			if ( startResource ( getResourceFromName ( name ), true ) ) then
				text = "started"
			end
		elseif ( action == "restart" ) then
			if ( getResourceState ( getResourceFromName ( name ) ) == "running" ) then
				if ( restartResource ( getResourceFromName ( name ) ) ) then text = "restarted" end
			end
		elseif ( action == "stop" ) then
			if ( stopResource ( getResourceFromName ( name ) ) ) then
				text = "stopped"
			end
		elseif ( action == "delete" ) then
			if ( deleteResource ( getResourceFromName ( name ) ) ) then
				text = "deleted"
			end
		elseif ( action == "stopall" ) then
			if ( stopAllResources ( ) ) then
				text = "All Stopped"
			end
		end
isso tudo está acima da linha que enviei anteriormente

Nesta função aparentemente está tudo certo, mostre como você está referindo os elements no lado client no triggerServerEvent.

Link to comment
  • 2 weeks later...

O erro que está ocorrendo nesse trecho de código é devido à função getAdminNameForLog(source) estar retornando nil ou uma string vazia "", causando assim o erro quando tenta concatenar com a string text.

Para corrigir esse erro, é necessário verificar o que está sendo retornado pela função getAdminNameForLog(source). Verifique se a função está sendo passada corretamente com o parâmetro source e se ela está retornando uma string válida.

Uma maneira de corrigir esse erro é usando um operador ternário para verificar se a função getAdminNameForLog(source) está retornando um valor válido. Se a função retornar nil ou uma string vazia, podemos atribuir um valor padrão, como "Console", por exemplo. Veja o exemplo abaixo:

if (text ~= "") then
    local adminName = getAdminNameForLog(source) or "Console"
    outputServerLog("ADMIN: Resource \'" .. name .. "\' " .. text .. " by " .. adminName)
    for id, player in ipairs(getElementsByType("player")) do
        triggerClientEvent(player, "aClientLog", root, text)
    end
end

Dessa forma, se a função getAdminNameForLog(source) retornar nil ou uma string vazia, o valor padrão "Console" será utilizado. Assim, a string será concatenada corretamente, evitando o erro.

Espero que isso ajude! - Equipe BGS

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