Jump to content

[HELP] table.remove


LabiVila

Recommended Posts

local players = {} 
  
function onjoin () 
    table.insert (players, source) 
     
    setTimer ( 
        function () 
            for k,v in ipairs (players) do 
                if (v == source) then 
                    table.remove (players, k) 
                end 
            end 
            triggerClientEvent ("handler", getRootElement(), players) 
        end, 5000, 1  
    ) 
    triggerClientEvent ("handler", getRootElement(), players) 
end 
addEventHandler ("onPlayerJoin", getRootElement(), onjoin) 
  
function handler (players) 
    addEventHandler ("onClientRender", getRootElement(), 
        function () 
            for i,v in ipairs (players) do 
                dxDrawText (i.." "..getPlayerName (v), 200, 200 + (i * 21)) 
            end 
        end 
    ) 
end 
addEvent ("handler", true) 
addEventHandler ("handler", getRootElement(), handler) 

so, 5 seconds after joining, the text should dissapear, but it is not dissapearing, it is most likely table.remove that isn't working, can I have some help?

Link to comment

setTimer has its own 'source' predefined variable, you must pass it as an argument,

  
setTimer ( 
        function (player) 
            for k,v in ipairs (players) do 
                if (v == player) then 
                    table.remove (players, k) 
                end 
            end 
            triggerClientEvent ("handler", getRootElement(), players) 
        end, 5000, 1, source 
    ) 
  

Link to comment

You should break after removing the player, so it doesn't uselessly loop through the rest of the table.

  
setTimer ( 
        function (player) 
            for k,v in ipairs (players) do 
                if (v == player) then 
                    table.remove (players, k) 
                    break 
                end 
            end 
            triggerClientEvent ("handler", resourceRoot, players) 
        end, 5000, 1, source 
    ) 
  

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