Jump to content

Rankingboard bug


Recommended Posts

Hey everyone,

I have a small question for you guys, which I just can't find. the rankingboard should normally show the colorcodes of the player that died, but it doesn't it's just white.

client:

local sx,sy = guiGetScreenSize() 
 
RankingBoard = {}
RankingBoard.__index = RankingBoard
 
RankingBoard.instances = {}
 
local screenWidth, screenHeight = guiGetScreenSize()
local topDistance = screenHeight-19*11
local bottomDistance = screenHeight-19*11
local posLeftDistance = screenWidth-120
local nameLeftDistance = 60
local labelHeight = 19
local maxPositions = 11
local rankingBoardEnabled = true
 
posLabel = {}
playerLabel = {}
alphaElem = {}
colorElem = {}
biggestLabelWidth = 0
 
function resetRankingboard ()
    for id, elem in pairs(posLabel) do
        setElementData(elem,"PlayerIsOffline",false)
        setElementData(elem,"spectated",false)
    end
    for i, val in ipairs(spectators) do
        table.remove(spectators, i)
    end
    for id, elem in pairs(posLabel) do
            setElementData(elem,"afkresult",false)
    end
posLabel = {}
playerLabel = {}
spectators = {}    
alphaElem = {}
colorElem = {}
biggestLabelWidth = 0
end
addEvent("onClientMapStopping",true)
addEventHandler ( "onClientMapStopping", getRootElement(), resetRankingboard )
 
function resetSpectators ()
    for i, val in ipairs(spectators) do
        table.remove(spectators, i)
    end
    for id, elem in pairs(posLabel) do
        setElementData(elem,"spectated",false)
    end 
spectators = {}    
end
addEvent("onClientPlayerWasted",true)
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), resetSpectators )
 
function RankingBoard.create(id)
    RankingBoard.instances[id] = setmetatable({ id = id, direction = 'down', labels = {}, position = 0 }, RankingBoard)
    posLabel = {}
    playerLabel = {}
end
 
function RankingBoard.call(id, fn, ...)
    RankingBoard[fn](RankingBoard.instances[id], ...)
end
 
function RankingBoard:setDirection(direction, plrs)
    self.direction = direction
    if direction == 'up' then
        self.highestPos = plrs--#g_Players
        self.position = self.highestPos + 1
    end
end
 
function RankingBoard:add(name, time)
    local position
    local y
    local doBoardScroll = false
    if self.direction == 'down' then
        self.position = self.position + 1
        if self.position > maxPositions then
            return
        end
        y = topDistance + (self.position-1)*labelHeight
    elseif self.direction == 'up' then
        self.position = self.position - 1
        local labelPosition = self.position
        if self.highestPos > maxPositions then
            labelPosition = labelPosition - (self.highestPos - maxPositions)
            if labelPosition < 1 then
                labelPosition = 0
                doBoardScroll = true
            end
        elseif labelPosition < 1 then
            return
        end
        y = topDistance + (labelPosition-1)*labelHeight
    end
    posLabel[name], posLabelShadow = createShadowedLabelFromSpare(nameLeftDistance, y, 20, labelHeight, tostring(self.position) .. '.', 'right')
    if time then
        if not self.firsttime then
            self.firsttime = time
            time = ': ' .. msToTimeStr(time)
        else
            time = ': +' .. msToTimeStr(time - self.firsttime)
        end
    else
        time = ''
    end
    time = ""
    playerLabel[name], playerLabelShadow = createShadowedLabelFromSpare(nameLeftDistance, y, 250, labelHeight, "#FFFFFF"..name)
    table.insert(self.labels, posLabel[name])
    table.insert(self.labels, posLabelShadow)
    table.insert(self.labels, playerLabel[name])
    table.insert(self.labels, playerLabelShadow)
    alphaElem[playerLabel[name]] = 0
    alphaElem[posLabel[name]] = 0
    colorElem[playerLabel[name]] = {30,30,30}
    playSoundFrontEnd(7)
        guiSetAlpha(posLabel[name], 0)
        guiSetAlpha(posLabelShadow, 0)
        guiSetAlpha(playerLabel[name], 0)
        guiSetAlpha(playerLabelShadow, 0)      
    if doBoardScroll then          
        local anim = Animation.createNamed('race.boardscroll', self)
        anim:addPhase({ from = 0, to = 1, time = 500, fn = RankingBoard.scroll, firstLabel = posLabel[name] })
        anim:addPhase({ fn = RankingBoard.destroyLastLabel, firstLabel = posLabel[name] })
        anim:play()
    end
    for id, elem in pairs(playerLabel) do
            local widthRezise1 = dxGetTextWidth(string.gsub( guiGetText(elem), '#%x%x%x%x%x%x', '' ),1.1,"default-bold")
            if widthRezise1 > biggestLabelWidth then
                biggestLabelWidth = widthRezise1
                posLeftDistance = screenWidth-biggestLabelWidth
            end
        end
