Jump to content

Problema con table.remove


aka Blue

Recommended Posts

Buenas, estoy creando un sistema de nametags cliente y estoy usando tablas, para que así cuando se loguee/desloguee, se muestre o no el texto en cuestión (el nametag). Todo va correcto, el problema que tengo es a la hora de usar table.insert, que sigue renderizando el nombre :S 

local nametags = { }
local font = dxCreateFont( "fuente.ttf" )
addEvent( "nmtgs:onPlayerLogin", true )
addEvent( "nmtgs:onPlayerQuit", true )

addEventHandler( "onClientRender", root,
	function( )
		if #nametags > 0 then
			for i=1, #nametags do
				local player = nametags[i]
				local px, py, pz = getElementPosition( player )
				local x, y, z = getElementPosition( getLocalPlayer( ) )
				local name = getPlayerNametagText( nametags[i] ):gsub("_"," ")
			end
		end
	end
)

function addPlayerToTable( player )
	if player then
		table.insert( nametags, player )
	end
end
addEventHandler( "nmtgs:onPlayerLogin", getRootElement( ), addPlayerToTable )

function removePlayerFromTable( player )
	if player and nametags[ player ] then
		table.remove( nametags, player )
	end
end
addEventHandler( "nmtgs:onPlayerQuit", getRootElement( ), removePlayerFromTable )

¿Alguna idea? Gracias de antemano.

Link to comment
function removePlayerFromTable( player )
   if player and nametags[ player ] then
      for i,v in ipairs(nametags) do
         if v == player then
            table.remove( nametags, i )
            return
         end
      end
   end
end
addEventHandler( "nmtgs:onPlayerQuit", getRootElement( ), removePlayerFromTable )

 

Link to comment
  • Recently Browsing   0 members

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