Monday 30 December 2019

A small Python script for die-drop tables

Someone was asking about ways to do die-drop tables online (other than pointing a webcam at a physical sheet of paper and dice, I guess). At first I was thinking about some program that opens a png, picks a random pixel, and looks up the RGB value to determine what's encountered. Then I realised if I could make it work with Hex Kit, it'd be way prettier. And it turns out Hex Kit's .map files are really just renamed .json files, so it's super-easy to just pick a random tile in that json, get the filepath to the associated image for that tile, and look up the filename in some user-defined dictionary.

So here's a quick proof of concept. You'll have to download the script and run it in the command line, since I still have no idea how to make a proper webapp. It's pretty limited, but maybe it's of some use to people.

The example provided is a small random encounter table that's for use in a city, but based on the surrounding surrounding wilderness. Is it a good random table? No. Does it suffice as an example? Sure, I guess.

Human-Readable Version

Roll a d6 on the above hex map. Note which hex type the die lands upon, look it up in the following table. Some entries also use the face-up side of the die. Treat coastal hexes as their land terrain-type, not as ocean.

Hex Type Encounter
Jungle (dark green) Traders from the jungle clans. They have [1. brightly coloured snakes, 2. shavings of bark from various medicinal trees, 3. river-gold, painstakingly panned, 4. six glowing orbs of various sizes, looted from a sunken temple, 5. giant capybaras, excellent pack animals, 6. scavenged goods from the last, failed military expedition into the mountains] for sale.
Meadow (light green) [1. A few, 2-3. Several, 4-5. Dozens of, 6. Hundreds of] farmers angry at the viceroy's new taxes
Mountain (brown) The elephant-powered klaxon sounds. An air-raid from those goddamn mountain pterodactyls again. They carry incendiary bombs in their talons. Parents shoo their children into stone cellars.
Ocean (blue) A ship sails into port, bearing the flag of [1. Redbeard's pirates, 2-3. the Imperial Navy, 4. the Open-Handed Ones, 5. one of the petty river-kings, 6. a PLAGUE SHIP]
Swamp (purple) The swamp-sorcerer has sent envoys to purchase research materials. They are looking for [1. a live bear, 2. a chunk of floatstone from the Flying Fortress, 3. the bitter tears of a child who's just learned Santa isn't real, 4. silt from one of the jungle's more alkaline rivers, 5. tobacco, the good kind, 6. a human heart] and will pay well above market price for speedy delivery.
Volcano (orange) KRAKABOOOOOOOOOOOM! The volcano erupts, huge pyroclastic cloud sweeping over the farming hinterland. You see wealthy folk rushing to buy as many supplies as possible and hunker down, while the poor look on with dread at what is to come.

1 comment:

  1. Fellow Pythonista30 December 2019 at 03:39

    Great post! Thanks for sharing the sauce!

    ReplyDelete

hi! all comments are moderated (mostly for spam) before they're published.