Lottery
By
TechCreated: 2018/06/08 10:11:17 UTC-07:00 (6 years and 199 days ago)
Edited: 2018/06/10 11:25:20 UTC-07:00 (6 years and 197 days ago)
Likes: 0
Denizen Version: 1.0.2 SNAPSHOT
Script Version: 1.0
Description:
A lottery plugin that adds Credits as currency.
The script comes with a main GUI, an animated GUI while playing the lottery, and a few simple commands that can be found with /lottery help.
You can change the rewards as you need.
Credits go to suspic and Xenmai for helping :D
Download script |
View raw scriptlottery_command:
type: command
name: Lottery
description: Main command for Lottery plugin
usage: "/lottery help"
script:
- define opt <context.args.get[1]>
- if li@gui|buy|credits| !contains <def[opt]> {
- define opt help
}
- inject locally path:<def[opt]>
help:
- narrate "<&6>Lottery help - Commands:"
- ^narrate "<&6>/lottery help - <&7>Displays this page"
- ^narrate "<&6>/lottery gui - <&7>Opens lottery inventory GUI"
- ^narrate "<&6>/lottery buy (amount) - <&7>Buy lottery credits"
- ^narrate "<&7> 1 credit = 10$"
- ^narrate "<&6>/lottery credits - <&7>Check your credits balance"
gui:
- inventory open d:in@lottery_gui
credits:
- narrate "<&6>[<&b>Lottery<&6>] <&e>You have <&6><player.flag[credits].round> <&e>credits."
buy:
- if !<context.args.get[2].matches[[0-9]+]||false> || <context.args.get[2].length||0> >= 4 {
- narrate "<&6>[<&b>Lottery<&6>] <&e>You didn't specify an amount, or the specified was either invalid or too big"
- queue clear
}
- if <player.money> >= <context.args.get[2].mul[10]> {
- execute as_op "eco take <player.name> <context.args.get[2].mul[10]>"
- flag player credits:+:<context.args.get[2]>
- narrate "<&6>[<&b>Lottery<&6>] <&6><context.args.get[2].round> <&e>credits has been added to your account."
- if <player.has_flag[extracredits].not> {
- flag player extracredits:1
}
else if <player.has_flag[extracredits]> {
- determine passively cancelled
}
- queue clear
}
else {
- narrate "<&6>[<&b>Lottery<&6>] <&e>You don't have enough money"
- determine cancelled
}
extracredits_handler:
type: world
events:
on system time hourly:
- if <server.get_players_flagged[extracredits].size> >= 3 {
- define randomplayer <server.get_players_flagged[extracredits].random>
- flag <def[randomplayer]> credits:+:10
- announce "<&6>[<&b>Lottery<&6>] <&e><def[randomplayer].name> recieved 10 extra credits!"
- foreach <server.get_players_flagged[extracredits]> {
- flag <def[value]> extracredits:!
}
}
rtd_gui_task:
type: task
debug: false
speed: 0
prefix: '&ss1&ss2&ss1&ss5&ss2&ss0&ss2&ss0&ss0&ss5&ss1&ss8&ss2&ss5&ss0&ss7&ss2&ss1&ss0&ss9&ssr'
script:
- define base_inv ''
#- define base_inv 'in@generic[title=<&6><&l>Lottery GUI;size=27;contents=li@i@air]'
- inventory open 'd:in@generic[title=<script.yaml_key[prefix].unescaped><&6><&l>Lottery GUI;size=27]'
- wait 1t
- repeat 50 {
- define rng '<util.random.int[1].to[300]>'
- if <def[rng]> < 30 {
- define item 'i@iron_sword[display_name=&sseLottery Sword;lore=&ss6Whippity whoopity, you now have a sword!;enchantments=DURABILITY,2|DAMAGE_ALL,3]'
}
else if <def[rng]> < 40 {
- define item 'i@diamond_boots[display_name=<&d>Lottery Boots]'
}
else if <def[rng]> < 60 {
- define item 'i@diamond_chestplate[display_name=&ssaLottery Chestplate;nbt_attributes=generic.armor/chest/0/1]'
}
else if <def[rng]> < 85 {
- define item 'i@diamond_leggings[display_name=<&d>Lottery Leggings]'
}
else if <def[rng]> < 110 {
- define item 'i@red_wool[display_name=<&c>Unlucky ;c]'
}
else if <def[rng]> < 140 {
- define item 'i@coal[display_name=<&b>Well.. That is a bummer]'
}
else if <def[rng]> < 150 {
- define item 'i@enchantment_table[display_name=<&b>Enchanting Table!]'
}
else if <def[rng]> < 165 {
- define item 'i@chorus_plant[display_name=<&d>Chorus Plant]'
}
else if <def[rng]> < 175 {
- define item 'i@witherskeleton_skull[display_name=<&0>Wither Skull]'
}
else if <def[rng]> < 190 {
- define item 'i@dirt[display_name=<&6>Better luck next time..]'
}
else if <def[rng]> < 210 {
- define item 'i@cobblestone[display_name=<&f>Cobblestone]'
}
else if <def[rng]> < 230 {
- define item 'i@diamond[display_name=<&f>Diamond]'
}
else if <def[rng]> < 250 {
- define item 'i@Golden_Apple[display_name=<&d>Golden_Apple]'
}
else if <def[rng]> < 270 {
- define item 'i@totem[display_name=<&d>Totem of Undying]'
}
else if <def[rng]> < 285 {
- define item 'i@saddle[display_name=<&d>Saddle!]'
}
else {
- define item 'i@name_tag[display_name=<&d>Name Tag!]'
}
- if <def[item]> != <def[prev_item]||i@air> {
- inventory open
'd:in@generic[title=<script.yaml_key[prefix].unescaped><&6><&l>Lottery GUI;size=27;contents=li@i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|i@air|<def[item]>]'
}
- define prev_item '<def[item]>'
- wait <el@2.71828182846.power[<def[value].mul[0.125].sub[3]>].round_up>t
}
- wait 1s
- narrate "<&6>[<&b>Lottery<&6>] <&e>Congratulations! You got <def[item].display_name>!"
- give <def[item]>
- flag player can_close_inv
- inventory close
rtd_gui_evts:
type: world
debug: false
events:
on player drags in inventory:
- if <context.inventory.title.escaped.starts_with[&ss1&ss2&ss1&ss5&ss2&ss0&ss2&ss0&ss0&ss5&ss1&ss8&ss2&ss5&ss0&ss7&ss2&ss1&ss0&ss9&ssr]> {
- determine cancelled
}
on player clicks in inventory:
- if <context.inventory.title.escaped.starts_with[&ss1&ss2&ss1&ss5&ss2&ss0&ss2&ss0&ss0&ss5&ss1&ss8&ss2&ss5&ss0&ss7&ss2&ss1&ss0&ss9&ssr]> {
- determine cancelled
}
on player closes inventory:
- if <context.inventory.title.escaped.starts_with[&ss1&ss2&ss1&ss5&ss2&ss0&ss2&ss0&ss0&ss5&ss1&ss8&ss2&ss5&ss0&ss7&ss2&ss1&ss0&ss9&ssr]> {
- if !<player.has_flag[can_close_inv]> {
- determine cancelled
}
- flag player can_close_inv:!
}
runscript:
type: item
material: i@diamond[flags=HIDE_ATTRIBUTES|HIDE_ENCHANTS;enchantments=ARROW_DAMAGE,1]
display name: <&d>Play lottery for 20 credits!
lottery_gui:
type: inventory
title: Lottery
size: 27
slots:
- "[wgs] [wgs] [bal] [] [] [] [bal] [wgs] [wgs]"
- "[wgs] [lcredits] [] [] [runscript] [] [] [lcredits] [wgs]"
- "[wgs] [wgs] [bal] [] [] [] [bal] [wgs] [wgs]"
definitions:
wgs: i@black_stained_glass_pane
lcredits: i@white_stained_glass_pane[display_name=<&d>Credits:;lore=<&f><player.flag[credits].round>]
bal: i@white_stained_glass_pane[display_name=<&d>Your money:;lore=<&f>$<player.money.as_int.round>]
roll_handler:
type: world
events:
on player clicks in lottery_gui:
- determine cancelled
on player drags in lottery_gui:
- determine cancelled
on player clicks runscript in lottery_gui:
- if <player.flag[credits].round> < 20 || <player.flag[credits] == null {
- inventory close
- narrate "<&6>[<&b>Lottery<&6>] <&e>You don't have enough credits!"
- queue clear
}
- if <player.has_flag[limit]> {
- inventory close
- narrate "<&6>[<&b>Lottery<&6>] <&e>You need to wait <player.flag[limit].expiration.in_minutes.round_to[2]> minutes to play again!"
- queue clear
}
- if <player.inventory.empty_slots.is[==].to[0]> {
- inventory close
- narrate "<&6>[<&b>Lottery<&6>] <&e>You can't play lottery, inventory is full!"
- queue clear
}
- inventory close
- flag player credits:-:20
- flag player limit:1 d:10m
- run rtd_gui_task instantly player:<player>
View History