N98E Posted September 8, 2016 Posted September 8, 2016 (edited) Hello, How I can know who got the most wanted player? I wanna a small code Edited September 9, 2016 by jhxp Changed topic title
BEN. Posted September 8, 2016 Posted September 8, 2016 (edited) https://wiki.multitheftauto.com/wiki/GetPlayerWantedLevel Edited September 8, 2016 by BEN.
KariiiM Posted September 8, 2016 Posted September 8, 2016 (edited) Well, all what you have to do is, to make a loop for all players, using getElementsByType( "player", root ) then, use the function getPlayerWantedLevel as the table index and store the looped players to the table. I coded this small code for you, not tested but it should work fine: [lua] local mostWanted = { } for _, player in ipairs ( getElementsByType ( "player", root ) ) do mostWanted[getPlayerWantedLevel ( player )] = getPlayerName ( player ) end table.sort ( mostWanted, function ( a, b ) return a > b end )[/lua] Edited September 8, 2016 by KariiiM
N98E Posted September 8, 2016 Author Posted September 8, 2016 (edited) Can you make it with cmd like "getwl" [lua]outputChatBox("The most online wanted player is "..mostWanted.."!", player, 255, 255, 0)[/lua] or smth like this. Edited September 8, 2016 by N98E
KariiiM Posted September 8, 2016 Posted September 8, 2016 I improved my code alitle bit, try it and tell me the results: function getMostWantedPlayer ( ) local mostWanted = { } local playerWL = { } for _, player in ipairs ( getElementsByType ( "player", root ) ) do mostWanted[getPlayerWantedLevel ( player )] = getPlayerName ( player ) table.insert ( playerWL, getPlayerWantedLevel ( player ) ) end table.sort ( playerWL, function ( a, b ) return ( a > b ) end ) return mostWanted, playerWL end addCommandHandler ( "gewl", function ( thePlayer ) local mostWanted, playerWL = getMostWantedPlayer ( ) outputChatBox ( "The most online wanted player is ".. tostring ( mostWanted[playerWL[1]] ) .."!", thePlayer, 255, 255, 0 ) end )
MTA Team jhxp Posted September 9, 2016 MTA Team Posted September 9, 2016 Please use more descriptive topic titles in the future, instead of just Help. Thanks. 1
N98E Posted September 9, 2016 Author Posted September 9, 2016 Works fine! but I need to get his wanted points too 1
KariiiM Posted September 9, 2016 Posted September 9, 2016 You have to make a system for wanted points, there's no function that receive wanted points of a specified player.
MTA Team qaisjp Posted September 9, 2016 MTA Team Posted September 9, 2016 (edited) 22 hours ago, KariiiM said: I improved my code alitle bit, try it and tell me the results: function getMostWantedPlayer ( ) local mostWanted = { } local playerWL = { } for _, player in ipairs ( getElementsByType ( "player", root ) ) do mostWanted[getPlayerWantedLevel ( player )] = getPlayerName ( player ) table.insert ( playerWL, getPlayerWantedLevel ( player ) ) end table.sort ( playerWL, function ( a, b ) return ( a > b ) end ) return mostWanted, playerWL end addCommandHandler ( "gewl", function ( thePlayer ) local mostWanted, playerWL = getMostWantedPlayer ( ) outputChatBox ( "The most online wanted player is ".. tostring ( mostWanted[playerWL[1]] ) .."!", thePlayer, 255, 255, 0 ) end ) Here's one that doesn't need tables: function getMostWantedPlayer ( ) local mostWantedPlayer = false local mostWantedLevel = -1 for _, player in ipairs ( getElementsByType ( "player", root ) ) do if getPlayerWantedLevel(player) > mostWantedLevel then mostWantedPlayer = player mostWantedLevel = getPlayerWantedLevel(player) end end return mostWantedPlayer end addCommandHandler ( "gewl", function ( thePlayer ) local mostWanted = getMostWantedPlayer ( ) if not mostWanted then outputChatBox("There are no players on the server") return end outputChatBox ( "The most online wanted player is ".. getPlayerName(mostWanted) .."!", thePlayer, 255, 255, 0 ) end ) Edited September 9, 2016 by qaisjp
KariiiM Posted September 9, 2016 Posted September 9, 2016 16 minutes ago, qaisjp said: Here's one that doesn't need tables: function getMostWantedPlayer ( ) local mostWantedPlayer = false local mostWantedLevel = -1 for _, player in ipairs ( getElementsByType ( "player", root ) ) do if getPlayerWantedLevel(player) > mostWantedLevel then mostWantedPlayer = player mostWantedLevel = getPlayerWantedLevel(player) end end return mostWantedPlayer end addCommandHandler ( "gewl", function ( thePlayer ) local mostWanted = getMostWantedPlayer ( ) if not mostWanted then outputChatBox("There are no players on the server") return end outputChatBox ( "The most online wanted player is ".. getPlayerName(mostWanted) .."!", thePlayer, 255, 255, 0 ) end ) Using varialbe instead of table, will receive only one player, with table you can get more players in order, as I did for you, anyway you have the choice to choose what you need.
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