iiv03 Posted January 11, 2020 Share Posted January 11, 2020 how make the number if the highest moves the player in the first place like toptime). what do I use? Loop and executeSQLQuery? Link to comment
ReZurrecti0n Posted January 11, 2020 Share Posted January 11, 2020 local highestping=0 local playername for loop,target in ipairs(getElementsByType("player"))do if(getPlayerPing(target)>highestping)then highestping=getPlayerPing(target) playername=getPlayerName(target) end end if(playername)then print("Player "..playername.." has the highest ping ("..highestping..")") Of course you will need to modify the values to your own code for (toptime), but it could be done with something like this... If I am understanding what you're saying correctly anyway Link to comment
iiv03 Posted January 11, 2020 Author Share Posted January 11, 2020 5 hours ago, ReZurrecti0n said: local highestping=0 local playername for loop,target in ipairs(getElementsByType("player"))do if(getPlayerPing(target)>highestping)then highestping=getPlayerPing(target) playername=getPlayerName(target) end end if(playername)then print("Player "..playername.." has the highest ping ("..highestping..")") Of course you will need to modify the values to your own code for (toptime), but it could be done with something like this... If I am understanding what you're saying correctly anyway i just want to know in your code how set that in dxDrawText like what say in above if he got top value number move in place first Link to comment
Simple0x47 Posted January 11, 2020 Share Posted January 11, 2020 Since you are talking about 'top value', I suppose you've got a table, whose indexes are numerical, which contains the players. If you draw the text within a loop, which goes through all the elements of the previously mentioned table, you can easily edit the order of the players by assigning them to a different index within the table. In the case you don't have a loop whose indexes are numerical, try to implement one to keep it easy. 1 Link to comment
iiv03 Posted January 12, 2020 Author Share Posted January 12, 2020 (edited) 18 hours ago, Simple0x47 said: Since you are talking about 'top value', I suppose you've got a table, whose indexes are numerical, which contains the players. If you draw the text within a loop, which goes through all the elements of the previously mentioned table, you can easily edit the order of the players by assigning them to a different index within the table. In the case you don't have a loop whose indexes are numerical, try to implement one to keep it easy. do you mean like this? local theplayers = {} for i,player in pairs(players) do local thetables = {name = getPlayerName(player), alive = getElementData(player,"state") == "alive", points = getElementData(player,"ThePoints") or "0"} table.insert(theplayers, thetables) table.sort(theplayers, function(a, b) return a.points > b.points end ) end Edited January 12, 2020 by xFabel Link to comment
iiv03 Posted January 12, 2020 Author Share Posted January 12, 2020 EDIT: it's work with table.sort thanks guys Link to comment
Simple0x47 Posted January 12, 2020 Share Posted January 12, 2020 Well since your code uses the same logic, here's a more efficient way to do it: local playerElements = getElementsByType( "player" ) local players = {} for i = 1, #playerElements do local player = playerElements[ i ] players[ i ] = { name = getPlayerName(player), alive = getElementData(player,"state") == "alive", points = tonumber( getElementData(player,"ThePoints")) or 0 } end table.sort( players, function( a, b ) return a.points > b.points end ) 1 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