Skip to content

Commit 6ca6ad9

Browse files
committed
Add force.lua wrapper around modtools/force
1 parent ebe992d commit 6ca6ad9

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

force.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- Forces an event (wrapper for modtools/force)
2+
--[====[
3+
4+
force
5+
=====
6+
A simpler wrapper around the `modtools/force` script.
7+
8+
Usage:
9+
10+
- ``force event_type``
11+
- ``force event_type civ_id`` - civ ID required for ``Diplomat`` and ``Caravan``
12+
events
13+
14+
See `modtools/force` for a complete list of event types.
15+
16+
]====]
17+
18+
utils = require 'utils'
19+
args = {...}
20+
if #args < 1 then qerror('missing event type') end
21+
eventType = nil
22+
for _, type in ipairs(df.timed_event_type) do
23+
if type:lower() == args[1]:lower() then
24+
eventType = type
25+
end
26+
end
27+
if not eventType then
28+
qerror('unknown event type: ' .. args[1])
29+
end
30+
31+
newArgs = {'-eventType', eventType}
32+
if eventType == 'Caravan' or eventType == 'Diplomat' then
33+
if not args[2] then
34+
qerror('event type ' .. eventType .. ' requires civ ID')
35+
else
36+
table.insert(newArgs, '-civ')
37+
table.insert(newArgs, args[2])
38+
end
39+
end
40+
41+
dfhack.run_script('modtools/force', table.unpack(newArgs))

0 commit comments

Comments
 (0)