Paste #5333: Jail

Date: 2014/06/16 15:06:03 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


'GuardKillsPlayerEvent':
  type: world
  debug: true
  events:
    on npc damages player:
    - if <npc[<context.damager>].name.contains[Guard]> {
      - if <context.entity.health.sub[<context.damage>]> < 5 {
        - heal <context.entity> 10.0
        - ^if !<player.flag[playerisjailed]> flag <context.entity> beforejailloc:<context.entity.location.simple>
        - run jailintro as:<context.entity> instantly
        - determine CANCELLED
        }
      }
    on server start:
    - run jailyloops
    on player drops item:
    - if <global.flag[playersinjail].as_list> contains <player> && <player.location.in_region[jail]> {
      - determine cancelled
      }
    on jail command:
    - if !<player.has_permission[essentials.togglejail]> && !<player.is_op> {
      - narrate "<&c>You do not have the permission to do this."
      - determine fulfilled
      }
    - if <context.args.size> != 2 || <context.args> contains 'help' {
      - narrate "<&c>/jail [player] [duration]"
      - narrate "<&c>/unjail [player]"
      - narrate "<&c>example durations<&co> 1w, 7d, 24h, 60m, 60s."
      - determine fulfilled
      }
    - if <server.list_online_players> !contains <context.args.get[1].as_player> {
      - narrate "<&c><context.args.get[1]> is not online."
      - determine fulfilled
      }
    - flag <context.args.get[1].as_player> jailedbycommand
    - run jailintro as:<context.args.get[1].as_player> def:<context.args.get[2]>|yes
    - narrate "<&c>Jailed <context.args.get[1]> for <context.args.get[2]>."
    - determine fulfilled
    on unjail command:
    - if !<player.has_permission[essentials.jail]> && !<player.is_op> {
      - narrate "<&c>You do not have the permission to do this."
      - determine fulfilled
      }
    - if <context.args.size> != 1 || <context.args> contains 'help' {
      - narrate "<&c>/jail [player] [duration]"
      - narrate "<&c>/unjail [player]"
      - narrate "<&c>example durations<&co> 1w, 7d, 24h, 60m, 60s."
      - determine fulfilled
      }
    - if <server.list_online_players> !contains <context.args.get[1].as_player> {
      - narrate "<&c><context.args.get[1]> is not online."
      - determine fulfilled
      }
    - flag <context.args.get[1].as_player> jailedbycommand:!
    - narrate "<&c>You unjailed <context.args.get[1]>"
    - flag <context.args.get[1].as_player> playerisjailed:!
    - flag server playersinjail:<-:<context.args.get[1].as_player>
    - ^inventory clear destination:<context.args.get[1].as_player.inventory>
    - ^foreach <context.args.get[1].as_player.flag[itemsbeforejailed].exclude[m@air]> {
      - ^give %value% player:<context.args.get[1].as_player>
      }
    - ^equip <context.args.get[1].as_player> boots:<context.args.get[1].as_player.flag[equipmentbeforejailedboots]||i@air>
    - ^equip <context.args.get[1].as_player> leggings:<context.args.get[1].as_player.flag[equipmentbeforejailedleggings]||i@air>
    - ^equip <context.args.get[1].as_player> chestplate:<context.args.get[1].as_player.flag[equipmentbeforejailedchestplate]||i@air>
    - ^equip <context.args.get[1].as_player> helmet:<context.args.get[1].as_player.flag[equipmentbeforejailedhelmet]||i@air>
    - ^teleport <context.args.get[1].as_player> l@2404,73,1181,world
    - ^playsound <context.args.get[1].as_player> sound:PORTAL_TRIGGER
    - ^flag <context.args.get[1].as_player> playerisjailed:!
    - ^inventory update destination:<context.args.get[1].as_player.inventory>
    - determine fulfilled
  commandblock:
    - if <player.location.in_region[jail]> {
      - if !<player.is_op> determine cancelled
      }
