Sign in to follow this  
Deadmau5

Spectators always show 0

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) 

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.