Paste #31477: Berufeng's Chat Overhaul

Date: 2016/03/11 16:36:21 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


LocalChat_Format:
  type: format
  format: <&2><&lb><player.name><&rb><&co> <&f><text>

GlobalChat_Format:
  type: format
  format: <&7><&lb>Global<&rb> <&8><player.name><&7><&co> <&a><text>

TradeChat_Format:
  type: format
  format: <&5><&lb>Trade - <player.location.cuboids.filter[contains[_town]].get[1].before[_town].after[cu@].replace[_].with[<&sp>].to_titlecase><&rb> <&d><player.name><&5><&co> <&b><text>

Chat_Channels:
  type: world
  Local_Radius:
    - 20
  Global_Chat_Limit:
    - 10
  Global_Chat_Period:
    - 1h
  help:
    - narrate "<&3>====== <&b>Chat Help <&3>======"
    - narrate ""
    - narrate "  - <&l>/local <&r>For speaking to everyone in a <script.yaml_key[Local_Radius]> block radius."
    - narrate "  - <&l>/global <&r><&a>Chat to everyone, limited to <script.yaml_key[Global_Chat_Limit]> per <script.yaml_key[Global_Chat_Period]>."
    - narrate "  - <&l>/trade <&r><&b>Arrange trades with others in the same city."
    - narrate ""
  events:
    on player chats:
      - determine passively cancelled
      - choose <player.flag[chat_channel]>:
        - case global:
          - inject GlobalChat_Monitor instantly
          - announce format:GlobalChat_Format <c.message>
        - case local:
          - narrate format:LocalChat_Format <c.message> targets:<pl.location.find.players.within[<script.yaml_key[Local_Radius]>]>
        - case trade:
          - if <pl.location.cuboids.filter[contains[_town]].size.is[LESS].than[1]> {
            - narrate "<&4>You cannot use Trade Chat unless you are in a town."
          } else {
            - narrate format:TradeChat_Format <c.message> targets:<pl.location.cuboids.filter[contains[_town]].get[1].list_players>
          }
    on chat command:
      - inject locally help
    on global command:
      - determine passively fulfilled
      - define message <c.raw_args>
      - if <c.raw_args.length.is[MORE].than[0]> {
        - inject GlobalChat_Monitor instantly
        - announce format:GlobalChat_Format <def[message]>
        - queue clear
      }
      - if <player.flag[chat_channel].is[==].to[global]> {
        - narrate "<&4>Your default channel is already Global Chat."
      } else {
        - narrate "<&3>Set your chat channel to <&8><&lb><&7>Global<&8><&rb>"
        - flag player chat_channel:global
      }
    on trade command:
      - determine passively fulfilled
      - define message <c.raw_args>
      - if <c.raw_args.length.is[MORE].than[0]> {
        - if <pl.location.cuboids.filter[contains[_town]].size.is[LESS].than[1]> {
          - narrate "<&4>You cannot use Trade Chat unless you are in a town."
        } else {
          - narrate format:TradeChat_Format <def[message]> targets:<pl.location.cuboids.filter[contains[_town]].get[1].list_players>
        }
        - queue clear
      }
      - if <player.flag[chat_channel].is[==].to[trade]> {
        - narrate "<&4>Your default channel is already Trade Chat."
      } else {
        - narrate "<&3>Set your chat channel to <&8><&lb><&5>Trade<&8><&rb>"
        - flag player chat_channel:trade
      }
    on local command:
      - determine passively fulfilled
      - define message <c.raw_args>
      - if <c.raw_args.length.is[MORE].than[0]> {
        - narrate format:LocalChat_Format <def[message]> targets:<pl.location.find.players.within[<script.yaml_key[Local_Radius]>]>
        - queue clear
      }
      - if <player.flag[chat_channel].is[==].to[local]> {
        - narrate "<&4>Your default channel is already Local."
      } else {
        - narrate "<&3>Set your chat channel to <&2><&lb>Local<&rb>"
        - flag player chat_channel:local
      }
    on player joins:
      - if <player.has_flag[chat_channel].not> {
        - flag player chat_channel:local
      }

GlobalChat_Monitor:
  type: task
  script:
    - if <pl.flag[global_chat_count].is[MORE].than[<s@Chat_Channels.yaml_key[Global_Chat_Limit]>]> {
      - narrate "<&4>You have reached your limit for Global Chat. Please try again later."
      - queue clear
    }
    - if <pl.flag[global_chat_count].is[MORE].than[<s@Chat_Channels.yaml_key[Global_Chat_Limit].mul[0.8].round>]> {
      - narrate "<&8>Warning<&co> You are nearing your limit of messages per <s@Chat_Channels.yaml_key[Global_Chat_Period]>."
    }
    - flag player global_chat_count:++
    - run GlobalChat_Decay delay:<s@Chat_Channels.yaml_key[Global_Chat_Period]> def:<player>

GlobalChat_Decay:
  type: task
  script:
    - if <def[1].as_player.flag[global_chat_count].is[MORE].than[0]> {
      - flag <def[1].as_player> global_chat_count:--
    }