Karuzo Posted February 15, 2014 Share Posted February 15, 2014 Hey Guys, so i have a problem, i wanted to let my scoreboard scroll, but that doesn't really work. The blocking if you reach the bottom position works, but idk how i could do that with the top position. Hope you understood me and can help me local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local offset = 0 function offsetplus() if offset+20 > 0 then return end--Bottom Position offset = offset+20 end function offsetneg()--Top Position, here i want the block! offset = offset-20 end playersO = #getElementsByType ( "player" ) local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end ) function Scoreboard() dxDrawImage(X,Y,Width,Height, "Scoreboard/images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) local players = getElementsByType ( "player" ) local playas = 0 local playerheight = 20 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = false if teamp then teamn = getTeamName(teamp) end if (teamp) then dxDrawText(teamn, X+350,Y+60+playerheight*(amt-1)+offset,Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) else dxDrawText("Keine", X+350,Y+60+playerheight*(amt-1)+offset,Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end local money = tonumber ( getElementData(player, "playerMoney") ) or 0 if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end dxDrawText(getPlayerName ( player ), X+60,Y+60+playerheight*(amt-1)+offset, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping,X+480,Y+60+playerheight*(amt-1)+offset, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText( tostring ( money ) .." $", X+210,Y+60+playerheight*(amt-1)+offset,Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350,Y+60+playerheight*(amt-1)+offset,Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Link to comment
Karuzo Posted February 15, 2014 Author Share Posted February 15, 2014 hey, i really need help with this. //400th post Link to comment
Moderators Citizen Posted February 16, 2014 Moderators Share Posted February 16, 2014 ok try this (didn't test it): local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 function offsetplus() if offset >= (#getElementsByType ( "player" ))-nbLinesToDraw then return end --Bottom Position offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) function Scoreboard() dxDrawImage(X,Y,Width,Height, "Scoreboard/images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) local players = getElementsByType ( "player" ) local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end local money = tonumber ( getElementData(player, "playerMoney") ) or 0 if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) I'm using offset to hold how much players I must skip for the loop: if there are 40 players, and offset = 5 then it will skip the 5 first players in the loop and so it will list the 6th player to 26th one. Before testing, use /debugscript 3 and tell me if there are errors once you tested it. To test with 40 players (for example) give the loop a table of string (names) and force the value for ping, money and team. Regards, Citizen Link to comment
Karuzo Posted February 16, 2014 Author Share Posted February 16, 2014 Hey Citizen, first i want to thank you that you take your free-time and help me . How do you mean that : To test with 40 players (for example) give the loop a table of string (names) and force the value for ping, money and team. ? Could you give me an example please ? It shows the scoreboard, but as i said i can't test it Regards, KRZO. Link to comment
Moderators Citizen Posted February 16, 2014 Moderators Share Posted February 16, 2014 Wasn't that hard, hope you could do it yourself: local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 function offsetplus() if offset >= (#getElementsByType ( "player" ))-nbLinesToDraw then return end --Bottom Position offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) ----- Generating a list of names ------ local fakelist = {} for k=1, 40 do table.insert(fakelist, "Player"..k) end --------------------------------------- function Scoreboard() dxDrawImage(X,Y,Width,Height, "Scoreboard/images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) -- local players = getElementsByType ( "player" ) local players = fakelist -- uncomment only for testing local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then -- local ping = getPlayerPing(player) local ping = 65 -- uncomment only for testing -- local teamp = getPlayerTeam(player) local teamp = nil -- uncomment only for testing local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end -- local money = tonumber ( getElementData(player, "playerMoney") ) or 0 local money = 1200 -- uncomment only for testing if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line -- dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(player, X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) EDIT: Fixed the render of the name Link to comment
Karuzo Posted February 16, 2014 Author Share Posted February 16, 2014 Thank you, but it looks like this atm : http://prntscr.com/2t0h26 i can't find the problem. My Code : local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 playersO = #getElementsByType ( "player" ) function offsetplus() if offset >= (#getElementsByType ( "player" ))-nbLinesToDraw then return end --Bottom Position offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) ----- Generating a list of names ------ local fakelist = {} for k=1, 40 do table.insert(fakelist, "Player"..k) end --------------------------------------- function Scoreboard() dxDrawImage(X,Y,Width,Height, "/images/back.png") dxDrawImage(X, Y, 549, 42,"/images/bar.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) -- local players = getElementsByType ( "player" ) local players = fakelist -- uncomment only for testing local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then -- local ping = getPlayerPing(player) local ping = 65 -- uncomment only for testing -- local teamp = getPlayerTeam(player) local teamp = nil -- uncomment only for testing local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end -- local money = tonumber ( getElementData(player, "playerMoney") ) or 0 local money = 1200 -- uncomment only for testing if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line -- dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(player, X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Link to comment
Karuzo Posted February 16, 2014 Author Share Posted February 16, 2014 Hey, sorry for doublepost but can't delete my post :3 So it works everything, but not the bottom position block, local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 playersO = #getElementsByType ( "player" ) function offsetplus() if offset == playersO-nbLinesToDraw then return end offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) local fakelist = {} for k=1, 40 do table.insert(fakelist, "Player"..k) end function Scoreboard() dxDrawImage(X,Y,Width,Height, "/images/back.png") dxDrawImage(X, Y, 549, 42,"/images/bar.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) --local players = getElementsByType ( "player" ) local players = fakelist -- uncomment only for testing local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then --local ping = getPlayerPing(player) local ping = 65 -- uncomment only for testing --local teamp = getPlayerTeam(player) local teamp = nil -- uncomment only for testing local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end --local money = tonumber ( getElementData(player, "playerMoney") ) or 0 local money = 500-- uncomment only for testing if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line if tmpY > Y and tmpY < Y+400 then --dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(player, X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Link to comment
Moderators Citizen Posted February 16, 2014 Moderators Share Posted February 16, 2014 You mean the vertical scroll ? if so then it works, but I just forgot to use the number of fake players (I used getElementsByType("player") so yeah). playersO = #getElementsByType ( "player" ) Why dafuq did you do that ?? I removed it wasn't suppose to come back. If you do that, then players0 will be the same all the time, even if someone joins or quit the server so please put it back (don't brake the fixes ...) local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 function offsetplus() -- if offset >= (#getElementsByType ( "player" ))-nbLinesToDraw then return end --Bottom Position if offset >= (#fakelist)-nbLinesToDraw then return end -- uncomment only for testing offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) ----- Generating a list of names ------ local fakelist = {} for k=1, 40 do table.insert(fakelist, "Player"..k) end --------------------------------------- function Scoreboard() dxDrawImage(X,Y,Width,Height, "Scoreboard/images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) -- local players = getElementsByType ( "player" ) local players = fakelist -- uncomment only for testing local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then -- local ping = getPlayerPing(player) local ping = 65 -- uncomment only for testing -- local teamp = getPlayerTeam(player) local teamp = nil -- uncomment only for testing local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end -- local money = tonumber ( getElementData(player, "playerMoney") ) or 0 local money = 1200 -- uncomment only for testing if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line -- dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(player, X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Send back a screenshot to see what we need to fix or the final result if everything is done. (There is a big empty area at the top, under the header, fix it my seting 60 lower (for example 40)) Regards, Citizen Link to comment
Karuzo Posted February 17, 2014 Author Share Posted February 17, 2014 Well i used playersO to show the players which are currently playing in the server as you can see in this line : dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) There is a big empty area at the top, under the header, fix it my seting 60 lower (for example 40)) Nah, not really , i just have a "rectangel" and the bar where the Names , Teams ,etc.. stand so it's easier for me . So lets get back to the problem : As you can see it stops at Player37 and i can't scroll anymore , why ? here's my code : local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) local playerheight = 20 --Better to be here as it's a constant local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time local offset = 0 local fakelist = {} for k=1, 40 do table.insert(fakelist, "Player"..k) end playersO = #getElementsByType ( "player" ) function offsetplus() if offset >= (#fakelist)-nbLinesToDraw then return end offset = offset + 1 end function offsetneg() if offset <= 0 then return end --Top Position offset = offset - 1 end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end) function Scoreboard() dxDrawImage(X,Y,Width,Height, "/images/back.png") dxDrawImage(X, Y, 549, 42,"/images/bar.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(playersO.."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Fraktion", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) --local players = getElementsByType ( "player" ) local players = fakelist -- uncomment only for testing local line = 0 --the current line number - 1 for k, player in pairs(players) do -- we will draw if we are at the right offset AND if we still didn't draw [nbLinesToDraw] lines (here 20) if k > offset and line <= nbLinesToDraw then --local ping = getPlayerPing(player) local ping = 67 -- uncomment only for testing --local teamp = getPlayerTeam(player) local teamp = nil -- uncomment only for testing local teamn = "Keine" if teamp then teamn = getTeamName(teamp) end --local money = tonumber ( getElementData(player, "playerMoney") ) or 0 local money = 500-- uncomment only for testing if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end local tmpY = Y+60+playerheight*line if tmpY > Y and tmpY < Y+400 then --dxDrawText(getPlayerName( player ), X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(player, X+60, tmpY, Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping, X+480, tmpY, Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(tostring( money ).." $", X+210, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350, tmpY, Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end line = line + 1 end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then bindKey("mouse_wheel_down", "down", offsetplus) bindKey("mouse_wheel_up", "down", offsetneg) addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else offset = 0 unbindKey("mouse_wheel_down", "down", offsetplus) unbindKey("mouse_wheel_up", "down", offsetneg) removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Link to comment
Moderators Citizen Posted February 17, 2014 Moderators Share Posted February 17, 2014 Well i used playersO to show the players which are currently playing in the server Nope, it will show show the number of players who were playing when the script has been loaded (so when you joined the server) That's a big difference ! Because you never update it anywhere. Imagine the following situation. You join the server, the script is loaded and your playersO = #getElementsByType( "player" ) will be executed and will be 1. So atm, everything is fine. Now a second player joins, that player will load that script and HIS playersO = #getElementsByType( "player" ) will be executed will return 2. Which is correct for him. But what happened to your players0 ?? Nothing, Absolutly nothing, YOUR players0 variable is still equal to 1 so for you it will still show 1/50 instead of 2/50 because you didn't update it when another player joined. Hope it's clear now. So there are two solutions: 1st solution (easy, for lazy coders), get get the number of players every time you want to draw it: local nbPlayers = #getElementsByType( "player" ) dxDrawText(nbPlayers.."/50", X, Y-15, Width, Y, tocolor(255, 255, 255, 255), 1.00, "default-bold", "right", "center", false, false, false, false, false) 2nd solution (cleaner), update the number of players everytime someone joins or quit: local nbPlayers = #getElementsByType("player") function updateNbPlayers(arg) nbPlayers = #getElementsByType("player") end addEventHandler("onClientPlayerJoin", root, updateNbPlayers) addEventHandler("onClientPlayerQuit", root, updateNbPlayers) Of course, replace players0 by nbPlayers in the dxDrawText (better name than players0) _________________________________ (just saw your #push and it isn't allowed ... and btw, I wasn't at home the whole day so ... be patient) So lets get back to the problem : As you can see it stops at Player37 and i can't scroll anymore , why ? Haha, because you broke my code dude with your dirty "fix": if tmpY > Y and tmpY < Y+400 then --I removed the code cuz it is useless to show end I made this variable: local nbLinesToDraw = 20 -- the number of lines that will be drawn at the same time Why didn't you use that variable ?? Maybe because you didn't read/understand the comment ? So if 20 lines was too much to fit the table, just modify that variable to something lower. In your case, the table only can show up to 17 lines at a time, so just set that variable to 17: local nbLinesToDraw = 17 -- the number of lines that will be drawn at the same time Test it again. 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