Paste #58809: elder

Date: 2019/10/01 22:40:14 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


JoinTown:
  type: item
  material: dirt
  display name: "Join Town"
  lore:
    - "Join this town"
    - "Requires approval"
    - "From X residents"
LeaveTown:
  type: item
  material: stone
  display name: "Leave Town"
  lore:
    - "Leave your town"
Roster:
  type: item
  material: player_head
  display name: "Roster"
  lore:
    - "View town members"
townElder_gui:
  type: inventory
  title: <player.flag[townElderInv]>
  size: 9
  slots:
    - "[] [i@JoinTown] [] [] [i@LeaveTown] [] [] [i@Roster] []"
townElder_roster_gui:
  type: inventory
  title: <player.flag[townElderInv]>_Roster
  procedural items:
    - define list li@
    - define town <town@>
    - foreach <server.list_players_flagged[ResidentOf]>:
      - if <[value].flag[ResidentOf]> == <player.flag[townElderInv]>:
        - define item player_head[skull_skin=<[value].uuid>]
        - define list <def[list].include[<def[item]>]>
    - determine <def[list]>


townElder_assignment:
  type: assignment
  actions:
    on assignment:
      - trigger name:click state:true
      - flag npc Town:<npc.location.town.after[@]>
  interact scripts:
  - 1 townElder
townElder:
  type: interact
  steps:
    1:
      click trigger:
        script:
          - flag player townElderInv:<npc.flag[Town]>
          - flag player townObject:@<npc.flag[Town]>
          - inventory open d:in@townElder_gui
townElder_gui_handler:
  type: world
  events:
    on player closes townElder_gui|townElder_roster_gui:
      - flag player townElderInv:!
      - flag player townObject:!
    on player clicks in townElder_gui:
      - determine cancelled
    on player drags in townElder_gui:
      - determine cancelled
    on player clicks JoinTown in townElder_gui priority:-1:
      - if <player.has_town>:
        - narrate "You are already part of a town."
        - stop
      - if !<player.has_flag[<player.flag[townElderInv]>_Approval]>:
        - narrate "You have to gain approval from residents of this town first! Go ask around!"
        - stop
      - if <player.flag[<player.flag[townElderInv]>_Approval]> >= <player.flag[townObject].player_count.div_int[4].round_up>:
        - narrate "You need 3 residents to approve you and you have <player.flag[<player.flag[townElderInv]>_Approval]> approvals."
        - stop
      - else:
        - execute as_op "townyadmin town <player.flag[townElderInv]> add <player.name>"
        - flag player ResidentOf:<player.flag[townElderInv]>
        - narrate "You are now a resident of <player.flag[townElderInv]>!"
    on player clicks LeaveTown in townElder_gui priority:-1:
      - execute as_player "town leave"
      - flag player ResidentOf:!
      - flag player <player.flag[townElderInv]>_Support:!
      - flag player <player.flag[townElderInv]>_Approval:!
    on player clicks Roster in townElder_gui priority:-1:
      - inventory open d:in@townElder_roster_gui