William147 Posted March 18, 2016 Share Posted March 18, 2016 Hello! I have a little problem with scoreboard. I took out it from roleplay mod, and I would like to make it to DayZ mod. The problem is that, when 2 players online then 2 times write me to scoreboard, so I think "player" value isn't right. How can I fix it? local sx,sy = guiGetScreenSize () local scoreboardState = false local font = dxCreateFont ("files/myriadproregular.ttf",13) local data = {} local slots = 300 local serverName = "" local g_oldControlStates local SCOREBOARD_DISABLED_CONTROLS = { "next_weapon", -- Controls that are disabled when the scoreboard is showing "previous_weapon", "aim_weapon", "radio_next", "radio_previous" } function loadScoreboardData () data.ids = {} data.players = {} local players = getElementsByType ("player") for k,v in ipairs(players) do if v ~= getLocalPlayer() then local ID = getElementData (v,"id") table.insert(data.players,ID) data.ids[ID] = v end end table.sort (data.players) local ID = getElementData(getLocalPlayer(),"playerid") data.ids[ID] = getLocalPlayer() table.insert(data.players,1,ID) data.length = #data.players --data.slots = maxP --data.serverName = sName data.maxHeight = 800 if sy-200 <= data.maxHeight then data.maxHeight = sy-200 end end function renderScoreboard () local pHeight = 24 local middleHeight = pHeight*data.length+20 if middleHeight > data.maxHeight-128-32 then middleHeight = data.maxHeight-128-32 end local totalHeight = data.maxHeight--128+middleHeight+32 local contentY = sy/2-middleHeight/2 local topY = contentY-128 local contentX = sx/2-900/2 local col = tocolor(255,255,255,255) local maxRows = math.floor(middleHeight/pHeight)--math.floor((data.maxHeight-128-32)/middleHeight) local maxRow = data.currentRow+maxRows-1 dxDrawImage (contentX,topY,900,128,"files/top.png",0,0,0,col,true) dxDrawImage (contentX,contentY,900,middleHeight,"files/bg.png",0,0,0,col,true) dxDrawImage (contentX,contentY+middleHeight,900,56,"files/bottom.png",0,0,0,col,true) local nameY = topY+50 local nameX = sx/2+900/2 - 45 local countY = nameY+16 local countX = nameX --dxDrawText (serverName,0,nameY,nameX,0,tocolor(255,255,255,255),0.8,font,"right","top",false,false,true) --dxDrawText ("" .. data.length .. "/" .. slots .. " játékos",0,countY,countX,0,tocolor(73,149,255,255),0.8,font,"right","top",false,false,true,true) local idX = 43 local nameX = 83 local gpX = 280 local pingX = 432 local lineX = 23 local n = 0 for k,v in ipairs(data.players) do if k >= data.currentRow then if k <= maxRow then local ID = v local player = data.ids[ID] if player and isElement(player) then n = n+1 local name = getPlayerName (player) --local r,g,b = getPlayerNametagColor (player) local ping = getPlayerPing (player) --local gp = getElementData (player,"gamescore") or 0 local zombieskilled = getElementData(player,"zombieskilled") local headshots = getElementData(player,"headshots") local murders = getElementData(player,"murders") local totalkills = getElementData(player,"totalkills") local daysalive = getElementData(player,"daysalive") if getElementData(player,"humanity") < 1 then r,g,b = 164,0,0 elseif getElementData(player,"humanity") > 4999 then r,g,b = 0,200,0 else r,g,b = 255,255,255 end if name and r and ping then local cY = contentY+(pHeight*(n-1)) --local path = "files/line.png" if n/2 ~= math.floor(n/2) then --path = "files/line2.png" dxDrawImage (contentX+lineX,cY,900-lineX*2,32,"files/line2.png",0,0,0,col,true) end --dxDrawText (ID,contentX+idX,cY,0,0,tocolor(150,150,150,150),0.9,font,"left","top",false,false,true) dxDrawText (tostring(name),contentX+nameX,cY,0,0,tocolor(r,g,b,255),0.9,font,"left","top",false,false,true,true) dxDrawText (tostring(zombieskilled),contentX+gpX,cY,0,0,tocolor(150,150,150,150),0.9,font,"left","top",false,false,true) dxDrawText (tostring(headshots),contentX+pingX,cY,0,0,tocolor(150,150,150,150),0.9,font,"left","top",false,false,true) dxDrawText (tostring(murders),contentX+595,cY,0,0,tocolor(150,150,150,150),0.9,font,"left","top",false,false,true) dxDrawText (tostring(daysalive),contentX+750,cY,0,0,tocolor(150,150,150,150),0.9,font,"left","top",false,false,true) end end else break end end end end addEvent ("onScoreboardDataLoad",true) addEventHandler ("onScoreboardDataLoad",getRootElement(), function (maxP,sName) --[[if scoreboardState == false then loadScoreboardData (maxP,sName) data.currentRow = 1 scoreboardState = true addEventHandler ("onClientRender",getRootElement(),renderScoreboard) end]] --data.slots = maxP --data.serverName = sName slots = maxP serverName = sName end ) function scoreboardCMD (key,state) --outputChatBox ("key: " .. key .. " state: " .. tostring(state)) if state == "down" then if scoreboardState == false then g_oldControlStates = {} for k, control in ipairs ( SCOREBOARD_DISABLED_CONTROLS ) do g_oldControlStates[k] = isControlEnabled ( control ) toggleControl ( control, false ) end --triggerServerEvent ("onCallForData",getLocalPlayer()) loadScoreboardData (maxP,sName) data.currentRow = 1 scoreboardState = true addEventHandler ("onClientRender",getRootElement(),renderScoreboard) end elseif state == "up" then if scoreboardState == true then for k, control in ipairs ( SCOREBOARD_DISABLED_CONTROLS ) do toggleControl ( control, g_oldControlStates[k] ) end g_oldControlStates = nil removeEventHandler ("onClientRender",getRootElement(),renderScoreboard) scoreboardState = false data = {} end end end bindKey ("tab","both",scoreboardCMD) function playerPressedKey(button, press) if scoreboardState then if button == "mouse_wheel_up" then if data.currentRow > 1 then data.currentRow = data.currentRow-10 end elseif button == "mouse_wheel_down" then local maxRows = data.length local middleHeight = data.maxHeight-128-32--pHeight*data.length+20 local pHeight = 24 local maxVisRows = math.floor(middleHeight/pHeight) local maxRows = maxRows-maxVisRows if data.currentRow < maxRows then data.currentRow = data.currentRow+10 end end end end addEventHandler("onClientKey", getRootElement(), playerPressedKey) --[[♠addEventHandler ("onClientResourceStart",getResourceRootElement(), function () triggerServerEvent ("onCallForData",getLocalPlayer()) end )]]-- addEventHandler("onClientPlayerJoin", getRootElement(), function () if scoreboardState then setTimer (loadScoreboardData,100,1) end end ) addEventHandler("onClientPlayerQuit", getRootElement(), function () if scoreboardState then setTimer (loadScoreboardData,100,1) end end ) Link to comment
Captain Cody Posted March 18, 2016 Share Posted March 18, 2016 function loadScoreboardData () data.ids = nil data.players = nil data.ids = {} data.players = {} local players = getElementsByType ("player") for k,v in ipairs(players) do if v ~= getLocalPlayer() then local ID = getElementData (v,"id") table.insert(data.players,ID) data.ids[ID] = v end end table.sort (data.players) local ID = getElementData(getLocalPlayer(),"playerid") data.ids[ID] = getLocalPlayer() table.insert(data.players,1,ID) data.length = #data.players --data.slots = maxP --data.serverName = sName data.maxHeight = 800 if sy-200 <= data.maxHeight then data.maxHeight = sy-200 end end Replace first part with this, clears the table. Originally it just added onto the already existent table thus, doubling the values. Link to comment
William147 Posted March 19, 2016 Author Share Posted March 19, 2016 Today came error: attempt to compare two boolean values How can I fix it? Link to comment
William147 Posted March 19, 2016 Author Share Posted March 19, 2016 Error is only this: attempt to compare two boolean values Link to comment
Captain Cody Posted March 20, 2016 Share Posted March 20, 2016 Does it give you the line of code?? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now