"jailintro":
  type: task
  debug: true
  script:
    - ^random {
      - ^teleport <player> l@2428,73,1171,world
      - ^teleport <player> l@2434,73,1171,world
      - ^teleport <player> l@2440,73,1171,world
      - ^teleport <player> l@2446,73,1171,world
      - ^teleport <player> l@2446,73,1192,world
      - ^teleport <player> l@2440,73,1192,world
      - ^teleport <player> l@2434,73,1192,world
      - ^teleport <player> l@2428,73,1191,world
      }
    - ^if !<player.location.in_region[jail]> queue clear
    - execute as_server 'effect <player.name> clear'
    - narrate "<&7><player.name> has been jailed!" targets:<server.list_online_players.exclude[<player>]>
    - ^narrate "<&4>You have been jailed!"
    - ^narrate "<&c>You can work your way out by mining coal, or serve your time by waiting"
    - ^if !<player.flag[playerisjailed]> flag <player> itemsbeforejailed:<player.inventory.list_contents>
    - ^if !<player.flag[playerisjailed]> flag <player> equipmentbeforejailedhelmet:<player.equipment.helmet>
    - ^if !<player.flag[playerisjailed]> flag <player> equipmentbeforejailedchestplate:<player.equipment.chestplate>
    - ^if !<player.flag[playerisjailed]> flag <player> equipmentbeforejailedleggings:<player.equipment.leggings>
    - ^if !<player.flag[playerisjailed]> flag <player> equipmentbeforejailedboots:<player.equipment.boots>
    - ^inventory clear destination:<player.inventory>
    - ^equip <player> head:<i@Jailuniform1||Leather_helmet>
    - ^equip <player> chest:<i@Jailuniform2||leather_chestplate>
    - ^equip <player> legs:<i@Jailuniform3||leather_leggings>
    - ^equip <player> boots:<i@Jailuniform4||leather_boots>
    - ^equip <player> hand:i@Jailuniform5
    - inventory update destination:<player.inventory>
    - if %2% == yes {
      - ^flag <player> playerisjailed duration:%1%
      } else if <player.has_flag[MarkedCriminal]> {
      - ^flag <player> playerisjailed duration:<player.flag[playerisjailed].expiration.in_minutes.add[10]||10>m
      } else if <server.flag[KingsGuildMembers].as_list.contains[<player>]> {
      - ^flag <player> playerisjailed duration:<player.flag[playerisjailed].expiration.in_minutes.add[3]||3>m
      } else {
      - ^flag <player> playerisjailed duration:<player.flag[playerisjailed].expiration.in_minutes.add[5]||5>m
      }
    - if <global.flag[playersinjail].as_list> !contains <player> flag server playersinjail:->:<player>

"jailyloops":
  type: task
  debug: true
  script:
  - if <server.list_online_players.size> > 0 {
    - ^playeffect l@2410,72,1181,world effect:ENDER_SIGNAL qty:10
    - ^playsound l@2410,72,1181,world sound:PORTAL volume:0.5
    }
  - ^foreach li@n@41|n@40|n@42|n@43 {
    - ^if <%value%.is_spawned> flag server jailkilledguards:++
    }
  - ^if <global.flag[playersinjail].as_list.size||0> > 0 && <server.list_online_players.size> > 0 {
    - ^foreach <global.flag[playersinjail].as_list> {
      - if <%value%.is_online> run jailyloopsexternal as:%value% instantly
      }
    }
  - run jailyloops delay:3s instantly

"jailyloopsexternal":
  type: task
  debug: true
  script:
    - ^if <cu@l@2411,73,1180,world|l@2409,73,1182,world.list_players> contains <player> run jailescape as:%value% instantly
    - ^if !<player.has_flag[playerisjailed]> playeffect l@2410,72,1181,world effect:FIREWORKS_SPARK qty:500 offset:1 targets:<player>
    - if <server.flag[jailkilledguards]||0> < 1 && !<player.has_flag[jailedbycommand]> {
      - playeffect l@2410,72,1181,world effect:FIREWORKS_SPARK qty:500 offset:1 targets:<player>
      }
    - if <player.is_online> run jailscoreboard as:<player> instantly

"jailscoreboard":
    type: task
    debug: true
    script:
    - ^scoreboard add viewers:<player> id:FJRHJSKHKJDH
    - scoreboard remove id:jail<player.name>
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&4><&4>------------' score:9
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&6>Jailtime<&co>' score:8
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&e><el@val[<player.flag[playerisjailed].expiration.formatted||<&b><&a>Free!>].substring[1,16]>' score:7
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&a><&4>------------' score:6
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&6>Coal left<&co>' score:5
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&d><&e><el@val[<player.flag[playerisjailed].expiration.in_seconds.div[5].round_up||<&a>Free!>].substring[1,16]>' score:4
    - ^scoreboard add id:jail<player.name> "obj:<&6>Jail Info" 'lines:<&c><&4>------------' score:0
    - ^scoreboard add id:jail<player.name> viewers:<player>

"jailescape":
  type: task
  debug: true
  script:
    - if <player.flag[playerisjailed].expiration.in_seconds||0> > 1 && <server.flag[jailkilledguards]||0> > 0 {
      - narrate "<&c>You are not allowed to leave, and there are too many guards to try to escape."
      } else if <player.flag[playerisjailed].expiration.in_seconds||0> > 1 && <player.flag[jailedbycommand]> {
      - narrate "<&c>There is a much greater force than guards holding you here."
      } else {
      - narrate "<&c>You leave the jail..."
      - ^flag server playersinjail:<-:<player>
      - ^inventory clear destination:<player.inventory>
      - ^foreach <player.flag[itemsbeforejailed].exclude[i@air]> {
        - ^give %value%
        }
      - ^equip <player> boots:<player.flag[equipmentbeforejailedboots]||i@air>
      - ^equip <player> leggings:<player.flag[equipmentbeforejailedleggings]||i@air>
      - ^equip <player> chestplate:<player.flag[equipmentbeforejailedchestplate]||i@air>
      - ^equip <player> helmet:<player.flag[equipmentbeforejailedhelmet]||i@air>
      - ^teleport <player> l@2404,73,1181,world
      - ^playsound <player> sound:PORTAL_TRIGGER
      - ^flag <player> playerisjailed:!
      - flag <player> jailedbycommand:!
      - ^inventory update destination:<player.inventory>
      - wait 2s
      - if <util.random.int[1].to[50]> == 25 {
        - narrate "<&c>You find a piece of Jail Uniform in your inventory.."
        - give i@jailuniform<util.random.int[1].to[5]>
        }
      }

