Advertisement
rootiest

annc-monitor.lua

Jan 19th, 2023
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | Gaming | 0 0
  1. -- Displays announcements in the DFHack console
  2. --@ enable = true
  3. --[====[
  4.  
  5. devel/annc-monitor
  6. ==================
  7. Displays announcements and reports in the console.
  8.  
  9. :enable|start:      Begins monitoring
  10. :disable|stop:      Stops monitoring
  11. :report enable:     Show combat reports
  12. :report disable:    Only show announcements
  13.  
  14. ]====]
  15.  
  16. VERSION = '0.3'
  17.  
  18. local eventful = require 'plugins.eventful'
  19.  
  20. enabled = enabled or false
  21. filter = filter or false
  22.  
  23. function usage()
  24.     print [[
  25. Usage:
  26.     annc-monitor start|enable: Begin monitoring
  27.     annc-monitor stop|disable: End monitoring
  28.     annc-monitor report enable: Show combat reports
  29.     annc-monitor report disable: Only show announcements
  30. ]]
  31. end
  32.  
  33. function log(s, color)
  34.     dfhack.color(color)
  35.     print(dfhack.df2console(s))
  36.     file = io.open("annc.log", "a")
  37.     file:write(s)
  38.     file:write("\n")
  39.     file:close()
  40.     dfhack.color(COLOR_RESET)
  41. end
  42.  
  43. local args = {...}
  44. if dfhack_flags and dfhack_flags.enable then
  45.     table.insert(args, dfhack_flags.enable_state and 'enable' or 'disable')
  46. end
  47. if #args >= 1 then
  48.     if args[1] == 'start' or args[1] == 'enable' then
  49.         enabled = true
  50.     elseif args[1] == 'stop' or args[1] == 'disable' then
  51.         enabled = false
  52.     elseif args[1] == 'report' and #args >= 2 then
  53.         if args[2] == 'enable' then
  54.             filter = false
  55.         elseif args[2] == 'disable' then
  56.             filter = true
  57.         else
  58.             usage()
  59.         end
  60.     else
  61.         usage()
  62.     end
  63. else
  64.     usage()
  65. end
  66.  
  67. eventful.enableEvent(eventful.eventType.REPORT, 1)
  68. function eventful.onReport.annc_monitor(id)
  69.     if enabled and dfhack.isWorldLoaded() then
  70.         local annc = df.report.find(id)
  71.         if filter and not annc.flags.announcement then
  72.             return
  73.         end
  74.         local color = annc.color + (annc.bright and 8 or 0)
  75.         log(annc.text, color)
  76.     end
  77. end
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement