Paste #28588: Edit of P#28581 - Edit of P#28579 - Edit of P#28577 - Edit of P#28575 - Edit of P#28573 - Edit of P#

Date: 2016/01/16 13:46:54 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


Leaderboard:
  type: world
  events: 
    on player killed by player:
    - flag <context.damager.as_player> kill_player_count:++
    - flag <context.entity.as_player> death_player_count:++
    #Run through the current top players to see if this kill places the player on the list
    - define x 1
    - define KD <context.damager.as_player.flag[kill_player_count].div[<context.damager.as_player.flag[death_player_count]>]||0>
    #Check if KD is greater than any of the top 5
    - while <def[x].is[OR_LESS].than[5]> {
      #Define the player at position
      - define TopPlayer <server.flag[Leaderboard].get[<def[x]>].as_player>
      #Define their KD
      - define TopKD <def[TopPlayer].flag[kill_player_count].div[<def[TopPlayer].flag[death_player_count]>]||0>
      #Compare their KD against the current killer. If it's greater, insert that player in the list.
      - if <def[KD].is[OR_MORE].than[<def[TopKD]>]> {
        - flag server Leaderboard:<server.flag[Leaderboard].insert[<context.damager.as_player>].at[<def[x]>]>
        #break the loop to avoid any unnecessary calculations
        - define x 5
        }
      #If not, try the next position on the list
      - define x <def[x].add[1]>
      }
    #For sake of space/memory, prune the list back down to 5.
    - flag server Leaderboard:<server.flag[Leaderbpard].get[1].to[5]>

    on leaderboard command:
    - narrate "<server.flag[Leaderboard]||'NA'>"
    on stats command:
    - narrate "<player.flag[kill_player_count].div[<player.flag[death_player_count]>]||0>"