Cookbook
These are complete, working mods, shown file by file. Each one is its own public repository on GitHub. We install and play each one in our own tests, so it works with the current game. Copy any of it into your own mod.
How do I... #
Each common task, and the file that does it in an example mod, a starter kit or a recipe further down this page. A link opens the file on GitHub at the line it starts on.
| How do I... | Where | API |
|---|---|---|
| Change how the town looks (textures) | Springtime Town, mod.json line 13 | mod.json content |
| Start a texture mod with the file names ready | Texture kit, mod.json line 11 | mod.json content |
| Give villagers new lines, by personality | Springtime Town, talk.json line 5 | talk.json personality |
| Give one villager lines of their own | Villager lines kit, talk.json line 58 | talk.json villager,talk.json chance |
| Give villagers lines for the weather, the season or the time of day | Small talk for the weather, the season and the time of day | talk.json season,talk.json time,talk.json weather |
| Put lines before the hello, as the hello, after the topic or as the whole talk | Lines anywhere in a talk: before, hello, topic, after, the whole conversation | talk.json place,talk.json topics,talk.json day |
| Have a villager ask the player a question | A villager asks the player something | villager_talked,villager_answered |
| Change the flower shop: name, hours, lines and goods | Shop kit, shops.json line 3 | shops.json when,shops.json hours,shops.json own_goods,shops.json goods,shops.json name,shops.json lines |
| Add goods to Nook's | Shop kit, shops.json line 18 | shops.json goods,shops.json price |
| Open Nook's at hours of your own, with only your goods | After Hours, shops.json line 3 | shops.json when,shops.json hours,shops.json open,shops.json own_goods |
| Change a shop's goods or open it from a script | A Saturday fruit market at the flower shop | cmd.set_shop_goods,cmd.set_shop_open |
| Put a picture of your own on the player's hat | Button Tricks, main.lua line 18 | cmd.set_hat,scene_entered,store.player |
| Count what the player does, and cheer on a milestone | Button Tricks, main.lua line 114 | player_acted,cmd.react,game.player,timer.after |
| Put a picture of your own on the player's shirt | Button Tricks, main.lua line 19 | cmd.set_shirt,scene_entered,store.player |
| Add a new item with its own pictures | After Hours, items.json line 3 | mod.json content,items.json base,items.json textures |
| Sell your own item in a shop | After Hours, shops.json line 8 | shops.json item |
| Rename an item players already have | Rename a mod item players already have | mod.json renames |
| Add a calendar day with a bulletin board notice | Harvest Post, calendar.json line 6 | calendar.json date,calendar.json board |
| Give a calendar day villager lines | Harvest Post, talk.json line 5 | talk.json day,talk.json place |
| Mail a letter on a calendar day, with no script | Harvest Post, calendar.json line 12 | calendar.json letter |
| Write a letter template | Harvest Post, letters.json line 4 | letters.json header,letters.json body,letters.json footer,letters.json sender |
| Run code when a new day starts | Script kit, main.lua line 38 | day_started |
| Run code when the player enters a scene | Script kit, main.lua line 134 | scene_entered |
| Have a villager say a line that depends on the game | Script kit, main.lua line 101 | villager_talked,game.pockets,game.day_number,message |
| React to an item picked up | Script kit, main.lua line 56 | item_picked_up |
| React to a fish caught (a bug works the same way) | Script kit, main.lua line 65 | fish_caught,bug_caught |
| Do something at a set hour | Harvest Post, main.lua line 164 | hour_changed |
| Know whether today is one of your calendar days | Harvest Post, main.lua line 33 | game.calendar_today |
| React to the player reading a letter | Harvest Post, main.lua line 235 | letter_read |
| React to buying or selling | A thank-you letter after spending Bells at Nook's | item_bought,item_sold |
| Notice a new villager, or a friend riding in | Notice a new villager, or a friend riding in | villager_moved_in,visitor_arrived |
| Show the player a line | Script kit, main.lua line 71 | cmd.show_line |
| Give the player an item | Script kit, main.lua line 123 | cmd.give_item |
| Know whether a command worked | Script kit, main.lua line 142 | command_finished |
| Mail a letter from a script | Harvest Post, main.lua line 75 | cmd.send_letter |
| Mail a letter template from a script | Harvest Post, main.lua line 189 | cmd.send_letter |
| Ask the player a question | Harvest Post, main.lua line 131 | cmd.ask |
| Read the answer to a question | Harvest Post, main.lua line 142 | question_answered |
| Take Bells from the player | Harvest Post, main.lua line 152 | cmd.take_bells |
| Take an item from the player | Swap an item for another | cmd.take_item |
| React to a button or a hotkey | A hotkey: a button combination | button_pressed,button_released,game.input |
| Save the game | Save the game each time the player steps outside | cmd.save |
| Play one of the game's sounds | Play a jingle when a fish is caught | cmd.play_sound |
| Change the weather | A rainy morning that clears by noon | cmd.set_weather |
| Save data for the town | Harvest Post, main.lua line 101 | store.get,store.set |
| Save data for each player | Harvest Post, main.lua line 77 | store.player.get,store.player.set |
| Save data for this browser, whatever the town | Remember something in this browser, whatever the town | store.client.get,store.client.set,store.town |
| Change the shape of saved data | Change the shape of saved data | mod.json data_version,data_migrated |
| Pick something at random | Harvest Post, main.lua line 68 | rng |
| Run code later (a timer) | Harvest Post, main.lua line 99 | timer.after,timer_fired |
| Cancel a timer | Harvest Post, main.lua line 114 | timer.cancel |
| Read the town, the player and the clock | Harvest Post, main.lua line 28 | game.town,game.player |
| Read the weather and where the player is | A weather report on the hour: where you are and what is falling | game.weather,game.place |
| Add a setting the player can change (choice, World) | Harvest Post, mod.json line 39 | mod.json settings,settings.get |
| Add an on or off setting to a Just you mod | Script kit, mod.json line 20 | mod.json settings,settings.get |
| Add a setting only its own player sees (client scope) | A setting only its own player sees | mod.json settings |
| Offer a function to other mods | Harvest Post, main.lua line 53 | remote.add,mod.json exports |
| Use another mod when it is there | Script kit, main.lua line 23 | mod.json optional_depends,remote.version,remote.has,remote.call |
| Need another mod, refuse one, or read its lines | Need another mod, or refuse to run with one | mod.json depends,mod.json conflicts,remote.call,message |
Recipes #
There are 4 example mods. Each shows two kinds of mod working together in one mod.
| Mod | Kind | Repository |
|---|---|---|
| Springtime Town | Textures and villager lines, no code | playac-example-springtime-town |
| After Hours | Nook's at night, an item with its own pictures | playac-example-after-hours |
| Harvest Post | Calendar days, letters, a script with commands and a timer | playac-example-harvest-post |
| Button Tricks | Buttons, looks, weather, reactions and saves | playac-example-button-tricks |
Springtime Town #
Town grass with clover and tiny white flowers, and new small talk from each villager in their own personality's voice, some of it for the season, the time of day or the weather. Textures and data only, no script.
Kind: Textures and villager lines, no code. Shows: Textures, Villager talk pools, Just you mod. Id: example.springtime-town, version 1.0.0, API level 1.
Repository: github.com/Play-AC-Online/playac-example-springtime-town. This page shows its
files at tag v1.0.0. In GitHub source form that version is:
github.com/Play-AC-Online/playac-example-springtime-town@v1.0.0
A Just you mod ("scope": "client") in two halves, with no script:
- **The grass** (textures/): the town grass is our own drawing, seamless green ground with clover leaves and small white flowers. - **The talk** (talk.json): new small talk in each villager's own personality's voice, some of it for the season, the time of day or the weather, and an evening goodbye after the topic.
Both are data. Neither changes what a visitor sees, so the mod is Just you.
The grass #
The grass is one 128x128 uncompressed RGBA DDS picture, saved under every name the game draws the grass with. The names say which in-game texture to replace, and the pixels are our own.
The grass is six textures. The game draws each under several palettes, through the seasons and the time of day. A file can name one texture and one palette:
tex1_32x32_<texture>_<palette>_8.ddsOr it can put $ in place of the palette, for that texture under any palette:
tex1_32x32_<texture>_$_8.ddsOur grass is the same picture all year, so the mod has one $ file per texture. That is six files.
These three grass textures are drawn under nine palettes:
textures: 626709d910129694 903adc6355e36f59 e96fecd242518c9f
palettes: 193ca5974976e36e 20430b0042498b04 4f54e78515f0a185
8910d24f6fbd5f83 8b8a1c2cacd60254 963dc45f18e13cf7
b2e512f9c0fe88ad e7f9e59c09c5f9d0 f83e63a8b6cb47b7And these three under three palettes:
textures: 82f28ec4199a45be cfa57a6e6f966d11 e2ab673814e71af6
palettes: 6d5ff5628ae85b42 ce63d23d746a058a d9eb32f9a8b17411To change the grass for one stretch of the year or one time of day, add a file named with that palette next to the $ file. The file named for one palette wins under that palette, and the $ file still covers the rest.
With one file per palette, 36 files, the mod could change with every palette. A $ file is loaded once and shared, so it is the lighter choice when the picture does not change.
The pictures were drawn by a small program, never copied from the game.
The talk #
Talk to a villager and choose to chat. After their hello they pick a topic, the way they always do: a trade, a letter, a hint, or small talk. When they pick small talk, the line can come from this mod.
talk.json holds line pools. Each personality has its own pool, and a few more pools are kept to a moment: a normal villager has a line for spring, a peppy one for the rain, a lazy one for the evening, a jock for winter, a cranky one for the snow and a snooty one for a spring morning ("season", "time" and "weather"). A pool counts only at its moment, and among the pools that count the game picks one line. A villager can say several of the mod's lines in a day, and never the same one twice running.
A pool can instead name one villager ("villager": "Bob"), or nobody, which means every villager, and can be said less often ("chance": 30; every time it fits when left out). The most specific pools that fit a villager decide.
Every pool names its place in the talk. The small talk pools say "place": "topic": their lines stand in for the topic the villager picks when you chat. The last pool says "place": "after": on an evening chat, half the time, any villager adds a line after their topic, as the talk's last message. Its line is a list of two pages, each on a clean window. A pool's place can also be "before" the hello, the "hello" itself or the whole "conversation".
No script is needed.
Make your own #
This repository is one mod, laid out the way the GitHub import wants it: mod.json at the top, and a tag named for the version in mod.json.
1. Copy the repository to your own account. 2. Change "id" in mod.json to your own, like yourname.springtime-town. Ids that start with example. are kept for these examples, so the import refuses them. 3. Tag the commit with the version, like v1.0.0. 4. Push the commit and the tag. Then, in the game, open **Settings**, then **Mods**, and scroll to **Share a mod**. Sign in, answer the age question and accept the mod rules the first time, and type the code from your authenticator app. **Import from GitHub** shows under the upload form once the code is accepted. Paste github.com/<you>/<repository>@v1.0.0 there and choose **Import**.
To keep only one half, delete the other half's files and its lines in mod.json, and playac-mod check tells you if anything still points at them.
The modding guide is at playaconline.com/modding.
media/ holds the pictures and the film the cookbook shows, with their captions in media/media.json. .playac/screenshots/ holds the listing's screenshots.
What goes in the mod's ZIP is decided by the pack rule, the same for playac-mod pack and the GitHub import:
- Left out: this repository's own files. Those are this README.md, CHANGELOG.md (it is sent beside the ZIP as the listing's changelog), LICENSE, the whole media/ folder with its pictures, film and media.json, and the screenshots (.playac starts with a dot). The game ignores the same files in any ZIP. - Kept: every other .json, .lua, .dds, .png, .txt and .md file.
Download Springtime Town as a ZIP, ready to install. It downloads from the example's release on GitHub.
Its 6 pictures are not text, so they are listed here by name. Each links to the file in the repository.
textures/tex1_32x32_626709d910129694_$_8.dds(64 KB)textures/tex1_32x32_82f28ec4199a45be_$_8.dds(64 KB)textures/tex1_32x32_903adc6355e36f59_$_8.dds(64 KB)textures/tex1_32x32_cfa57a6e6f966d11_$_8.dds(64 KB)textures/tex1_32x32_e2ab673814e71af6_$_8.dds(64 KB)textures/tex1_32x32_e96fecd242518c9f_$_8.dds(64 KB)
{
"schema": 1,
"api": 1,
"id": "example.springtime-town",
"name": "Springtime Town",
"version": "1.0.0",
"authors": [
"Play AC Online"
],
"description": "Town grass with clover and tiny white flowers, and new small talk from each villager in their own personality's voice, some of it for the season, the time of day or the weather. Textures and data only, no script.",
"scope": "client",
"content": {
"textures": "textures/",
"talk": "talk.json"
},
"assets_original": true
}
{
"pools": [
{
"place": "topic",
"personality": "normal",
"lines": [
"I baked something this morning. The whole house smells like cinnamon now.",
"Have you seen the flowers by the river? I could look at them all day.",
"I wrote you a letter in my head. Maybe one day I'll put it on paper!"
]
},
{
"place": "topic",
"personality": "peppy",
"lines": [
"Guess what? Nothing happened today, and I'm SO excited about it!",
"I practiced my dance moves all night. Want to see? Okay, maybe later!",
"Today feels like a sparkly day. Do you feel sparkly too?"
]
},
{
"place": "topic",
"personality": "lazy",
"lines": [
"I was going to nap, but then I thought about snacks. Now I'm too busy.",
"Do you ever just lie in the grass and count clouds? I got to three.",
"Bugs are my friends. Well, the slow ones are."
]
},
{
"place": "topic",
"personality": "jock",
"lines": [
"I ran around the whole town twice before breakfast. Feel the burn!",
"You look strong today. Have you been lifting rocks? Keep it up!",
"Every step is a workout if you stomp hard enough!"
]
},
{
"place": "topic",
"personality": "cranky",
"lines": [
"Hmph. Kids these days don't even know how to sit on a bench properly.",
"Back in my day the river was wetter. Don't ask me how.",
"I'm not grumpy. I'm just thinking very loudly."
]
},
{
"place": "topic",
"personality": "snooty",
"lines": [
"Darling, your outfit is almost fashionable. Almost.",
"I only drink tea from the finest cups. The chipped ones are for guests.",
"One must always look one's best. Even for the fish."
]
},
{
"place": "topic",
"personality": "normal",
"season": "spring",
"lines": [
"The cherry trees are out! I keep finding petals in my pockets."
]
},
{
"place": "topic",
"personality": "peppy",
"weather": "rain",
"lines": [
"Rain boots ON! Every puddle in town is mine today!"
]
},
{
"place": "topic",
"personality": "lazy",
"time": "evening",
"lines": [
"Evening already? I was just about to start my morning nap."
]
},
{
"place": "topic",
"personality": "jock",
"season": "winter",
"lines": [
"Snow training! Run in it and your legs get twice as strong!"
]
},
{
"place": "topic",
"personality": "cranky",
"weather": "snow",
"lines": [
"Snow. Again. My nose has been cold since breakfast."
]
},
{
"place": "topic",
"personality": "snooty",
"season": "spring",
"time": "morning",
"lines": [
"A spring morning, darling. Even the air is wearing perfume."
]
},
{
"place": "after",
"time": "evening",
"chance": 50,
"lines": [
[
"The sky is going all pink.",
"Get home before the stars come out!"
]
]
}
]
}
After Hours #
From 1 AM to 3 AM the town shop opens again, and all it sells is gyroids. A different few stand on the floor each night, and among them, now and then, a Ghost Lantern of the mod's own, its windows glowing green. Every other spot is empty. The rest of the day the shop is its usual self. Remove the mod and a Ghost Lantern you bought stays in your house as the plain tall lantern it is built on.
Kind: Nook's at night, an item with its own pictures. Shows: A shop, New items, World mod. Id: example.after-hours, version 1.0.0, API level 1.
Repository: github.com/Play-AC-Online/playac-example-after-hours. This page shows its
files at tag v1.0.0. In GitHub source form that version is:
github.com/Play-AC-Online/playac-example-after-hours@v1.0.0
A World mod ("scope": "world") in two halves:
- **The shop** (shops.json): from 1 AM to 3 AM the town shop opens again, and all it sells is gyroids, a different few each night. Every other spot is empty. - **The lantern** (items.json, items/ghost-lantern/): the Ghost Lantern, a tall lantern of the mod's own with its own pictures. Now and then it stands among the gyroids.
A shop changes the town, so the mod is a World mod.
The shop #
shops.json changes one shop, Nook's store, by its id "nook". Its block says when it applies, what it does then, and its sixteen goods: fifteen gyroids and the Ghost Lantern.
- "when": { "hours": { "from": "01:00", "to": "03:00" } }: the block applies only inside these hours. - "open": true: while it applies the shop is open, even though it is shut at night. - "own_goods": false: while it applies the mod's goods are the shop's whole stock. Each furniture spot holds one of them and every other spot is bare. Without it the goods would join the day's own instead. - Outside the hours nothing changes. The shop keeps its own hours and its own goods, and the day's stock is still there when it opens in the morning. - The shop has fewer furniture spots than sixteen goods, so it shows a few of them each night, and a different few the next night. The Ghost Lantern is one of the sixteen, so it is there only on some nights. - A good may be an item of the same mod, named by its full id, example.after-hours:ghost-lantern. Without a price it takes the item's own price from items.json. The gyroids sell at the game's own price. - Every shop takes the same fields with the same meaning. The same block works on the flower shop as "flower".
The lantern #
items.json lists the new item. It has an id, a name, a price, a base (the game's own piece it is built on, here the tall lantern) and textures, a folder of pictures only this item draws.
- The pictures in items/ghost-lantern/ are named like texture mod files, after the base's textures. Only the Ghost Lantern wears them: a tall lantern next to it keeps its own look. Four of the lantern's textures are replaced, the windows and the stone beside them, and the rest stay the base's. - A gyroid cannot be a base, so the mod's own piece is a lantern. - With the mod installed, the piece is the mod's item, with its own name. - Remove the mod and the piece stays in the house as the plain base piece. - Put the mod back and it is the mod's item again.
Other files name an item as example.after-hours:ghost-lantern: the mod id, a colon, and the item id. Never change an item's id once players have it. To rename one in a later version, map the old id to the new one with "renames" in mod.json.
Make your own #
This repository is one mod, laid out the way the GitHub import wants it: mod.json at the top, and a tag named for the version in mod.json.
1. Copy the repository to your own account. 2. Change "id" in mod.json to your own, like yourname.after-hours, and the full ids in shops.json with it. Ids that start with example. are kept for these examples, so the import refuses them. 3. Tag the commit with the version, like v1.0.0. 4. Push the commit and the tag. Then, in the game, open **Settings**, then **Mods**, and scroll to **Share a mod**. Sign in, answer the age question and accept the mod rules the first time, and type the code from your authenticator app. **Import from GitHub** shows under the upload form once the code is accepted. Paste github.com/<you>/<repository>@v1.0.0 there and choose **Import**.
To keep only one half, delete the other half's files and its lines in mod.json, and playac-mod check tells you if anything still points at them.
The modding guide is at playaconline.com/modding.
media/ holds the pictures and the film the cookbook shows, with their captions in media/media.json. .playac/screenshots/ holds the listing's screenshots.
What goes in the mod's ZIP is decided by the pack rule, the same for playac-mod pack and the GitHub import:
- Left out: this repository's own files. Those are this README.md, CHANGELOG.md (it is sent beside the ZIP as the listing's changelog), LICENSE, the whole media/ folder with its pictures, film and media.json, and the screenshots (.playac starts with a dot). The game ignores the same files in any ZIP. - Kept: every other .json, .lua, .dds, .png, .txt and .md file.
Download After Hours as a ZIP, ready to install. It downloads from the example's release on GitHub.
Its 4 pictures are not text, so they are listed here by name. Each links to the file in the repository.
items/ghost-lantern/tex1_16x32_0d673c8f9b3a70fb_$_8.dds(8 KB)items/ghost-lantern/tex1_16x32_39b3254f69f1b89d_$_8.dds(8 KB)items/ghost-lantern/tex1_16x32_4f8aaa9bcfcdaf16_$_8.dds(8 KB)items/ghost-lantern/tex1_16x32_6707ef8a75e6e7ea_$_8.dds(8 KB)
{
"schema": 1,
"api": 1,
"id": "example.after-hours",
"name": "After Hours",
"version": "1.0.0",
"authors": [
"Play AC Online"
],
"description": "From 1 AM to 3 AM the town shop opens again, and all it sells is gyroids. A different few stand on the floor each night, and among them, now and then, a Ghost Lantern of the mod's own, its windows glowing green. Every other spot is empty. The rest of the day the shop is its usual self. Remove the mod and a Ghost Lantern you bought stays in your house as the plain tall lantern it is built on.",
"scope": "world",
"content": {
"items": "items.json",
"shops": "shops.json"
},
"assets_original": true
}
{
"items": [
{ "id": "ghost-lantern", "name": "Ghost Lantern", "base": "0x122C", "price": 2600, "textures": "items/ghost-lantern/" }
]
}
{
"shops": {
"nook": {
"when": { "hours": { "from": "01:00", "to": "03:00" } },
"open": true,
"own_goods": false,
"goods": [
{ "item": "example.after-hours:ghost-lantern" },
{ "item": "0x1768" },
{ "item": "0x1738" },
{ "item": "0x16E4" },
{ "item": "0x1780" },
{ "item": "0x15BC" },
{ "item": "0x15E0" },
{ "item": "0x16C0" },
{ "item": "0x16CC" },
{ "item": "0x16FC" },
{ "item": "0x16F0" },
{ "item": "0x16B0" },
{ "item": "0x1728" },
{ "item": "0x1744" },
{ "item": "0x1774" },
{ "item": "0x1798" }
]
}
}
}
Harvest Post #
Two calendar days of our own, the Harvest Fair and Apple Day, with a notice on the bulletin board, villagers talking about it all day and a letter on Apple Day. On fair day you can enter the fruit contest for 100 Bells and get a thank-you letter. And once a game day, a script mails you a letter with a little present: a worked example of mod commands, a question, a setting and a timer.
Kind: Calendar days, letters, a script with commands and a timer. Shows: Lines, Letters, Calendar days, Villager talk pools, Lua script (day_started, scene_entered, hour_changed, question_answered, command_finished, timer_fired, letter_read), World mod. Id: example.harvest-post, version 1.0.0, API level 1.
Repository: github.com/Play-AC-Online/playac-example-harvest-post. This page shows its
files at tag v1.0.0. In GitHub source form that version is:
github.com/Play-AC-Online/playac-example-harvest-post@v1.0.0
A World mod ("scope": "world") in two halves:
- **The calendar** (calendar.json, letters.json, talk.json): two days of our own. The Harvest Fair is the third Wednesday of September and Apple Day is October 21. A notice goes up on the bulletin board and villagers talk about it all day. - **The post** (main.lua, messages.json): once a game day, a script mails you a letter with a little present. On fair day it runs a fruit contest with a 100 Bell entry fee. A worked example of mod commands, a question, a setting, a timer and a function other mods can call.
A board notice changes the town, so the whole mod is a World mod. It still does not count for a friend visit: only a World mod with textures, shops or items does, so two friends need not both have it. The board notice goes up in the player's own town only. The script half alone would run in a Just you mod too.
The calendar #
- It adds two calendar days. The Harvest Fair is the third Wednesday of September (week 3, weekday 3). Apple Day is October 21 (day). - On each day a notice goes up on the town bulletin board. It is posted once, in the player's own town only. - talk.json has a pool for each day: "day" names the calendar day by its id, and "place": "before" puts the line before the villager's hello. Every pool names its place; the others are the hello itself, the topic after a chat answer, a line after the topic, and the whole conversation. - letters.json holds two letter templates. The player's name goes where {player} is, and an apple comes with each. - fair-thanks is mailed by the script, with cmd.send_letter{ template = "fair-thanks" }, once a player pays to enter the fruit contest. Another mod's command would name it example.harvest-post:fair-thanks. - apple-day is mailed by the calendar, with no script: the Apple Day entry in calendar.json says "letter": "apple-day". It goes out once on the day, the first time the player is free in their own town, and it counts against the mod's 3 letters a day. - The thank-you signs "The Fair Committee". The mailbox list has room for 8 characters, so sender names it "The Fair" there.
Letter and notice text is plain ASCII and must fit six lines of the paper. The game measures it in its own font and refuses text that does not fit.
The post: commands #
An event handler never changes the game itself. It queues a command, and the game applies it at the end of a frame's update, once the player is free.
- cmd.send_letter{ text = ..., item = ..., from = ... } queues the letter. It returns the command's id, or nil, a message and a code when the game refuses it now. The text and the sender come from messages.json, read with message("letter") and message("from"). - "permissions": ["send_letter"] in mod.json names the command. A command the mod does not name is refused. - command_finished says what happened to it: e.ok, e.via (mailbox, or post_office when the mailbox was full), or e.code and e.message for a refusal. - The game's cap is 3 letters a day from one mod, per town. The refusal's code is command-day-cap.
The post: a setting #
mod.json declares one setting, present, a choice of fruit or none. The player sets it on the Mods tab, and settings.get("present") reads it. With none the daily letter comes with no present.
- A setting has no scope, so it is world, the default: the value is part of the town. A friend visit compares it, and a visitor lent the mod runs the host's value. - A World setting may decide what the town gets, so the letter command after it is allowed. A "scope": "client" setting is each player's own, and in a handler that read one the game refuses send_letter, give_item, take_item and take_bells with command-client-setting. The script kit shows a client setting.
The fruit contest: a question and a take #
On the Harvest Fair, the first time a resident enters the town, the script asks them to enter the fruit contest.
- cmd.ask{ text = message("contest"), choices = { "Apple", "Pear", "Not today" } } puts the question in the player's thought window. It has 2 to 4 answers of up to 16 characters. - question_answered brings back e.id (what cmd.ask returned), e.choice (counting from 1) and e.text. Both are nil when the window closed with no pick. - For Apple or Pear, cmd.take_bells{ amount = 100 } asks for the fee. The game shows its own question, which names the amount and the mod, and the player says yes or no there. The script cannot change those words. - command_finished with e.command == "take_bells" says how it went: e.via is "taken" on yes, and e.code is command-declined on no, or command-not-held when the wallet holds less than 100 Bells. - Once the fee is taken the script mails fair-thanks. - A take is refused on a visit, so the contest is asked only at home: store.town() starts with "v:" away from home.
The fair at 6 PM: hour_changed and show_line #
hour_changed fires on the game's own hourly update, with e.hour from 0 to 23. At 18 on fair day the script runs cmd.show_line(message("packing_up")), which puts a line in the player's thought window once they are free.
game.calendar_today() tells the script which of its calendar days fall today. It lists this mod's own days only, by their id in calendar.json.
A function other mods can call #
remote.add("fair_today", ...) offers a function to other mods while the script loads. "exports" in mod.json lists it, with one line that says what it returns, and the game then lets the script offer only the names listed.
Another mod names Harvest Post in "optional_depends" and calls it:
if remote.version("example.harvest-post") and remote.has("example.harvest-post", "fair_today") then
local fair = remote.call("example.harvest-post", "fair_today")
endThe script kit in the modding guide does exactly that.
The post: timers #
A letter the game could not take now (both boxes full, or the player away from home) is tried again half a game hour later.
- timer.after(30, "retry", p.id) counts game minutes. The timer is kept with the town's data, so it still fires after a save and a reload. - timer_fired brings back the name and the data: here, whose letter it was. - timer.cancel(id) cancels a waiting timer. When the letter gets through on the next scene first, the script cancels the retry.
The post: saved data #
- store.player remembers the day's letter, so each resident of the town gets their own. - The town's store keeps the mark that a retry timer is waiting, under the resident's id. The timer may fire while another resident plays, and only the town's store can be cleared then. - rng() counts the numbers the mod drew in this town today and keeps that count with the town, so reloading the game cannot reroll the present.
The post: events #
day_started sends the day's letter. scene_entered tries too, since a game loaded on a day it already saw does not run day_started again.
command_finished comes for every command, the line and the question too (e.via is "shown" for those), so the script reads e.command first.
letter_read fires when the player reads a letter. e.letter is "example.harvest-post:fair-thanks" or "example.harvest-post:apple-day" for this mod's templates, and nil for a letter sent as plain text.
Make your own #
This repository is one mod, laid out the way the GitHub import wants it: mod.json at the top, and a tag named for the version in mod.json.
1. Copy the repository to your own account. 2. Change "id" in mod.json to your own, like yourname.harvest-post. Ids that start with example. are kept for these examples, so the import refuses them. 3. Tag the commit with the version, like v1.0.0. 4. Push the commit and the tag. Then, in the game, open **Settings**, then **Mods**, and scroll to **Share a mod**. Sign in, answer the age question and accept the mod rules the first time, and type the code from your authenticator app. **Import from GitHub** shows under the upload form once the code is accepted. Paste github.com/<you>/<repository>@v1.0.0 there and choose **Import**.
To keep only one half, delete the other half's files and its lines in mod.json, and playac-mod check tells you if anything still points at them.
The modding guide is at playaconline.com/modding.
media/ holds the pictures and the film the cookbook shows, with their captions in media/media.json. .playac/screenshots/ holds the listing's screenshots.
What goes in the mod's ZIP is decided by the pack rule, the same for playac-mod pack and the GitHub import:
- Left out: this repository's own files. Those are this README.md, CHANGELOG.md (it is sent beside the ZIP as the listing's changelog), LICENSE, the whole media/ folder with its pictures, film and media.json, and the screenshots (.playac starts with a dot). The game ignores the same files in any ZIP. - Kept: every other .json, .lua, .dds, .png, .txt and .md file.
Download Harvest Post as a ZIP, ready to install. It downloads from the example's release on GitHub.
{
"schema": 1,
"api": 1,
"id": "example.harvest-post",
"name": "Harvest Post",
"version": "1.0.0",
"authors": [
"Play AC Online"
],
"description": "Two calendar days of our own, the Harvest Fair and Apple Day, with a notice on the bulletin board, villagers talking about it all day and a letter on Apple Day. On fair day you can enter the fruit contest for 100 Bells and get a thank-you letter. And once a game day, a script mails you a letter with a little present: a worked example of mod commands, a question, a setting and a timer.",
"scope": "world",
"content": {
"calendar": "calendar.json",
"letters": "letters.json",
"messages": "messages.json",
"talk": "talk.json"
},
"scripts": {
"main": "main.lua",
"events": [
"day_started",
"scene_entered",
"hour_changed",
"question_answered",
"command_finished",
"timer_fired",
"letter_read"
]
},
"permissions": [
"send_letter",
"show_line",
"ask",
"take_bells"
],
"exports": {
"fair_today": "true when today is the Harvest Fair in this town, else false."
},
"settings": [
{
"name": "present",
"type": "choice",
"label": "Present in the daily letter",
"description": "Fruit puts a piece of fruit in each day's letter. None sends the letter alone.",
"choices": ["fruit", "none"],
"default": "fruit"
}
],
"assets_original": true
}
{
"days": [
{
"id": "harvest-fair",
"date": { "month": 9, "week": 3, "weekday": 3 },
"board": "HARVEST FAIR TODAY!\nBring your best fruit and\nshow it to your neighbours.\nThe biggest apple wins\nbragging rights for a year."
},
{
"id": "apple-day",
"date": { "month": 10, "day": 21 },
"board": "APPLE DAY\nShare an apple with a friend\ntoday. Any apple will do,\nbut a red one says it best.",
"letter": "apple-day"
}
]
}
{
"letters": [
{
"id": "fair-thanks",
"header": "Dear {player},",
"body": "Thank you for coming to the\nHarvest Fair! Here is an apple\nfrom the prize table. Plant it\nand see what grows.",
"footer": "The Fair Committee",
"sender": "The Fair",
"item": "0x2800",
"paper": 12
},
{
"id": "apple-day",
"header": "Dear {player},",
"body": "Happy Apple Day! Here is an\napple to share with a friend.\nOr plant it, and share the\ntree for years to come.",
"footer": "The Harvest Post",
"sender": "Harvest",
"item": "0x2800",
"paper": 12
}
]
}
-- Harvest Post, the script half. Four small pieces in one file:
--
-- 1. The post: once a game day, a letter with a little present arrives in
-- the mailbox. A setting decides the present. A timer tries again later.
-- 2. The fruit contest, on fair day only: a question (cmd.ask), an entry
-- fee (cmd.take_bells) and a thank-you letter from letters.json.
-- 3. A line at 6 PM on fair day (hour_changed, cmd.show_line).
-- 4. A function other mods can call (remote.add, mod.json "exports").
--
-- An event handler never changes the game itself. It QUEUES a command, and the
-- game applies it at the end of a frame's update, once the player is free.
-- mod.json must name each command in "permissions". command_finished then
-- says how each one went, whatever kind it was.
--
-- The game's cap is per town, not per player: 3 letters a day from one mod,
-- so in a town of four the fourth resident to play that day gets none.
local MOD = "example.harvest-post"
local FAIR = "harvest-fair" -- a day's id in calendar.json
local ENTRY_FEE = 100
-- Fruit: always a fine present (the shop's item rules refuse money, turnips,
-- tickets, grab bags, fossils and reserve ids).
local GIFTS = { 0x2800, 0x2801, 0x2802, 0x2803, 0x2804 }
-- The game day as one number, 20261112, or nil before a town is loaded.
local function today()
local t = game.town()
if not t then return nil end
return t.year * 10000 + t.month * 100 + t.day
end
-- Is one of this mod's calendar days today? game.calendar_today() lists the
-- ids of this mod's own days that fall on the town's date, and only its own.
local function is_today(day_id)
for _, id in ipairs(game.calendar_today()) do
if id == day_id then return true end
end
return false
end
-- store.town() names the town the store is for. It starts with "v:" away from
-- home, on a friend's town, where a take is refused.
local function at_home()
local town = store.town()
return town ~= nil and town:sub(1, 2) ~= "v:"
end
-- ── 4. A function for other mods ────────────────────────────────────────────
-- remote.add offers it while the script loads. mod.json "exports" lists the
-- names a mod offers, each with a line that says what it returns. Another mod
-- names this one in "optional_depends" and asks with remote.call.
remote.add("fair_today", function()
return is_today(FAIR)
end)
-- ── 1. The post ─────────────────────────────────────────────────────────────
-- "present" is a setting from mod.json, set by the player on the Mods tab.
-- It is a World setting (the default scope), so it is part of the town: a
-- visitor lent this mod runs the host's choice. A World setting may decide
-- what the town gets, so the letter command below is allowed after it.
local function present()
if settings.get("present") == "none" then return nil end
-- rng() counts the numbers this mod has drawn in this town today and keeps
-- that count with the town, so a reload carries on from it: reloading the
-- game cannot reroll the present.
return GIFTS[rng(#GIFTS)]
end
local function send_today()
local day = today()
if not day or store.player.get("sent") == day then return end
local gift = present()
local id, why, code = cmd.send_letter{ text = message("letter"), item = gift, from = message("from") }
if id then
store.player.set("sent", day)
log("letter #" .. id .. " queued" .. (gift and string.format(" with item 0x%04X", gift) or ", no present"))
else
log("no letter today: " .. why .. " (" .. code .. ")")
-- The town's letters for today are used up: do not ask again until tomorrow.
if code == "command-day-cap" then store.player.set("sent", day) end
end
end
-- Try again later. timer.after counts GAME minutes and keeps the timer with
-- this town's data, so it still fires after a save and a reload. One timer per
-- resident is enough: a second refusal finds the first still waiting. The name
-- comes back in timer_fired, and the data says whose letter it was.
--
-- The timer's id is kept in the town's store under the resident's id, not in
-- store.player. The timer may fire while another resident plays, and only the
-- town's store can be cleared then.
local RETRY_MINUTES = 30
local function retry_key(id) return "retry:" .. tostring(id) end
local function retry_later()
local p = game.player()
if not p or store.get(retry_key(p.id)) then return end
local id, why, code = timer.after(RETRY_MINUTES, "retry", p.id)
if id then
store.set(retry_key(p.id), id)
else
log("no retry timer: " .. why .. " (" .. code .. ")")
end
end
-- The letter got through some other way first: the waiting timer is not
-- needed now. timer.cancel answers true when there was one to cancel.
local function cancel_retry()
local p = game.player()
if not p then return end
local timer_id = store.get(retry_key(p.id))
if timer_id then
log("retry timer cancelled: " .. tostring(timer.cancel(timer_id)))
store.set(retry_key(p.id), nil)
end
end
-- ── 2. The fruit contest ────────────────────────────────────────────────────
local ask_id = nil -- the contest question, while it is out
local thanks = {} -- command ids of thank-you letters, so their results are not the post's
-- cmd.ask puts a question with 2 to 4 answers in the player's thought window.
-- The pick comes back in question_answered. Asked once per fair day per
-- resident, in their own town.
local function invite()
local day = today()
if not day or ask_id or not at_home() or not is_today(FAIR) then return end
if store.player.get("contest") == day then return end
local id, why, code = cmd.ask{ text = message("contest"), choices = { "Apple", "Pear", "Not today" } }
if id then
ask_id = id
store.player.set("contest", day) -- asked today, whatever the answer
else
log("no contest question: " .. why .. " (" .. code .. ")")
end
end
-- e.choice counts from 1 and e.text is the answer. Both are nil when the
-- player closed the window with no pick.
on("question_answered", function(e)
if e.id ~= ask_id then return end
ask_id = nil
if e.choice == nil or e.choice == 3 then
log("contest: not entered")
return
end
-- take_bells shows the game's own question, which names the amount and this
-- mod, so the player always sees what they pay. Its one result comes back in
-- command_finished: via "taken", or command-declined for a no.
local id, why, code = cmd.take_bells{ amount = ENTRY_FEE }
if id then
store.player.set("fruit", e.text)
else
log("contest: no entry fee asked: " .. why .. " (" .. code .. ")")
end
end)
-- ── 3. A line at 6 PM on fair day ───────────────────────────────────────────
-- hour_changed fires on the game's own hourly update. cmd.show_line puts a
-- line in the player's thought window once the player is free.
on("hour_changed", function(e)
if e.hour ~= 18 or not is_today(FAIR) then return end
local id, why, code = cmd.show_line(message("packing_up"))
if not id then log("no packing-up line: " .. why .. " (" .. code .. ")") end
end)
-- ── Events ──────────────────────────────────────────────────────────────────
-- A new day, and the first scene of each session (a game loaded on a day it
-- already saw does not run day_started again).
on("day_started", send_today)
on("scene_entered", function(e)
send_today()
if e.name == "town" then invite() end
end)
-- What happened to each command. e.command names its kind. e.via says how it
-- was applied ("mailbox" or "post_office" for a letter, "taken" for a take,
-- "shown" for a line or a question). A refusal has e.code (stable, for the
-- script) and e.message (for the log).
on("command_finished", function(e)
if e.command == "take_bells" then
if e.ok then
log("contest: entered with " .. tostring(store.player.get("fruit")) .. ", " .. ENTRY_FEE .. " Bells paid")
-- the letters.json template: header, body, sign-off, present and paper
local id, why, code = cmd.send_letter{ template = "fair-thanks" }
if id then thanks[id] = true else log("no thank-you letter: " .. why .. " (" .. code .. ")") end
else
-- command-declined: the player said no. command-not-held: the wallet
-- holds less than the fee. Nothing was taken either way.
log("contest: no entry (" .. e.code .. ")")
end
return
end
if e.command ~= "send_letter" then return end -- the line and the question report "shown"
if thanks[e.id] then
thanks[e.id] = nil
log("thank-you letter " .. (e.ok and ("delivered via " .. e.via) or ("not delivered: " .. e.message)))
return
end
if e.ok then
log("letter #" .. e.id .. " delivered via " .. e.via)
cancel_retry()
elseif e.code == "command-day-cap" then
log("letter #" .. e.id .. " not delivered: " .. e.message)
else
-- Refused for now (in The City, visiting a friend, both boxes full): the
-- day's letter is owed again. The next scene tries, and so does a timer
-- half a game hour from now, for a player who stays where they are.
-- Away from home, store and timers live in memory only. A result that
-- arrives there clears "sent" in that copy, not at home, so the letter is
-- not owed again today. Tomorrow's comes as usual.
log("letter #" .. e.id .. " not delivered: " .. e.message)
store.player.set("sent", nil)
retry_later()
end
end)
-- The timer is gone once it fires, so its mark goes too, whoever is playing.
-- Send only to the resident it was set for: another resident may be playing by
-- now, and has a letter of their own.
on("timer_fired", function(e)
if e.name ~= "retry" then return end
store.set(retry_key(e.data), nil)
local p = game.player()
if p and p.id == e.data then send_today() end
end)
-- The player read a letter. e.letter names a letters.json letter as
-- "<mod id>:<letter id>" when a mod mailed it: the contest's thank-you, or
-- Apple Day's, which calendar.json mails with no script at all.
on("letter_read", function(e)
if e.first_time and e.letter and e.letter:sub(1, #MOD + 1) == MOD .. ":" then
log("read " .. e.letter)
end
end)
{
"letter": "Good morning! Here is a little something to start your day. Have a lovely time in town, and come back tomorrow for another!",
"from": "A friend",
"contest": "The fruit contest is on! It costs 100 Bells to enter. Which fruit will you show?",
"packing_up": "The Harvest Fair is packing up for the year. See you next September!"
}
{
"pools": [
{
"place": "before",
"day": "harvest-fair",
"lines": [
"It's the Harvest Fair! I've been polishing my pears since sunrise.",
"Harvest Fair day! Did you bring any fruit? Mine is the shiniest, I checked.",
"The fair smells like apples and wood smoke. Best day of the season!"
]
},
{
"place": "before",
"day": "apple-day",
"lines": [
"Happy Apple Day! Have you shared an apple with anyone yet?",
"An apple a day, they say. Today it's an apple for everyone!"
]
}
]
}
Button Tricks #
Tricks on the D-pad, anywhere in town. Right puts on a striped, spotted or checked hat and shirt of the mod's own. Left turns the weather to snow, then a blizzard, then clear again (rain and a storm in the rain season). Up dances, cheers or poses, and spins with R held. Down saves the town and tells you where you are. And every fifth thing you do, your character cheers.
Kind: Buttons, looks, weather, reactions and saves. Shows: Lua script (scene_entered, button_pressed, button_released, player_acted, timer_fired, command_finished), World mod. Id: example.button-tricks, version 1.0.0, API level 1.
Repository: github.com/Play-AC-Online/playac-example-button-tricks. This page shows its
files at tag v1.0.0. In GitHub source form that version is:
github.com/Play-AC-Online/playac-example-button-tricks@v1.0.0
A World mod ("scope": "world") with one script, main.lua, on the D-pad, anywhere in town:
- **Right**: a striped, spotted or checked hat and shirt of the mod's own (hats/, shirts/), then your own clothes again. - **Left**: the weather. Light snow, a blizzard, then clear again. In the rain season it is light rain and a storm. - **Up**: a dance, hooray, a pose or thanks. With R held, a spin. - **Down**: save the town, then say where you are. - **Every fifth thing you do** (a dig, a swing, a door), your character cheers.
Setting the weather changes the town, so the mod is a World mod. It still does not count for a friend visit: only a World mod with textures, shops or items does, so two friends need not both have it. On a visit, friends see your reactions but the game's own hat and shirt: a mod's look draws only on your screen. The weather and the save are refused there, as the host's game decides them.
The buttons #
button_pressed gives the button's name: dpad_right, a, c_up and the rest. The script keeps one function per D-pad direction in a table, PRESS, and calls the one pressed. button_released is the same for letting go: the look plays its sound (cmd.play_sound("wear")) then. A mod may play at most 10 sounds a minute and show 20 lines a game day, so a long go at the buttons falls quiet until the next day.
A button is a button however it is played: a key, a controller or the touch pad, with the player's own key settings. Nothing reaches a mod while the player types.
Right: the look #
cmd.set_hat and cmd.set_shirt take a picture from the mod's own files: a 32 x 32 PNG with at most 16 colours and no see-through pixels, the same as an Able Sisters design. nil gives the player's own back. The pictures sit outside a textures/ folder, since they are not texture replacements.
The game saves nothing about a mod's look, so the pick is kept in store.player (this player, in their own town) and put back at every scene_entered, which also runs at the first scene of a session. On a visit or in The City store.player starts empty, and the look you came in stays on.
Left: the weather #
game.weather() says the weather now, { kind, intensity }. The script steps from clear to light to heavy and back to clear with cmd.set_weather. The game allows only weather it could roll on the day, snow from November 1 to February 24 and rain from February 25 to November 15, and refuses the rest at once with the code command-weather, so the script tries snow, then rain. A mod may change the weather 4 times a game day, and the game's own weather comes back the next day.
Up: reactions #
cmd.react plays a reaction from the reactions bar on the player's character, the same one friends see. game.input() is every button held right now, so game.input().r tells the script R is down as up is pressed: then it is a spin. A reaction needs the player free, so the game refuses one in a talk or mid-swing.
Down: save anywhere #
cmd.save saves the town as the Autosave setting does, outdoors and in free control only, and at most once every 10 seconds for all mods together. It returns an id; command_finished comes back with that id once the game has written the save (via is saved, or unchanged when nothing changed). Then game.place() gives the acre and the square of the town map the player stands on, and the script says it with cmd.show_line.
Every fifth thing: player_acted #
player_acted fires when the player starts one of the game's actions: a dig, a filled hole, a swing of the axe or the net, a cast, a shaken tree, a seat, a door. game.player() says what the player is doing now and the tool in their hand, and the script writes both in the mod log. It counts the actions in store.player and, on every fifth, sets a timer: the player is busy with the action that just started, so cmd.react("hooray") waits for timer_fired a game minute later. Its own cheer comes back as "reacted", which the script leaves out of the count.
Make your own #
This repository is one mod, laid out the way the GitHub import wants it: mod.json at the top, and a tag named for the version in mod.json.
1. Copy the repository to your own account. 2. Change "id" in mod.json to your own, like yourname.button-tricks. Ids that start with example. are kept for these examples, so the import refuses them. 3. Tag the commit with the version, like v1.0.0. 4. Push the commit and the tag. Then, in the game, open **Settings**, then **Mods**, and scroll to **Share a mod**. Sign in, answer the age question and accept the mod rules the first time, and type the code from your authenticator app. **Import from GitHub** shows under the upload form once the code is accepted. Paste github.com/<you>/<repository>@v1.0.0 there and choose **Import**.
To keep only some buttons, delete their functions and their line in PRESS, and their permissions and events in mod.json. playac-mod check tells you if anything still points at them.
The modding guide is at playaconline.com/modding.
media/ holds the pictures and the film the cookbook shows, with their captions in media/media.json. .playac/screenshots/ holds the listing's screenshots.
What goes in the mod's ZIP is decided by the pack rule, the same for playac-mod pack and the GitHub import:
- Left out: this repository's own files. Those are this README.md, CHANGELOG.md (it is sent beside the ZIP as the listing's changelog), LICENSE, the whole media/ folder with its pictures, film and media.json, and the screenshots (.playac starts with a dot). The game ignores the same files in any ZIP. - Kept: every other .json, .lua, .dds, .png, .txt and .md file.
Download Button Tricks as a ZIP, ready to install. It downloads from the example's release on GitHub.
Its 6 pictures are not text, so they are listed here by name. Each links to the file in the repository.
hats/checks.png(1 KB)hats/dots.png(1 KB)hats/stripes.png(1 KB)shirts/checks.png(1 KB)shirts/dots.png(1 KB)shirts/stripes.png(1 KB)
{
"schema": 1,
"api": 1,
"id": "example.button-tricks",
"name": "Button Tricks",
"version": "1.0.0",
"authors": [
"Play AC Online"
],
"description": "Tricks on the D-pad, anywhere in town. Right puts on a striped, spotted or checked hat and shirt of the mod's own. Left turns the weather to snow, then a blizzard, then clear again (rain and a storm in the rain season). Up dances, cheers or poses, and spins with R held. Down saves the town and tells you where you are. And every fifth thing you do, your character cheers.",
"scope": "world",
"scripts": {
"main": "main.lua",
"events": [
"scene_entered",
"button_pressed",
"button_released",
"player_acted",
"timer_fired",
"command_finished"
]
},
"permissions": [
"set_hat",
"set_shirt",
"set_weather",
"react",
"save",
"play_sound",
"show_line"
],
"assets_original": true
}
-- Button Tricks: every addition of mod API 1.1, on the D-pad, anywhere in town.
--
-- right the next hat and shirt (cmd.set_hat, cmd.set_shirt), with a sound
-- as you let go (button_released, cmd.play_sound)
-- left the next weather (game.weather, cmd.set_weather)
-- up the next reaction, or a spin with R held (cmd.react, game.input)
-- down save the town, then say where (cmd.save, command_finished, game.place)
-- every 5th thing you do, a cheer (player_acted, game.player, cmd.react)
--
-- The game logs every refused command in the mod log, so this script does not.
------------------------------------------------------------------ right
local LOOKS = { "stripes", "dots", "checks" }
local function wear(i) -- nil: the player's own hat and clothes
local look = LOOKS[i]
cmd.set_hat(look and "hats/" .. look .. ".png")
cmd.set_shirt(look and "shirts/" .. look .. ".png")
end
-- The game keeps nothing of a mod's look, so it is put back at every scene.
-- store.player is empty on a visit or in The City: nil there keeps what is on.
on("scene_entered", function()
local i = store.player.get("look")
if i then wear(i) end
end)
local function next_look()
local i = (store.player.get("look") or 0) + 1
if i > #LOOKS then i = nil end
store.player.set("look", i)
wear(i)
end
------------------------------------------------------------------- left
-- Clear, light, heavy, clear. Snow, or rain on a date the game refuses snow
-- (only weather it could roll that day is allowed, refused with command-weather).
local NAMES = { snow = { light = "light snow", heavy = "a blizzard" }, rain = { light = "light rain", heavy = "a storm" } }
local function next_weather()
local now = game.weather()
local step = now.kind == "clear" and "light" or now.intensity ~= "heavy" and "heavy" or nil
local id, why, code, kind
if not step then
id, why = cmd.set_weather("clear")
else
for _, k in ipairs({ "snow", "rain" }) do
kind = k
id, why, code = cmd.set_weather(k, step)
if code ~= "command-weather" then break end
end
end
if id then
cmd.show_line("The weather was " .. now.kind .. ". Here comes " .. (step and NAMES[kind][step] or "clear sky") .. "!")
else
cmd.show_line("The weather stays " .. now.kind .. ": " .. why)
end
end
--------------------------------------------------------------------- up
local REACTIONS = { "dance", "hooray", "pose", "thanks" }
local reaction = 0
local function react()
local input = game.input() -- nil while the text editor is open
local name = "spin"
if not (input and input.r) then
reaction = reaction % #REACTIONS + 1
name = REACTIONS[reaction]
end
if cmd.react(name) then cmd.play_sound("choice") end
end
------------------------------------------------------------------- down
local saving -- the save's id, to know its command_finished
local function save_here()
local id, why = cmd.save()
if id then saving = id else cmd.show_line("No save here: " .. why) end
end
on("command_finished", function(e)
if e.id ~= saving then return end
if not e.ok then
cmd.show_line("The save was refused: " .. e.message)
else
local p, w = game.place(), game.weather() -- a save is only ever outdoors in town
cmd.show_line("Town saved in acre " .. p.acre .. ", square " .. p.unit_x .. "-" .. p.unit_z .. ", in " .. w.kind .. " weather.")
cmd.play_sound("item_get")
end
end)
---------------------------------------------------------------- buttons
local PRESS = { dpad_right = next_look, dpad_left = next_weather, dpad_up = react, dpad_down = save_here }
on("button_pressed", function(e)
if PRESS[e.button] then PRESS[e.button]() end
end)
-- One button shows button_released: the look's sound plays as you let go.
on("button_released", function(e)
if e.button == "dpad_right" then cmd.play_sound("wear") end
end)
------------------------------------------------------------ every 5th thing
-- player_acted is the start of one of the game's actions (a dig, a swing, a
-- door). "reacted" is left out: the cheer would count itself.
on("player_acted", function(e)
if e.action == "reacted" then return end
local done = (store.player.get("done") or 0) + 1
store.player.set("done", done)
local p = game.player() or {} -- nil before a town is loaded
log(e.action, "#" .. done, "now", p.state or "?", p.tool or "no tool")
-- The player is busy with that action now, so cheer a game minute later.
if done % 5 == 0 then timer.after(1, "cheer") end
end)
on("timer_fired", function(e)
if e.name ~= "cheer" then return end
local ok, _, code = cmd.react("hooray")
if ok then
cmd.play_sound("item_get")
elseif code == "command-busy" or code == "command-cannot-react" then
timer.after(1, "cheer") -- sitting, mid-swing or talking: again in a minute
end
end)
More recipes #
Smaller mods for the rarer features, which no example mod uses. Each is a whole mod: put its files in a folder, change yourname to your own name, and it installs.
A thank-you letter after spending Bells at Nook's #
Counts what each player spends at Nook's and mails a thank-you once they pass 10,000 Bells. It also logs every sale.
{
"schema": 1,
"api": 1,
"id": "yourname.big-spender",
"name": "Big Spender",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"content": {
"messages": "messages.json"
},
"scripts": {
"main": "main.lua",
"events": [
"item_bought",
"item_sold"
]
},
"permissions": [
"send_letter"
],
"assets_original": true
}local GOAL = 10000
-- item_bought fires at every counter. e.shop says which one.
on("item_bought", function(e)
if e.shop ~= "nook" then return end
local spent = (store.player.get("spent") or 0) + e.price
store.player.set("spent", spent)
if spent < GOAL or store.player.get("thanked") then return end
local id, why, code = cmd.send_letter{ text = message("thanks"), from = message("from") }
if id then store.player.set("thanked", true) else log("no letter:", why, code) end
end)
-- item_sold: e.count goods went for e.bells, to "nook" or a "villager".
on("item_sold", function(e)
log(string.format("sold %d x 0x%04X for %d Bells to %s", e.count, e.item, e.bells, e.shop))
end){
"thanks": "Thank you for shopping with us! You are one of our very best customers.",
"from": "The Shop"
}- A catalog order fires item_bought too, with e.ordered true. It is paid now and mailed tomorrow.
- On a friend's town the letter is refused (command-visiting): only the town owner's game mails letters.
A Saturday fruit market at the flower shop #
Every Saturday the flower shop sells only cherries and pears, and it stays open through the night. A script decides it each morning, so the rule can be anything a script can read.
{
"schema": 1,
"api": 1,
"id": "yourname.saturday-market",
"name": "Saturday Market",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "world",
"scripts": {
"main": "main.lua",
"events": [
"day_started"
]
},
"permissions": [
"set_shop_goods",
"set_shop_open"
],
"assets_original": true
}local CHERRY, PEAR = 0x2801, 0x2802
-- A shop change from a script lasts for the rest of the game day,
-- so it is set again each morning.
on("day_started", function(e)
if e.weekday ~= 6 then return end -- 0 is Sunday, 6 is Saturday
local id, why, code = cmd.set_shop_goods("flower", {
goods = { { item = CHERRY, price = 400 }, { item = PEAR, price = 400 } },
own_goods = false
})
if not id then log("no market today:", why, code) return end
cmd.set_shop_open("flower", true)
end)- A script's change is one more block after the mod's own shops.json blocks for that shop. It is gone when the day changes or the game restarts.
- It is refused when a mod later in the load order changes the same shop, or when the shop has no goods or no open in the shop table.
Swap an item for another #
Once a day, asks the player for an apple and gives a pear back. cmd.take_item asks with the game's own question, so the player always agrees first.
{
"schema": 1,
"api": 1,
"id": "yourname.fruit-swap",
"name": "Fruit Swap",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"scene_entered",
"command_finished"
]
},
"permissions": [
"take_item",
"give_item"
],
"assets_original": true
}local APPLE, PEAR = 0x2800, 0x2802
on("scene_entered", function(e)
if e.name ~= "town" or store.player.get("asked") == game.day_number() then return end
local id, why, code = cmd.take_item{ item = APPLE, count = 1 }
if id then
store.player.set("asked", game.day_number())
else
log("no swap today:", why, code) -- command-not-held: no apple in the pockets
end
end)
on("command_finished", function(e)
if e.command == "take_item" and e.ok then -- e.via is "taken"
cmd.give_item(PEAR)
elseif e.command == "take_item" then
log("no swap:", e.code) -- command-declined when the player said no
end
end)- A take is refused at once with command-not-held when the pockets do not hold the item.
- A take sends no question_answered. Its one result is command_finished.
- Takes are refused on a visit and in The City.
A hotkey: a button combination #
Hold L and press Z: says the time, or the date with the stick pushed up. A keyboard, a controller and the touch pad all reach a script as the same buttons.
{
"schema": 1,
"api": 1,
"id": "yourname.clock-key",
"name": "Clock Key",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"button_pressed",
"button_released"
]
},
"permissions": [
"show_line"
],
"assets_original": true
}local holding_l = false
on("button_released", function(e)
if e.button == "l" then holding_l = false end
end)
on("button_pressed", function(e)
if e.button == "l" then holding_l = true return end
if e.button ~= "z" or not holding_l then return end
local t, input = game.town(), game.input()
if not t or not input then return end
if input.stick_y > 0.5 then
cmd.show_line(string.format("It is %d/%d.", t.month, t.day))
else
cmd.show_line(string.format("It is %d:%02d.", t.hour, t.minute))
end
end)- game.input() reads every button held and the main stick when the handler runs. On a busy frame an event can run a frame or two after the press, so a combination is safest tracked from the events, as holding_l is here.
- The game still gets every press, so pick a combination it does not use, or a moment where the button does nothing.
- A script never sees which key was typed. While the player writes a letter or a name, nothing reaches it and game.input() is nil.
Save the game each time the player steps outside #
cmd.save() saves the town where the player could save at Gyroid. This mod asks for a save every time the player comes back outdoors, and says so when the game wrote one.
{
"schema": 1,
"api": 1,
"id": "yourname.step-out-save",
"name": "Step Out Save",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"scene_entered",
"command_finished"
]
},
"permissions": [
"save",
"show_line"
],
"assets_original": true
}on("scene_entered", function(e)
if e.name ~= "town" then return end
local id, why, code = cmd.save() -- waits until the player is free outdoors
if not id then log("no save:", why, code) end -- command-too-soon right after another save
end)
on("command_finished", function(e)
if e.command ~= "save" then return end
if e.ok and e.via == "saved" then
cmd.show_line("Saved!")
elseif not e.ok then
log("save refused:", e.code) -- command-busy, command-indoors, ...
end
end)- The game saves only outdoors in the player's own town, in free control. Indoors the save is refused with command-indoors and nothing is written.
- The save never changes the town being played, so it cannot lose or double an item.
- via is "unchanged" when nothing changed since the last save. Only a save that wrote the town counts against the day's cap.
- Saves by mods are at least a few seconds apart, and every save uploads the town to the cloud, so never save on a timer: the Autosave setting does that.
- A save is refused on a visit and in The City.
Play a jingle when a fish is caught #
cmd.play_sound plays one of the game's own sound effects, by its name in sounds.json. This mod plays the item jingle when the player catches a fish worth keeping.
{
"schema": 1,
"api": 1,
"id": "yourname.catch-jingle",
"name": "Catch Jingle",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"fish_caught"
]
},
"permissions": [
"play_sound"
],
"assets_original": true
}on("fish_caught", function(e)
local id, why, code = cmd.play_sound("item_get") -- a name from sounds.json
if not id then log("no jingle:", why, code) end -- command-sound-cap after many in a minute
end)- Only the player whose game runs the mod hears the sound. On a visit the friend does not hear it.
- A sound plays at once, in a talk or a menu too: it does not wait for the player to be free.
- Every sound in sounds.json plays once and stops on its own. None loops.
- A few sounds per event and a few per minute: play one for a moment that matters.
A rainy morning that clears by noon #
cmd.set_weather sets the town's weather for the rest of the game day. This mod makes it rain at 8 in the morning and clears the sky at noon, and in the snowy months it snows instead.
{
"schema": 1,
"api": 1,
"id": "yourname.rainy-morning",
"name": "Rainy Morning",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "world",
"scripts": {
"main": "main.lua",
"events": [
"hour_changed",
"command_finished"
]
},
"permissions": [
"set_weather"
],
"assets_original": true
}local function wet()
local t = game.town()
local m, d = t.month, t.day
if (m == 11 and d > 15) or m == 12 or m == 1 or (m == 2 and d <= 24) then return "snow" end
return "rain"
end
on("hour_changed", function(e)
if e.hour == 8 then
local id, why, code = cmd.set_weather(wet())
if not id then log("no weather today:", code) end -- command-weather on a festival or a clear-only day
elseif e.hour == 12 then
cmd.set_weather("clear")
end
end)
on("command_finished", function(e)
if e.command == "set_weather" and not e.ok then log("weather refused:", e.code) end
end)- Only weather the game itself could roll that day is allowed: no rain in the snowy months, no snow from late February to October, and only clear on the days the game keeps clear, such as New Year and the cherry blossoms.
- The change waits for the player to be free, then the drops or flakes fade in as the game's own weather does. via is "unchanged" when the town already had that weather.
- It needs "scope": "world": a friend visiting sees the same weather. A visitor's game needs no copy of the mod for it.
- The weather is refused on a visit and in The City. The next game day the game picks its own weather again.
A setting only its own player sees #
A World mod with a setting each player keeps for themselves: whether a line greets them each morning.
{
"schema": 1,
"api": 1,
"id": "yourname.morning-line",
"name": "Morning Line",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "world",
"content": {
"messages": "messages.json"
},
"scripts": {
"main": "main.lua",
"events": [
"day_started"
]
},
"permissions": [
"show_line"
],
"settings": [
{
"name": "greet",
"type": "bool",
"label": "Say good morning",
"default": true,
"scope": "client"
}
],
"assets_original": true
}on("day_started", function(e)
if not settings.get("greet") then return end
local id, why, code = cmd.show_line(message("morning"))
if not id then log("no line:", why, code) end
end){
"morning": "Good morning! What a lovely day for a walk."
}- "scope": "client" makes the value the player's own. A friend visit never compares it, and on a visit each player runs their own value.
- A client setting may decide only what its own player sees or hears. In an event that read one, send_letter, give_item, take_item and take_bells are refused with command-client-setting. show_line and ask still work.
- In a Just you mod the scope changes nothing a visit sees. The script kit's setting leaves it out.
Remember something in this browser, whatever the town #
store.client is one store per mod per browser. store keeps a value per town and store.player per resident.
{
"schema": 1,
"api": 1,
"id": "yourname.day-counter",
"name": "Day Counter",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"day_started"
]
},
"assets_original": true
}local town_seen = nil -- what store.town() said last time
on("day_started", function(e)
local n = (store.client.get("days") or 0) + 1
store.client.set("days", n)
-- store.town() changes when the town does, so a local can be reloaded.
if store.town() ~= town_seen then
town_seen = store.town()
log("another town now:", town_seen)
end
log("days started in this browser:", n, "in this town:", store.get("days"))
store.set("days", (store.get("days") or 0) + 1)
end)- store.client answers the same in every town played in this browser. store and store.player travel with the town.
Change the shape of saved data #
Version 2 of a mod renames a store key. data_migrated runs once per town, before any other handler there.
{
"schema": 1,
"api": 1,
"id": "yourname.visit-count",
"name": "Visit Count",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"data_version": 2,
"scripts": {
"main": "main.lua",
"events": [
"data_migrated",
"scene_entered"
]
},
"assets_original": true
}-- Version 1 kept the count as "count". Version 2 calls it "visits".
on("data_migrated", function(e)
if e.from < 2 then
store.set("visits", store.get("count"))
store.set("count", nil)
end
log("data moved from version", e.from, "to", e.to)
end)
on("scene_entered", function(e)
store.set("visits", (store.get("visits") or 0) + 1)
end)- e.from is 0 for data written before the mod had a data_version. If the handler errors, the script stops and the next start tries again.
Notice a new villager, or a friend riding in #
villager_moved_in fires at the game start after a villager moved in. visitor_arrived fires in the host's game when a friend is on the way.
{
"schema": 1,
"api": 1,
"id": "yourname.arrivals",
"name": "Arrivals",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"villager_moved_in",
"visitor_arrived"
]
},
"permissions": [
"show_line"
],
"assets_original": true
}on("villager_moved_in", function(e)
cmd.show_line(e.villager.name .. " has moved in. Go and say hello!")
end)
on("visitor_arrived", function(e)
-- e.kind is "friend"
cmd.show_line("A friend is riding in on the train!")
end)- A brand-new town fires villager_moved_in for its first villagers too.
A weather report on the hour: where you are and what is falling #
Every game hour, while the player is outdoors, says the acre they stand in and the weather there. Indoors it stays quiet.
{
"schema": 1,
"api": 1,
"id": "yourname.weather-report",
"name": "Weather Report",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"hour_changed"
]
},
"permissions": [
"show_line"
],
"assets_original": true
}local WORDS = { clear = "clear skies", rain = "rain", snow = "snow" }
on("hour_changed", function(e)
local w, p = game.weather(), game.place()
if not w or not p or not p.acre then return end -- no town yet, or indoors
local sky = WORDS[w.kind]
if w.intensity ~= "none" then sky = w.intensity .. " " .. sky end
local where = p.island and "the island" or ("acre " .. p.acre)
cmd.show_line(string.format("%d:00 at %s: %s.", e.hour, where, sky))
end)- kind is clear, rain or snow, the words shops and talk pools use. Cherry blossom petals and falling leaves count as clear.
- p.acre is the town map's label, like "C-3", and is nil indoors. unit_x and unit_z say which of the acre's 16 by 16 squares, never anything finer.
- Neither query needs a permission: reading changes nothing. Both are nil before a town is loaded.
Need another mod, or refuse to run with one #
"depends" names mods this one needs: it loads after them and not at all without them. "conflicts" names mods it cannot run with. message() reads another mod's line by its full key.
{
"schema": 1,
"api": 1,
"id": "yourname.tea-talk",
"name": "Tea Talk",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"villager_talked"
]
},
"depends": {
"yourname.tea-lib": ">=1.0.0 <2.0.0"
},
"conflicts": {
"someone.other-tea": "*"
},
"assets_original": true
}on("villager_talked", function(e)
-- a needed mod is always there, so call it without asking first
local tea = remote.call("yourname.tea-lib", "brew", "green", 2)
-- "author.mod:key" reads a line from another mod's messages file
local hello = message("yourname.tea-lib:greeting") or "Hello!"
return { place = "before", line = hello .. " I made " .. tea.cups .. " cups of " .. tea.kind .. " tea." }
end)- A mod id goes in only one of depends, optional_depends and conflicts.
- For a mod yours can use but does not need, see optional_depends in the script kit and the dependencies guide.
Small talk for the weather, the season and the time of day #
Villagers say your lines as their small talk, when you choose to chat. A pool can be kept to one personality, to rain or snow, or to a season and a time of day. No code.
{
"schema": 1,
"api": 1,
"id": "yourname.weather-talk",
"name": "Weather Talk",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"content": {
"talk": "talk.json"
},
"assets_original": true
}{
"pools": [
{
"place": "topic",
"personality": "cranky",
"lines": [
"Hmph. Another day of\nyou walking around.",
"What now? I was just\ngetting comfortable."
]
},
{
"place": "topic",
"weather": "rain",
"lines": [
"Rain again. The flowers\nare loving it, at least."
]
},
{
"place": "topic",
"season": "fall",
"time": "evening",
"chance": 30,
"lines": [
"The evenings come so\nearly now. I like it."
]
}
]
}- season is spring, summer, fall or winter. time is morning (5 to 12), day (12 to 17), evening (17 to midnight) or night (midnight to 5). weather is clear, rain or snow.
- The most specific pools that fit decide: the villager by name, else their personality, else everyone. A cranky villager only ever gets the cranky pool here, rain or not.
- chance is in how many talks in 100 a fitting pool speaks. Leave it out for every one. When every pool that fits rolls no, the villager makes the game's own small talk.
Lines anywhere in a talk: before, hello, topic, after, the whole conversation #
A pool's place puts its lines before the hello, as the hello, as the topic after a chat answer, after the topic, or as the whole conversation. A line can be a list of pages. No code.
{
"schema": 1,
"api": 1,
"id": "yourname.town-talk",
"name": "Town Talk",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"content": {
"calendar": "calendar.json",
"talk": "talk.json"
},
"assets_original": true
}{
"days": [
{
"id": "kite-day",
"date": {
"month": 4,
"day": 12
}
}
]
}{
"pools": [
{
"place": "before",
"chance": 20,
"lines": [
"Psst! Over here!"
]
},
{
"place": "hello",
"weather": "rain",
"lines": [
[
"Oh, hi! Isn't the rain\nlovely?",
"The flowers think so."
]
]
},
{
"place": "topic",
"topics": [
"trade",
"small_talk"
],
"chance": 30,
"lines": [
"No deals today. Let's\njust talk."
]
},
{
"place": "after",
"time": "evening",
"lines": [
"Getting late. Get home\nsafe!"
]
},
{
"place": "topic",
"day": "kite-day",
"chance": 50,
"lines": [
"Kite Day! Look up!"
]
},
{
"place": "conversation",
"day": "kite-day",
"chance": 20,
"lines": [
[
"Kite Day! Everyone is\non the beach.",
"Go and see!"
]
]
}
]
}- before keeps the hello. hello replaces an everyday hello only; a hello with news is kept. The menu follows either.
- topic replaces the topic the game picked after a chat answer when it is one of topics (small_talk when you name none, "any" for all six). The talk ends after it. A trade it replaces does not happen.
- after is the last message of a chat. conversation is the whole talk: no hello, no menu, no topic.
- day is the id of a day in the same mod's calendar file: it is how a calendar day gets villager lines. On the day, a day's pools come ahead of every other pool of their place. Each place picks its own line, so one talk can have a before, a hello, a topic and an after line.
A villager asks the player something #
A script's conversation takes the whole talk and ends in a question. The player's pick goes to villager_answered, which says what comes next and may ask again.
{
"schema": 1,
"api": 1,
"id": "yourname.bake-sale",
"name": "Bake Sale",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "client",
"scripts": {
"main": "main.lua",
"events": [
"villager_talked",
"villager_answered"
]
},
"assets_original": true
}local asked = {}
on("villager_talked", function(e)
if asked[e.villager.id] then return nil end
asked[e.villager.id] = true
return {
place = "conversation",
line = { "I baked today!", "Want some?" },
ask = { text = "Tea or cake?", choices = { "Tea", "Cake", "No thanks" } },
}
end)
on("villager_answered", function(e)
if e.text == "Cake" then
return { line = "Cake it is!", ask = { text = "A big slice?", choices = { "Yes", "No" } } }
end
if e.text == "Yes" then return "A big slice for you. Enjoy!" end
if e.text == "Tea" then return "Tea, then. Lovely." end
return nil
end)
- ask has 2 to 4 choices of up to 16 characters. e.choice counts from 1; e.text is the answer picked.
- Return nil from villager_answered and the talk ends.
- A conversation needs every place in the talk free, so put the mod high in the list if another mod's script talks too.
- The list of who was asked is in memory: everyone is asked again after a restart.
Rename a mod item players already have #
Never change an item's id once players have it. To rename one, map the old full id to the new one with "renames". It runs once per save.
{
"schema": 1,
"api": 1,
"id": "yourname.lamps",
"name": "Lamps",
"version": "1.0.0",
"authors": [
"yourname"
],
"scope": "world",
"content": {
"items": "items.json"
},
"renames": {
"yourname.lamps:old-lamp": "yourname.lamps:ghost-lamp"
},
"assets_original": true
}{
"items": [
{
"id": "ghost-lamp",
"name": "Ghost Lamp",
"base": "0x122C",
"price": 2600
}
]
}- Both sides of a rename are this mod's own ids. An item of another mod cannot move into yours.
Try a recipe #
- Download its ZIP above, or copy its files into a folder with the same names.
- In the game, open Settings, then Mods. Under Install from a file, choose Choose a file, then Restart now.
The example mods are also in the mod list, under Browse mods in the Mods tab.
Start from a recipe on GitHub #
- Make a copy of the recipe's repository on GitHub, or download its ZIP and put the files in a new repository.
- Change the
idinmod.jsonto your own, such asyourname.something, and set your ownname. - Tag a release named for the version in
mod.json, such asv1.0.0. - In the game, open Settings, then Mods, and scroll to Share a mod. Import from GitHub shows there, under the upload form, once you are signed in, have answered the age question, have accepted the mod rules and have entered a code from your authenticator app. Paste
github.com/you/your-repo@v1.0.0there. See Publishing.