Narutimmy Posted May 3, 2015 Share Posted May 3, 2015 Hola mucho gusto pasa que tengo este scoreboard pero me muestra a los usuarios en desorden y poniendome en 1... queria ponerlo en top tomando en cuenta algun varlo por ejemplo el numero de kills. el de mas kills sea el nuemero 1 y asi... Gracias. addEventHandler( "onClientRender", root, function() if getKeyState( "tab" ) == false then ploff = 0; return end if getElementData(getLocalPlayer(),"logedin") then dxDrawRectangle ( baseX, baseY, width, topsize, tocolor(32,32,32),true,false ) dxDrawText ( serverName, baseX+20, baseY+10, baseX+width, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold","left","top",false,false,true ) dxDrawRectangle ( baseX, baseY+topsize, width, panelsize, tocolor(0,0,0,150),true,false ) dxDrawLine ( baseX, baseY+30, baseX+width, baseY+30, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+30, baseX, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+panelsize+topsize, baseX+width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX+40, baseY+30, baseX+40, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( "№", baseX, baseY+60, baseX+40, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) local xoff = 60 for i, v in ipairs ( scoreboardColumns ) do dxDrawLine ( baseX+xoff+v.width, baseY+30, baseX+xoff+v.width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( v.name, baseX+xoff, baseY+60, baseX+xoff+v.width, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+v.width end local playersTable = getElementsByType ( "player" ) --local playersTable = { localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer } dxDrawText ( "Online: "..tostring(#playersTable).."/"..tostring(max_players), baseX+20, baseY+10, baseX+width-20, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold", "right","top",false,false,true ) local maxNum = #playersTable if maxNum > 25 then maxNum = 25 end for i = 1, maxNum do dxDrawLine ( baseX, baseY+topsize+playersize*i, baseX+width, baseY+topsize+playersize*i, tocolor(100,100,100),0.8,true ) dxDrawText ( i+ploff, baseX, baseY+topsize+playersize*(i-1), baseX+40, baseY+topsize+playersize*i, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) if playersTable[i+ploff] == localPlayer then dxDrawRectangle ( baseX, baseY+topsize+playersize*(i-1), width, playersize, tocolor(112,112,112,100),true,false ) end local xoff = 60 for c, d in ipairs ( scoreboardColumns ) do local data = d.data(playersTable[i+ploff]) local r,g,b = 255,255,255 if d.name == "grupo" and data == "none" then r,g,b = 0,255,0 data = "Sin Grupo" end dxDrawText ( data, baseX+xoff, baseY+topsize+playersize*(i-1), baseX+xoff+d.width, baseY+topsize+playersize*i, tocolor(r,g,b), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+d.width end end end end ) Link to comment
Tomas Posted May 3, 2015 Share Posted May 3, 2015 function getTableSortedByKills ( ) tSS = {} tSS_f = {} for index, value in ipairs(getElementsByType("player")) do tSS[value] = getElementData(value, "kills"), value end for k,v in spairs(tSS, function(t,a,b) return t[b] < t[a] end) do tSS_f[#tSS_f] = k end return tSS_f end function spairs(t, order) local keys = {} for k in pairs(t) do keys[#keys+1] = k end if order then table.sort(keys, function(a,b) return order(t, a, b) end) else table.sort(keys) end local i = 0 return function() i = i + 1 if keys[i] then return keys[i], t[keys[i]] end end end addEventHandler( "onClientRender", root, function() if getKeyState( "tab" ) == false then ploff = 0; return end if getElementData(getLocalPlayer(),"logedin") then dxDrawRectangle ( baseX, baseY, width, topsize, tocolor(32,32,32),true,false ) dxDrawText ( serverName, baseX+20, baseY+10, baseX+width, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold","left","top",false,false,true ) dxDrawRectangle ( baseX, baseY+topsize, width, panelsize, tocolor(0,0,0,150),true,false ) dxDrawLine ( baseX, baseY+30, baseX+width, baseY+30, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+30, baseX, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+panelsize+topsize, baseX+width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX+40, baseY+30, baseX+40, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( "№", baseX, baseY+60, baseX+40, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) local xoff = 60 for i, v in ipairs ( scoreboardColumns ) do dxDrawLine ( baseX+xoff+v.width, baseY+30, baseX+xoff+v.width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( v.name, baseX+xoff, baseY+60, baseX+xoff+v.width, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+v.width end local playersTable = getTableSortedByKills ( ) --local playersTable = { localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer } dxDrawText ( "Online: "..tostring(#playersTable).."/"..tostring(max_players), baseX+20, baseY+10, baseX+width-20, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold", "right","top",false,false,true ) local maxNum = #playersTable if maxNum > 25 then maxNum = 25 end for i = 1, maxNum do dxDrawLine ( baseX, baseY+topsize+playersize*i, baseX+width, baseY+topsize+playersize*i, tocolor(100,100,100),0.8,true ) dxDrawText ( i+ploff, baseX, baseY+topsize+playersize*(i-1), baseX+40, baseY+topsize+playersize*i, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) if playersTable[i+ploff] == localPlayer then dxDrawRectangle ( baseX, baseY+topsize+playersize*(i-1), width, playersize, tocolor(112,112,112,100),true,false ) end local xoff = 60 for c, d in ipairs ( scoreboardColumns ) do local data = d.data(playersTable[i+ploff]) local r,g,b = 255,255,255 if d.name == "grupo" and data == "none" then r,g,b = 0,255,0 data = "Sin Grupo" end dxDrawText ( data, baseX+xoff, baseY+topsize+playersize*(i-1), baseX+xoff+d.width, baseY+topsize+playersize*i, tocolor(r,g,b), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+d.width end end end end ) Link to comment
Narutimmy Posted May 4, 2015 Author Share Posted May 4, 2015 function getTableSortedByKills ( ) tSS = {} tSS_f = {} for index, value in ipairs(getElementsByType("player")) do tSS[value] = getElementData(value, "kills"), value end for k,v in spairs(tSS, function(t,a,b) return t[b] < t[a] end) do ---Linea 47 tSS_f[#tSS_f] = k end return tSS_f end function spairs(t, order) local keys = {} for k in pairs(t) do keys[#keys+1] = k end if order then table.sort(keys, function(a,b) return order(t, a, b) end) else table.sort(keys) end local i = 0 return function() i = i + 1 if keys[i] then return keys[i], t[keys[i]] end end end addEventHandler( "onClientRender", root, function() if getKeyState( "tab" ) == false then ploff = 0; return end if getElementData(getLocalPlayer(),"logedin") then dxDrawRectangle ( baseX, baseY, width, topsize, tocolor(32,32,32),true,false ) dxDrawText ( serverName, baseX+20, baseY+10, baseX+width, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold","left","top",false,false,true ) dxDrawRectangle ( baseX, baseY+topsize, width, panelsize, tocolor(0,0,0,150),true,false ) dxDrawLine ( baseX, baseY+30, baseX+width, baseY+30, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+30, baseX, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX, baseY+panelsize+topsize, baseX+width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawLine ( baseX+40, baseY+30, baseX+40, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( "№", baseX, baseY+60, baseX+40, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) local xoff = 60 for i, v in ipairs ( scoreboardColumns ) do dxDrawLine ( baseX+xoff+v.width, baseY+30, baseX+xoff+v.width, baseY+panelsize+topsize, tocolor(100,100,100),0.8,true ) dxDrawText ( v.name, baseX+xoff, baseY+60, baseX+xoff+v.width, baseY+topsize-30, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+v.width end local playersTable = getTableSortedByKills ( ) --local playersTable = { localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer, localPlayer } dxDrawText ( "Online: "..tostring(#playersTable).."/"..tostring(max_players), baseX+20, baseY+10, baseX+width-20, baseY+topsize, tocolor(255,255,255), 0.9, "default-bold", "right","top",false,false,true ) local maxNum = #playersTable if maxNum > 25 then maxNum = 25 end for i = 1, maxNum do dxDrawLine ( baseX, baseY+topsize+playersize*i, baseX+width, baseY+topsize+playersize*i, tocolor(100,100,100),0.8,true ) dxDrawText ( i+ploff, baseX, baseY+topsize+playersize*(i-1), baseX+40, baseY+topsize+playersize*i, tocolor(255,255,255), 1, "default-bold", "center", "center",false,false,true ) if playersTable[i+ploff] == localPlayer then dxDrawRectangle ( baseX, baseY+topsize+playersize*(i-1), width, playersize, tocolor(112,112,112,100),true,false ) end local xoff = 60 for c, d in ipairs ( scoreboardColumns ) do local data = d.data(playersTable[i+ploff]) local r,g,b = 255,255,255 if d.name == "grupo" and data == "none" then r,g,b = 0,255,0 data = "Sin Grupo" end dxDrawText ( data, baseX+xoff, baseY+topsize+playersize*(i-1), baseX+xoff+d.width, baseY+topsize+playersize*i, tocolor(r,g,b), 1, "default-bold", "center", "center",false,false,true ) xoff = xoff+d.width end end end end ) Me da error function getTableSortedByKills ( ) tSS = {} tSS_f = {} for index, value in ipairs(getElementsByType("player")) do tSS[value] = getElementData(value, "KDR"), value end for k,v in spairs(tSS, function(t,a,b) return t[b] < t[a] end) do tSS_f[#tSS_f] = k end return tSS_f end Link to comment
Tomas Posted May 4, 2015 Share Posted May 4, 2015 A mi me funcionó en el test t_T, quizás el problema lo causa alguien sin KDR, intenta con esto: function getTableSortedByKills ( ) tSS = {} tSS_f = {} for index, value in ipairs(getElementsByType("player")) do tSS[value] = getElementData(value, "KDR") or 0, value end for k,v in spairs(tSS, function(t,a,b) return t[b] < t[a] end) do tSS_f[#tSS_f] = k end return tSS_f end Link to comment
Narutimmy Posted May 4, 2015 Author Share Posted May 4, 2015 A mi me funcionó en el test t_T, quizás el problema lo causa alguien sin KDR, intenta con esto: function getTableSortedByKills ( ) tSS = {} tSS_f = {} for index, value in ipairs(getElementsByType("player")) do tSS[value] = getElementData(value, "KDR") or 0, value end for k,v in spairs(tSS, function(t,a,b) return t[b] < t[a] end) do tSS_f[#tSS_f] = k end return tSS_f end Mismo Problema Link to comment
Bc# Posted May 5, 2015 Share Posted May 5, 2015 Googlea Estructuras de datos, para que te orientes un poco, hay muchos mecanismos de ordenamiento ya programados, generalmente los mas fáciles son los menos optimos. Te dejo un link (para variar de wikipedia xdd) explicando mas menos el tema: http://es.wikipedia.org/wiki/Algoritmo_de_ordenamiento EDIT* Para orientarlos un poco mas miren un ejemplo de el mecanismo de ordenamiento Bubble Sort, que no es el mas optimo de todos, pero cuando se tratan de pocos datos es efectivo. Codigo: function bubbleSort(A) local itemCount=#A local hasChanged repeat hasChanged = false itemCount=itemCount - 1 for i = 1, itemCount do if A[i] > A[i + 1] then A[i], A[i + 1] = A[i + 1], A[i] hasChanged = true end end until hasChanged == false end Ejemplo: list = { 5, 6, 1, 2, 9, 14, 2, 15, 6, 7, 8, 97 } bubbleSort(list) for i, j in pairs(list) do print(j) end Esta función la pueden adecuar para que les ordene la tabla de jugadores cada vez que lo requieran. Link to comment
Narutimmy Posted May 6, 2015 Author Share Posted May 6, 2015 Me creerias si te digo que no entendi mucho ? Link to comment
Bc# Posted May 6, 2015 Share Posted May 6, 2015 Por lo mismo te dije que googlearas, no es algo que se aprenda con un simple ejemplo. Link to comment
Recommended Posts