Daniels69 Posted February 3, 2016 Share Posted February 3, 2016 Hey there. I have couple questions about setelementdata and getlementdata. Basically what i need is. How do i get the player with the biggest elementdata which was set by script? For e.x On player kill somebody it gives him score like, setElementData(player , murders+1) and how do i get the player with the biggest data? Any suggestions please. Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 You can use getElementsByType to get every player and compare their kills with getElementData. Or you can save the kills in an array and use the array to get the most kills. Link to comment
Renkon Posted February 3, 2016 Share Posted February 3, 2016 Typical algorithm for this: var max = 0 var player = null for each player ingame... do if (murders > max) max = murders player = currentplayer fi done Please notice that this will consider, in case of a draw, the last ocurrence. Link to comment
tosfera Posted February 4, 2016 Share Posted February 4, 2016 I would rather save the top scoring player in a variable and when someone gets killed, compare the killer's score with the highest score to see if he jumped over the score. Take care of the onPlayerQuit and onPlayerJoin too. Link to comment
Dimos7 Posted February 4, 2016 Share Posted February 4, 2016 max = 0 addEventHandler("onPlayerWasted", root, function() for _, player in ipairs(getElementsByType("player")) do if (murder > max ) then setElementData(player, "Kills", murder) end getElementData(player, "Kills") end end ) 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