Jump to content

Spectators always show 0


Deadmau5

Recommended Posts

Subject says it all...

local x, y = guiGetScreenSize () 
  
local localPlayer = getLocalPlayer() 
  
local spectators = {} 
  
addEvent('addSpectator', true) 
addEvent('removeSpectator', true) 
  
addEventHandler('onClientResourceStart', root, 
    function() 
        triggerServerEvent ('addClient', localPlayer) 
         
        local screenWidth, screenHeight = guiGetScreenSize() 
        g_dxGUI = { 
             
            spectators = dxText:create('Spectators:', 2, screenHeight - dxGetFontHeight(0.0, 'bankgothic')-40, false, 'default-bold', 1, 'left'), 
            spectatorsCount = dxText:create('0', 70, screenHeight - dxGetFontHeight(0.0, 'bankgothic')-40, false, 'default-bold', 1, 'left') 
        } 
        g_dxGUI.spectators:color(255, 128, 0, 255) 
        g_dxGUI.spectatorsCount:color(255, 255, 255, 255) 
    end 
) 
  
addEventHandler('addSpectator', root, 
    function(spectator) 
        table.insert(spectators, spectator) 
    end 
) 
  
addEventHandler('removeSpectator', root, 
    function(spectator) 
        for i, val in ipairs(spectators) do 
            if (val == spectator) then 
                table.remove(spectators, i) 
            end 
        end 
    end 
) 
  
function elementCheck (elem) 
    if elem then 
        if isElement (elem) then 
            if (getElementType (elem) == 'player') then 
                return true 
            end 
        end 
    end 
    return false 
end 
  
function drawSpectators() 
    g_dxGUI.spectatorsCount:text(#spectators) 
end 
addEventHandler('onClientRender', root, drawSpectators) 

Link to comment
  • 3 weeks later...

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