- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: Leaderboards


By Fortifier42
Created: 2016/01/16 17:54:57 UTC-08:00 (8 years and 342 days ago)
Edited: 2016/02/03 05:39:00 UTC-08:00 (8 years and 324 days ago)
Likes: 0

Staff pick as of: 2016/01/16 18:28:31 UTC-08:00 (8 years and 342 days ago)
Denizen Version: Dev #457
Script Version: 1.3
Description:

A Leaderboard system for PVP.

If you use an old version of denizen (pre 1.8.7 spigot) please use this version: http://mcmonkey.org/haste/29595

This script records a players Kills, Deaths and calculates their Kill Death Ratio (stored in flags.)

Flags:
<p@player.flag[kill_score]>
<p@player.flag[death_score]>
<p@player.flag[kill_death_ratio]>

Kill Death Ratio by defaults is rounded to 2 decimal places (for prettiness).

A command is included which displays the top 5 leaders.
/leaderboard
Also a command for checking your own or another player's stats.
/stats
And finally, reset commands.
-- Reset the entire server's leaderboards. Requires the 'leaderboard.resetscore' permission to use.
/leaderboard reset
-- Reset your own or another player's score. Requires the 'leaderboard.resetscore' permission to reset another player's score.
/resetscore (player)
/resetscore (player)


Download script | View raw script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
15700

LeaderBoard_Version:
  type: version
  name: LeaderBoard
  id: 71
  description: A PVP Leaderboard system.
  version: 1.3

LeaderBoard_Command:
  type: command
  debug: false
  name: leaderboard
  aliases:
  - leaders
  - leader
  - leaderboards
  usage: /leaderboard
  description: Check the pvp leaderboards!
  script:
    - if <player.has_permission[leaderboard.reset]||<context.server>> && <context.args.get[1]||null> == reset {
      - narrate "<&6>Resetting the server's leaderboard. <&f>NOTE: May lag servers with a large playerbase."
      - foreach <server.list_players> {
        - flag <def[Value]> kill_score:!
        - flag <def[Value]> death_score:!
        - flag <def[Value]> kill_death_ratio:!
      }
      - flag server "leaders:!"
      - narrate "<&6>Successfully reset the server's leaderboard."
      - queue clear
    }
    - if <server.has_flag[update_leaders]> {
      - flag server update_leaders:!
      - inject s@LeaderBoard_Handler path:update
    }
    - narrate "----- <&6>Leaderboards<&r> -----"
    - if <server.has_flag[leaders].not> {
      - narrate "Sorry, there are <&6>no<&r> leaders at this time!"
      - queue clear
    }
    - foreach <server.flag[leaders].as_list> {
      - narrate "<def[loop_index]><&6><def[Value].name><&r> - KDR<&6><def[value].flag[kill_death_ratio]||0><&r> (<&6><def[value].flag[kill_score].round||0> <&r>Kills & <&6><def[Value].flag[death_score].round||0><&r> Deaths)"
    }
    
LeaderBoard_ResetScore_Command:
  type: command
  debug: false
  name: resetscore
  aliases:
  - scorereset
  usage: /resetscore (player)
  description: Reset your own or another player's score.
  tab complete:
  - determine <server.list_players.parse[name].filter[starts_with[<context.args.last||>]]>
  permission message<&c>I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.
  script:
  - choose <context.args.size>:
    - case 0:
      - define Target <player>
      - narrate "Resetting your <&6>Leadeboard scores<&r>!"
    - case 1:
      - if <player.has_permission[leaderboard.reset].not||<context.server.not>> {
        - narrate "<parse:<script.yaml_key[permission message]>>"
        - queue clear
      }
      - define Target <server.match_offline_player[<context.args.get[1]>]||null>
      - if <def[Target]> == null {
        - narrate "<&c>No player can be found by that name!"
        - queue clear
      }
      - narrate "Resetting the Leaderboard scores of <&6><def[Target].name><&r>."
    - default:
      - narrate "Usage: <parse:<script.yaml_key[usage]>>"
      
  - flag <def[Target]> kill_score:!
  - flag <def[Target]> death_score:!
  - flag <def[Target]> kill_death_ratio:!
  - run s@LeaderBoard_Handler path:update instantly
    
Stats_Command:
  type: command
  debug: false
  name: stats
  aliases:
  - stats
  usage: /stats (player)
  description: Check your own or another player's pvp stats.
  script:
  - if <context.server> && <context.args.size> == 0 {
    - narrate "<&c>You must enter a player from console!"
    - queue clear
  }
  - if <context.server.not> {
    - define Target <player>
  }
  - if <context.args.size> >= 1 {
    - define Target <server.match_offline_player[<context.args.get[1]>]||null>
    - if <def[Target]> == null {
      - narrate "<&c>No player can be found by that name!"
      - queue clear
    }
  }
  - if <context.server.not> && <def[Target]> == <player> {
    - narrate "<&6>Your stats!"
  }
  else {
    - narrate "Stats for<&6><def[Target].name>"
  }
  - narrate "KDR: <&6><def[Target].flag[kill_death_ratio]||0><&r> (<&6><def[Target].flag[kill_score].round||0> <&r>Kills & <&6><def[Target].flag[death_score].round||0><&r> Deaths)"

LeaderBoard_Handler:
  debug: false
  type: world

  ## A death!
  death:
  - flag <player> "death_score:++"
  - flag <player> "kill_death_ratio:<player.flag[kill_score].div[<player.flag[death_score]>].round_to[2]||0>"

  ## A kill!
  kill:
  - flag <player> "kill_score:++"
  - flag <player> "kill_death_ratio:<player.flag[kill_score].div[<player.flag[death_score]||1>].round_to[2]>"
  
  ## Update the leaderboard!
  update:
  - flag server "leaders:!"
  - define Leaders <server.list_players.filter[has_flag[kill_death_ratio]].sort[LeaderBoard_Sort].get[1].to[5]||li@>
  - if <def[Leaders].is_empty.not> {
    - flag server "leaders:|:<def[Leaders]>"
  }

  events:
    ## Someone got smacked in the face! :o
    on player kills player:
    - run <script> path:kill player:<context.damager> instantly
    - run <script> path:death player:<context.entity> instantly
    - flag server update_leaders

LeaderBoard_Sort:
  type: procedure
  debug: false
  definitions: p1|p2
  script:
  ## If P2's kill score is better than P1's move P2 up, ooh that bitch is climbin!
  - if <def[p2].flag[kill_death_ratio]||0> > <def[p1].flag[kill_death_ratio]||0> {
    - determine 1
  }
  ## If P1's kill score is better than P2's move P1 up, ooh that bitch is climbin!
  else if <def[p1].flag[kill_death_ratio]||0> > <def[p2].flag[kill_death_ratio]||0> {
    - determine -1
  }
  ## Their kill score is equal, so do nothing... boring..
  else {
    - determine 0
  }







View History