Jump to content

[Help] setElementData/getElementData


Daniels69

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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

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