forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint-event.lua
More file actions
54 lines (45 loc) · 1.13 KB
/
print-event.lua
File metadata and controls
54 lines (45 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Prints the description of an event by ID or index.
--author BenLubar
--[====[
devel/print-event
=================
Prints the description of an event by ID or index.
]====]
local utils = require "utils"
local validArgs = utils.invert({
"id",
"index"
})
local args = utils.processArgs({...})
if type(args.id) == "string" then
args.id = {args.id}
elseif args.id == nil then
args.id = {}
end
if type(args.index) == "string" then
args.index = {args.index}
elseif args.index == nil then
args.index = {}
end
if #args.id == 0 and #args.index == 0 then
qerror("requires at least one event ID or index")
end
local function print_event(event)
local str = df.new("string")
local ctx = df.history_event_context:new()
event:getSentence(str, ctx)
ctx:delete()
print(str.value)
str:delete()
end
for _, id in ipairs(args.id) do
local event = df.history_event.find(tonumber(id))
if not event then
qerror("event ID not found: " .. id)
end
print_event(event)
end
for _, idx in ipairs(args.index) do
local event = df.global.world.history.events[tonumber(idx)]
print_event(event)
end