LabiVila Posted September 9, 2014 Share Posted September 9, 2014 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
darhal Posted September 10, 2014 Share Posted September 10, 2014 getDistanceBetweenPoints3D Link to comment
LabiVila Posted September 10, 2014 Author Share Posted September 10, 2014 Yea I've actually done that one time, that's the way I got the distance to the marker (in meters), but I was told there's a way to put the players on a table then loop through it, but not sure how to... Link to comment
darhal Posted September 10, 2014 Share Posted September 10, 2014 get all players in.the race compare their.distance.and.put the first and the second etc Link to comment
LabiVila Posted September 11, 2014 Author Share Posted September 11, 2014 Would you mind giving me the commands as I never did that before Link to comment
crismar Posted September 11, 2014 Share Posted September 11, 2014 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
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