Jump to content

question move player in first place


iiv03

Recommended Posts

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
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

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.

  • Thanks 1
Link to comment
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 by xFabel
Link to comment

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 )

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...