'jaildeath':
  type: world
  debug: true
  events:
    on player respawns:
    - if <global.flag[playersinjail].as_list> contains <player> run jaildeathrespawn as:<player> delay:10t

"jaildeathrespawn":
  type: task
  debug: true
  script:
    - random {
      - teleport <player> l@2428,73,1171,world
      - teleport <player> l@2434,73,1171,world
      - teleport <player> l@2440,73,1171,world
      - teleport <player> l@2446,73,1171,world
      - teleport <player> l@2446,73,1192,world
      - teleport <player> l@2440,73,1192,world
      - teleport <player> l@2434,73,1192,world
      - teleport <player> l@2428,73,1191,world
      }
    - narrate "<&c>You are still jailed!"
    - ^inventory clear destination:<player.inventory>
    - ^equip <player> head:<i@Jailuniform1||Leather_helmet>
    - ^equip <player> chest:<i@Jailuniform2||leather_chestplate>
    - ^equip <player> legs:<i@Jailuniform3||leather_leggings>
    - ^equip <player> boots:<i@Jailuniform4||leather_boots>
    - ^equip <player> hand:i@jailuniform5
    - inventory update destination:<player.inventory>

'jailcoalminer':
  type: world
  debug: true
  events:
    on player breaks m@coal_ore:
    - if !<player.location.in_region[jail]> queue clear
    - playsound <player> sound:ITEM_PICKUP pitch:2.0
    - give <player> i@coal qty:1
    - modifyblock <context.location> m@air
    - if !<player.flag[jailcoalminerCD]> {
      - narrate "<&c>You mined a piece of coal!"
      - narrate "<&c>For each piece of coal that you hand the coal collector, you reduce your jail time by 5 seconds."
      - flag <player> jailcoalminerCD duration:15m
      }
    - run jailcoalminerrestorecoal delay:30s def:<context.location> as:<player>
    on player right clicks entity:
    - if <context.entity> != n@45 queue clear
    - if <player.inventory.contains[i@coal]> {
      - define amount <player.inventory.qty[i@coal]>
      - take i@coal qty:<player.inventory.qty[i@coal]>
      - ^inventory update destination:<player.inventory>
      - flag <player> playerisjailed duration:<player.flag[playerisjailed].expiration.in_seconds.sub[<el@val[%amount%].mul[5]>]>
      - if <player.flag[playerisjailed].expiration.in_seconds||0> < 1 {
        - narrate "<&c>You have served your time and are free to leave now."
        - narrate "<&c>Step through the portal at the gate to leave."
        - flag <player> playerisjailed:!
        } else {
        - narrate "<&c>You give the guard <el@val[%amount%].as_int> pieces of coal."
        - narrate "<&c>Your jail time has been reduced by <el@val[%amount%].mul[5].as_int> seconds."
        }
      } else {
      - narrate "<&c>You have no coal to hand to the officer."
      }
CoalBreak:
  type: world
  debug: false
  events:
    on player breaks block:
      - if <player.location.in_region[jail]> && <context.material> != m@coal_ore {
        - narrate "<&c>Your jail issued pickaxe is far too dull to tunnel out."
        - determine cancelled
        }
CoalOnly:
  type: world
  debug: false
  events:
    on player places block:
      - if <player.location.in_region[jail]> {
        - narrate "<&c>You can't alter jail."
        - determine cancelled
        }
"jailcoalminerrestorecoal":
  type: task
  debug: true
  script:
    - modifyblock %1% m@coal_ore
Jailuniform1:
    type: item
    no_id: true
    material: i@leather_helmet
    display name: '<&8>Jail Helmet'
    lore:
    - Uniform for those
    - who are jailed.
    color: c@075,066,045
Jailuniform2:
    type: item
    no_id: true
    material: i@leather_chestplate
    display name: '<&8>Jail Tunic'
    lore:
    - Uniform for those
    - who are jailed.
    color: c@075,066,045
Jailuniform3:
    type: item
    no_id: true
    material: i@leather_leggings
    display name: '<&8>Jail Leggings'
    lore:
    - Uniform for those
    - who are jailed.
    color: c@075,066,045
Jailuniform4:
    type: item
    no_id: true
    material: i@leather_boots
    display name: '<&8>Jail Boots'
    lore:
    - Uniform for those
    - who are jailed.
    color: c@075,066,045
Jailuniform5:
    type: item
    no_id: true
    material: i@stone_pickaxe
    display name: '<&8>Jail Pickaxe'
    lore:
    - Pickaxe for Enforced Labor.