I have a problem. when someone comes to the server, in scoreboard disappear all players.
When all players login everything is working.
Userpanel
function onUserStart()
--callScoreboard()
refreshScoreboard()
end
addEventHandler("onResourceStart",resourceRoot,onUserStart)
function callScoreboard()
call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Cash",getRootElement(),70)
call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Points",getRootElement(),70)
call(getResourceFromName("scoreboard"),"scoreboardAddColumn","Rank",getRootElement(),70)
end
function refreshScoreboard()
for i,player in ipairs(getElementsByType("player")) do
if isPlayerLogged(player) then
local playerCash = getDataValue ( player, "cash")
local playerPoints = getDataValue ( player, "points")
setElementData(player,"Cash","$"..playerCash)
setElementData(player,"Points",playerPoints)
setElementData(player,"Rank","?")
else
setElementData(player,"Cash","Guest")
setElementData(player,"Points","Guest")
setElementData(player,"Rank","?")
end
end
end
function refreshNowDatas(player)
--for i,player in ipairs(getElementsByType("player")) do
if isPlayerLogged(player) then
local playerCash = getDataValue ( player, "cash") or "0"
local playerPoints = getDataValue ( player, "points") or "0"
setElementData(player,"Cash","$"..playerCash)
setElementData(player,"Points",playerPoints)
--setElementData(player,"Rank","?")
else
setElementData(player,"Cash","Guest")
setElementData(player,"Points","Guest")
setElementData(player,"Rank","?")
end
--end
end
-- join/login/logout/quit
function playerJoin ()
setElementData(source,"Cash","Guest")
setElementData(source,"Points","Guest")
setElementData(source,"Rank","?")
end
addEventHandler("onPlayerJoin",root,playerJoin)
function playerLogout ()
if isPlayerLogged(source) then
local playerOnline = getTickCount() - getElementData(source,"playerOnline")
addDataValue(source,"online",playerOnline)
end
setElementData(source,"playerOnline","0")
callClientFunction(source,"updateNitroColor")
callClientFunction(source,"setPlayerLoginStatus",false,false)
onPlayerQuitServer(source)
refreshNowDatas(source)
end
addEventHandler("onPlayerLogout",root,playerLogout)
addEventHandler("onPlayerQuit",root,playerLogout)
function playerLogin ()
startDataValue(source)
end
addEventHandler("onPlayerLogin",root,playerLogin)
Scoreboard
local drawScoreboard = function()
uptadePlayers()
showCursor(getKeyState("mouse2"))
local rCount = math.min(#scoreboard-1, rowsCount -1)
start = math.min(#scoreboard - rCount, start)
local c = 0
local cx, cy = 0,0
if isCursorShowing() then
cx, cy = getCursorPosition()
cx = cx * sX
cy = cy * sY
end
local x, y = sX / 2 - 320, sY / 2 - rCount * 20 / 2+25
dxDrawRectangle(x, y-2, 35, rCount * 20+2, tocolor(0, 0, 0, 140))
dxDrawRectangle(x, y-2, 640, rCount * 20+2, tocolor(0, 0, 0, 160))
rotateimage = rotateimage +2
dxDrawRectangle(x, y - 47, 640, 30, tocolor(255,170,0,225))
dxDrawImage( x,y-48, 28,28, "logo.png", 0, 0, 0, tocolor(255,255,255,255) )
dxDrawText("#4fc0e5Ss! #ffffffSoul Stars! ", x + 30, y - 60, x + 640, y, tocolor(255, 255, 255, 255), 1, fonts["bold"][4], "left", "center",false,false,false,true)
dxDrawText(#getElementsByType("player") .. " #4fc0e5/ #ffffff"..ServerMaxPlayer, x + 10, y - 60, x + 630, y, tocolor(255, 255, 255, 255), 1,fonts["bold"][3], "right", "center",false,false,false,true)
dxDrawRectangle(x, y-17, 640, 15, tocolor(15,15,15,225))
dxDrawText("#", x+15 , y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Name", x +40, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Country", x +195, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Cash", x +280, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Points", x +370, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Rank", x +425, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("State", x +470, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("FPS", x +540, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
dxDrawText("Ping", x +600, y-20, x + 640, y, tocolor(220,220,220, 255), 1, fonts["bold"][2], "left", "center")
for id,element in ipairs(scoreboard) do
if start < id and id <= start + rCount then
c = c + 1
if element[1] == "player" and isElement(element[2]) then
if isCursorShowing() and x <= cx and cx < x + 640 and y + (c - 1) * 20 <= cy and cy < y + (c) * 20 then
dxDrawRectangle(x + 35, y-1 + (c - 1) * 20, 605, 20, tocolor(255, 255, 255, 50))
end
local r, g, b = 255, 255, 255
if getPlayerTeam(element[2]) then
r, g, b = getTeamColor(getPlayerTeam(element[2]))
end
local RainbowColorNameHex = getElementData(element[2],"donatorRainbowColorNameHEX") or ""
if not getElementData(element[2], "AFK") then
dxDrawText(RainbowColorNameHex..element[3], x + 40, y-5 + (c - 1) * 20, x + 200, y + (c) * 20, tocolor(r, g, b, 255), 1, "default-bold", "left", "center", false, false, false, true)
else
dxDrawText(RainbowColorNameHex..element[3], x + 68, y-5 + (c - 1) * 20, x + 200, y + (c) * 20, tocolor(r, g, b, 255), 1, "default-bold", "left", "center", false, false, false, true)
dxDrawText("#ff0000AFK", x + 40, y-5 + (c - 1) * 20, x + 200, y + (c) * 20, tocolor(r, g, b, 255), 1, "default-bold", "left", "center", false, false, false, true)
end
--ID
dxDrawText(getElementData(element[2],"ID") or "?", x, y-5 + (c - 1) * 20, x + 35, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--Country
country = getElementData(element[2],"country") or "?"
dxDrawText(string.upper(country) or "?", x+223, y-5 + (c - 1) * 20, x + 200, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "left", "center")
if country and fileExists("flags/"..country..".png") then
dxDrawImage(x+205, y-5 + (c - 1) * 20+4,16,16,"flags/"..country..".png",0,0,0,tocolor(255,255,255,255))
end
--Cash
local cash
if getElementData(element[2],"Cash") then
cash = "$"..comma_value(getElementData(element[2],"Cash"))
else
cash = "Guest"
end
dxDrawText(cash, x+275, y-5 + (c - 1) * 20, x+275+45, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--Points
local points
if getElementData(element[2],"Points") then
points = comma_value(getElementData(element[2],"Points"))
else
points = "Guest"
end
dxDrawText(points, x+365, y-5 + (c - 1) * 20,x+365+45,y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
---Rank
local rank = getElementData(element[2],"Rank") or 0
dxDrawText(rank..getOrdinalSuffix(rank), x+425, y-5 + (c - 1) * 20, x + 425+35, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--State
dxDrawText(getElementData(element[2],"state") or "waiting", x+465, y-5 + (c - 1) * 20, x + 465+38, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--FPS
dxDrawText(getElementData(element[2],"FPS") or "?", x+535, y-5 + (c - 1) * 20, x + 535+34, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--Ping
dxDrawText(getPlayerPing(element[2]), x+595, y-5 + (c - 1) * 20, x + 595+40, y + (c) * 20, tocolor(255,255,255, 255), 1, "default-bold", "center", "center")
--
elseif element[1] == "team" and isElement(element[2]) then
local r, g, b = getTeamColor(element[2])
dxDrawRectangle(x+35, y + (c - 1) * 20, 605, 20, tocolor(0, 0, 0, 150))
if getTeamName(element[2]) == "Admins" or getTeamName(element[2]) == "Soul Stars!" then
if TextStartTime then
local TextTimeleft = getTickCount() - TextStartTime
local alpha = (TextTimeleft/600)
if(not TextFadeUp)then
alpha = 1 - alpha
end
if(alpha > 1)then alpha = 1 end
if(alpha < 0)then alpha = 0 end
--
local TeamName = getTeamName(element[2])
local progressTeam = math.floor(getEasingValue(alpha, "Linear")*TeamName:len())
if(progressTeam > TeamName:len())then
progressTeam = TeamName:len()
end
local _TeamName = TeamName:sub(1, progressTeam)
dxDrawText(_TeamName, x + 38, y + (c - 1) * 20, x + 150, y + (c) * 20, tocolor(r, g, b, 255), 1, "default-bold", "left", "center")
end
else
dxDrawText(getTeamName(element[2]), x + 38, y + (c - 1) * 20, x + 150, y + (c) * 20, tocolor(r, g, b, 255), 1, "default-bold", "left", "center")
end
end
end
end
end