Jump to content

[HELP] Top 3


LabiVila

Recommended Posts

Hey guys, if I've got a distance to a marker script, how can I get the top three closest players to that marker? I mean for example if I've got only 20 meters left (less than any other player), the dxDrawText shows: 1. LabiVila, 2. ..., 3. ..., you know? Where player "2" and player "3" have got less meters to go than the rest?

Link to comment
  
local topThree = {} 
local marker = createMarker(0, 0, 5, "checkpoint", 3) 
  
function topThreePlayers(thePlayer) 
for i, v in ipairs(getAlivePlayers()) do 
local x, y, z = getElementPosition(i) 
topThree[i] = getDistanceBetweenPoints3D(i, getElementPosition(marker)) -- You can only add functions with multiple arguments at the end! 
end 
-- Now we've got a table with all the alive players, sort it 
table.sort(topThree) 
for i = 1, 3 do 
outputChatBox("#"..i..":"..getPlayerName(topThree[i]), thePlayer, 0, 255, 0) 
end 
addCommandHandler("top3", topThreePlayers, false) 
  

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