end
 
function RankingBoard:scroll(param, phase)
    local firstLabelIndex = table.find(self.labels, phase.firstLabel)
    for i=firstLabelIndex,firstLabelIndex+3 do
        guiSetAlpha(self.labels[i], param)
    end
    local x, y
    for i=0,#self.labels/4-1 do
        for j=1,4 do
            x = (j <= 2 and posLeftDistance or nameLeftDistance)
            y = topDistance + ((maxPositions - i - 1) + param)*labelHeight
            if j % 2 == 0 then
                x = x + 1
                y = y + 1
            end
            guiSetPosition(self.labels[i*4+j], sx + x, y, false)
        end
    end
    for i=1,4 do
        guiSetAlpha(self.labels[i], 1 - param)
    end
end
 
function RankingBoard:destroyLastLabel(phase)
    for i=1,4 do
        destroyElementToSpare(self.labels[1])
        guiSetVisible(self.labels[1],false)
        table.remove(self.labels, 1)
    end
    local firstLabelIndex = table.find(self.labels, phase.firstLabel)
    for i=firstLabelIndex,firstLabelIndex+3 do
        guiSetAlpha(self.labels[i], 1)
    end
end
 
function RankingBoard:addMultiple(items)
    for i,item in ipairs(items) do
        self:add(item.name, item.time)
    end
end
 
 
function testing (c,name)
RankingBoard:add(name)
end
--addCommandHandler("addt",testing)
 
function RankingBoard:clear()
    table.each(self.labels, destroyElementToSpare)
    self.labels = {}
end
 
function RankingBoard:destroy()
    self:clear()
    RankingBoard.instances[self.id] = nil
end
 
 
function isPlayerOnline (name)
    for i,sPlayer in ipairs(getElementsByType"player") do
        if getPlayerName(sPlayer) == name then
            playerIsOnline = true
        else
            playerIsOnline = false
        end
    end
    return playerIsOnline
end
 
function RankingBoardAddQuit(playername)
setTimer(
function ()
    for id, elem in pairs(posLabel) do
        if id == playername then  
            setElementData(elem,"PlayerIsOffline",true)
        end 
    end
end,500,1)
end
addEvent("addQuitPlayerToGUI",true)
addEventHandler("addQuitPlayerToGUI",getLocalPlayer(),RankingBoardAddQuit)
 
function RankingBoardAddJoin(playername)
setTimer(
function ()
    for id, elem in pairs(posLabel) do
        if id == playername then  
            setElementData(elem,"PlayerIsOffline",false)
        end 
    end
end,250,1)
end
addEvent("addJoinPlayerToGUI",true)
addEventHandler("addJoinPlayerToGUI",getLocalPlayer(),RankingBoardAddJoin)
 
function RankingBoardAddAFK(playername)
setTimer(
function ()
    for id, elem in pairs(posLabel) do
        if id == playername then  
            setElementData(elem,"afkresult",true)
        end 
    end
end,250,1)
end
addEvent("onAFKKillResult",true)
addEventHandler("onAFKKillResult",getRootElement(),RankingBoardAddAFK)
 
function RankingBoardAddAFK(playername)
setTimer(
function ()
    for id, elem in pairs(posLabel) do
        if id == playername then  
            setElementData(elem,"afkresult",false)
        end
   
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...