# Lifestyle – the CPAPI reference (version 1)

Everything in Lifestyle runs through one Lua table, `CPAPI`: the phone (your own apps and contacts), settings, daily needs, money, Lifemail, AI, body sliders, tattoos, pets and the menu. The mod's own screens use these same functions, so a change made from your mod shows up everywhere.

## Where your files go

Your mod is a normal FS25 mod folder (or the same thing zipped) in your mods folder:

```
Documents\My Games\FarmingSimulator2025\mods\
    HS25_Lifestyle_Mod.zip        <- Lifestyle (or its unzipped folder)
    FS25_MyPhoneApp\              <- your mod, while you work on it
        modDesc.xml               <- the game reads this first: name, version, which scripts to load
        icon_myApp.dds            <- the mod's icon (256 x 256), also used as the phone app icon
        scripts\
            MyPhoneApp.lua        <- your code (listed in modDesc.xml under <extraSourceFiles>)
        textures\                 <- optional: your own pictures (.dds)
```

- `modDesc.xml` must have `<dependency>HS25_Lifestyle_Mod</dependency>` so Lifestyle loads before your mod.
- Every `.lua` file must be listed in `<extraSourceFiles>` or the game never runs it.
- `g_currentModDirectory` (read it at the top of your script, while the game loads it) is the path to your folder: use it for your pictures, e.g. `modDir .. "textures/logo.dds"`.
- Errors go to `Documents\My Games\FarmingSimulator2025\log.txt`. Search it for your mod's name.
- To send it in: zip the CONTENTS of your folder (modDesc.xml at the top of the zip) and upload it on /submit.

## Getting the API from your mod

```lua
local api = CPAPI or (HS25_Lifestyle_Mod ~= nil and HS25_Lifestyle_Mod.CPAPI) or nil
if api ~= nil and api.VERSION >= 1 then
    -- use it
end
```

Call it after the map has loaded, for example from your mod's `loadMap` or later (each mod has its own Lua environment; Lifestyle puts `CPAPI` where yours can see it). In every function that takes a character key, `key = nil` means the character being edited in the wardrobe, or your own player when the wardrobe is closed.

## Phone apps
| Function | What it does |
|---|---|
| `api.phone.addApp(def)` | Put your app on the phone's Home Screen (see below). Returns `true` when it was added. |
| `api.phone.open(view)` / `api.phone.close()` / `api.phone.isOpen()` | Open the phone (optionally on an app's view), close it, or check it. |
| `api.phone.notify(title, body)` | A banner on the phone (a toast when it's closed) with the message sound. |
| `api.phone.message(text, kind)` | A line in the phone's system messages. `kind`: `"info"`, `"ok"`, `"critical"`. |
| `api.phone.design()` | Returns `CPDesign, CPUI`: the phone's own drawing kit (below), so your app looks like the rest of the phone. |

```lua
api.phone.addApp({
    id    = "myPhoneApp",                       -- unique, letters / numbers / _ only
    title = "My App",                           -- the name under the icon (or a l10n key)
    icon  = modDir .. "icon_myApp.dds",         -- a .dds path, or the name of a phone icon like "uiL_star"
    color = { 0.20, 0.55, 0.90 },               -- the icon's tile colour
    draw  = function(phone, x, y, w, h) end,    -- runs every frame while your app is open (inside the phone screen)
    -- launch = function() end,                 -- instead of draw: your app opens its own screen
    badge = function() return nil end,          -- a number or "!" = a red dot on the icon
})
```

**Drawing inside the phone.** `x, y, w, h` is the app's area in screen units (0..1, y goes up). `phone:hit(x, y, w, h, fn)` makes a box clickable (it returns `true` while the mouse is over it). With the design kit:

```lua
local D, UI = api.phone.design()
local c = D.c()                                                  -- the current colours: c.text, c.sub, c.surface, c.raised ...
D.text(x, y + h - UI.py(30), UI.py(18), "Hello", c.text, 1, RenderText.ALIGN_LEFT, true)       -- (x, y, size, text, colour, alpha, align, bold, maxWidth)
D.row(phone, x, y + h - UI.py(90), w, UI.py(46), { title = "A row", sub = "with a line under it", chevron = true, part = "single", fn = function() end })
D.button(phone, x, y, w, UI.py(44), "Do it", "primary", function() end)                       -- kinds: primary, plain, tinted, danger
UI.box(x, y, w, h, 1, 1, 1, 0.1, UI.px(12))                                                    -- a rounded box (x, y, w, h, r, g, b, a, radius)
```
`UI.px(n)` / `UI.py(n)` turn pixels of a 1920 x 1080 screen into screen units, so your app looks the same on every monitor.

## Money
| Function | What it does |
|---|---|
| `api.money.get()` | The player's farm money. |
| `api.money.canAfford(amount)` | Whether the farm has that much. |
| `api.money.charge(amount)` | Take money off the farm account (in multiplayer the host checks and takes it). Returns `true` when it went. |
| `api.money.pay(amount)` | Pay money to the farm. Host / single player only (a client can't make money); returns `false` otherwise. |

## Lifemail
| Function | What it does |
|---|---|
| `api.mail.send({ from, fromAddr, subject, body, quiet })` | Put a mail in the player's in-game inbox (works offline). `quiet = true` = no banner. |

## AI and Lifestyle Link
| Function | What it does |
|---|---|
| `api.ai.ready()` | Whether an AI answer is possible right now (Lifestyle Link signed in, AI on). |
| `api.ai.isOff(key)` | Whether the player switched an AI feature off in Settings > AI (`"neighbours"`, `"family"`, `"pet"`, `"farmer"`, `"advisor"`, `"dispatch"`...). Check this before your own AI feature, and add nothing if they turned AI off. |
| `api.ai.ask(question, persona, function(answer, err) end)` | Ask the AI as your character (`persona` = who they are and how they talk). Counts against the player's daily AI answers. Keep it 13+. |
| `api.link.online()` | Whether Lifestyle Link is signed in (online features work). |

## Settings
| Function | What it does |
|---|---|
| `api.settings.get(id)` / `api.settings.set(id, value)` | Read or change a setting. The change saves straight away. |
| `api.settings.list()` | Every setting: `{ id, section, sectionTitle, type, value, default, values, texts, label, tooltip }`. |
| `api.settings.add(sectionId, def, sectionTitle)` | Add your own setting to the menu. `def = { id, type = "bool" \| "choice", default, values = {...}, texts = {...}, label, tooltip, onChange = function(v) end }`. A saved value is restored automatically. |

## Body
| Function | What it does |
|---|---|
| `api.body.sections()` | The slider groups, each with its sliders: `{ id, label, min, max, step, values, texts }`. |
| `api.body.get(key, sliderId)` / `api.body.set(key, sliderId, value)` | Read or change one slider. The value is a multiplier (1 = normal) and is clamped to the slider's range. |
| `api.body.getAll(key)` / `api.body.setAll(key, { height = 1.03, ... })` | Read or change every slider at once. |
| `api.body.reset(key)` | Set every slider back to normal. |
| `api.body.currentKey()` | The key of the character being edited or worn. |

Slider ids: `height`, `weight`, `muscle`, `headSize`, `neckLength`, `neckThick`, `shoulders`, `chest`, `chestWidth`, `belly`, `waist`, `hips`, `butt`, `upperArms`, `forearms`, `armLength`, `hands`, `thighs`, `calves`, `feet`.

## Tattoos
| Function | What it does |
|---|---|
| `api.tattoos.slots(key)` | The spots this character has: `{ id, zone, zoneTitle, title, list }`. |
| `api.tattoos.designs(slotId)` | The designs that fit a spot: `{ id, name, icon }`. |
| `api.tattoos.get(key, slotId)` | The id of the design on that spot, or `nil`. |
| `api.tattoos.set(key, slotId, design)` | Put a design on a spot. `design` is an id, a list number, or `nil` / `"none"` to remove it. Covering one area clears whatever else was there, e.g. a full sleeve replaces the upper arm and forearm pieces. |
| `api.tattoos.getAll(key)` / `api.tattoos.clear(key)` | Read every spot, or remove every tattoo. |
| `api.tattoos.registerDesign(list, def)` | Add your own artwork while the game runs (see below). |

**Spots:**

| Zone | Spots |
|---|---|
| Head | `forehead`, `leftCheek`, `rightCheek`, `leftTeardrop`, `rightTeardrop`, `leftNeck`, `rightNeck` |
| Torso | `chest`, `back` |
| Arms | `leftSleeve`, `leftUpperArm`, `leftForearm`, `rightSleeve`, `rightUpperArm`, `rightForearm` |
| Hands | `leftHand`, `rightHand`, `leftKnuckles`, `rightKnuckles` |
| Legs | `leftThigh`, `rightThigh`, `leftCalf`, `rightCalf` |

Face spots are on the mod's own characters only. Leg spots are on the base game characters only.

**Lists:** `normal` (the regular designs), `small` (face and neck: tiny designs plus the regular ones), `tiny`, `sleeve` and `knuckles` (4 letters, one per finger).

**Your own design:**

```lua
api.tattoos.registerDesign("normal", {
    id = "myDragon",                                  -- must be unique
    texture = g_currentModDirectory .. "dragon.dds",  -- RGBA, transparent background, square (sleeve: 512x1024 and wraps sideways)
    icon = g_currentModDirectory .. "dragon_icon.dds",-- optional, 256x256
    name = "Dragon",
})
```

A saved choice of a custom design comes back as soon as the design is registered again.

## Daily needs
Food (`hunger`), water (`thirst`) and energy (`energy`), each from 0 to 100. They go down with in-game time, faster while running and thirst faster above 25 °C. Sleeping in the game's bed brings energy back. Meals, water and coffee are free near a farmhouse your farm owns; anywhere else they are bought with farm money. The HUD and the menu read everything through these functions, so a need you register gets its own HUD row and menu line.

| Function | What it does |
|---|---|
| `api.needs.isEnabled()` | Whether daily needs are switched on. |
| `api.needs.list()` | Every need: `{ id, label, icon, value, low, critical }`. |
| `api.needs.get(id)` / `api.needs.set(id, value)` / `api.needs.add(id, delta)` | Read, set or change a need. Values are clamped to 0–100. |
| `api.needs.reset()` | Fill every need. |
| `api.needs.eat()` / `api.needs.drink()` / `api.needs.coffee()` | The same as the keys and menu buttons: free at home, bought away from home. Return `ok, message`. |
| `api.needs.offer(kind)` | What `"eat"`, `"drink"` or `"coffee"` would give right now: `{ id, label, price, effects, home }`. |
| `api.needs.consume(def, quiet)` | Your own food or drink: `{ label = "Sandwich", effects = { hunger = 30 }, price = 8 }`. The price comes off the farm account. |
| `api.needs.isHome()` / `api.needs.isSleeping()` | Whether you are near your farmhouse, or asleep. |
| `api.needs.register(def)` | Add your own need: `{ id, label, icon = "<white-on-transparent .dds>", perHour = 4, sleepPerHour = -1, run = 1.2, heat = 1, lowText, criticalText }`. |

Keys: Left Alt + B eats, Left Alt + V drinks. They show in the key help only when that need is below 40. The Settings page has a **Cheat menu** switch; while it is on, a section appears for setting each need, freezing needs, free food, and pet helpers.

## Pets
| Function | What it does |
|---|---|
| `api.pets.list()` / `api.pets.get(idOrName)` | Your pets: `{ id, name, species, breed, gender, mode, hunger, mood, bond, ageDays, out, personality, followDist, size, nightHome, autoFeed, mapIcon, alerts, x, y, z, distance }`. |
| `api.pets.breeds()` | Every pet type you can adopt: `{ key, name, species }`. |
| `api.pets.canAdopt()` / `api.pets.max()` | Whether there is room for another pet, and the limit. |
| `api.pets.adopt({ name, breed, species, gender = "m"\|"f", personality, size, followDist })` | Adopt a pet. Returns the new pet's id, or `nil`. Host only. |
| `api.pets.release(id)` / `api.pets.rename(id, name)` / `api.pets.setBreed(id, breedKey)` | Release, rename or change the coat of a pet. |
| `api.pets.setOption(id, option, value)` | Change one setting. Options: `personality`, `followDist` (1–4), `size` (1–4), `nightHome`, `autoFeed`, `mapIcon`, `alerts`. |
| `api.pets.command(id, cmd)` | Give an order. Commands: `follow`, `stay`, `come`, `home`, `setHome`, `feed`, `pet`, `fetch`. |
| `api.pets.whistle()` | Call your pets. |

## Pet mess
| Function | What it does |
|---|---|
| `api.poop.count()` | How many piles are lying around. |
| `api.poop.drop(kind, x, y, z, scale)` | Drop a pile. `kind` is `"dog"`, `"cat"` or `"kangaroo"`. |
| `api.poop.cleanAround(x, z, radius)` | Clean up near a spot. Returns how many piles were removed. |
| `api.poop.clearAll()` | Clean up every pile. |

## Menu
| Function | What it does |
|---|---|
| `api.menu.open(page)` / `api.menu.close()` / `api.menu.isOpen()` | Open, close or check the menu. Pages: `"settings"`, `"needs"`, `"body"`, `"tattoos"`, `"pets"`, `"help"`, or your own. |
| `api.menu.addPage(def)` | Add your own tab (it goes before Help). See the example below. |

```lua
api.menu.addPage({
    id = "myPage", title = "My stuff",
    info = function(menu, state) return "Shown under the page title" end,
    action = { text = "Do it", fn = function(menu) end },        -- the bottom-bar button (controller: X / Y)
    build = function(menu, rows, state)
        rows:header("Section")
        rows:choice("Label", "Tooltip", { "Off", "On" }, function() return 1 end, function(i) end)
        rows:slider("Amount", "", { "0", "1", "2" }, function() return 2 end, function(i) end)
        rows:buttons({ { text = "Button", fn = function() end } })
        -- menu:rebuild() rebuilds the page on the next frame
    end,
    refresh = function(menu, rows, state) end,               -- runs when something changes
    live = false,                                            -- true = refresh every second while the page is open
})
```

## Phone contacts
Your mod can add its own people to the phone's Contacts, with a Messages conversation. You decide what they say. The player texts back and your function answers.

| Function | What it does |
|---|---|
| `api.contacts.add(def)` | Add a contact (see below). Returns `false` if the id is missing or another contact already uses that name. |
| `api.contacts.text(id, body)` | A text from them, any time (the phone's normal text alert). |
| `api.contacts.reply(id, body, delayMs)` | An answer with the typing dots first (default 1.5 s). |
| `api.contacts.remove(id)` / `api.contacts.list()` | Remove one, or get `{ {id, name, role}, ... }`. |

```lua
api.contacts.add({
    id = "dale", name = "Dale", role = "Feed store",
    onMessage = function(text, photo)        -- the player texted them (photo = true if they sent a picture)
        if text:lower():find("feed") then return "20 bags on the way!" end   -- a string = the reply
        return nil                                                           -- nil = no reply now
    end,
    onCall = function() end,                 -- optional: what tapping Call does
})
```
Names must be unique on the phone. The phone's own AI never answers for your contacts. An error inside `onMessage` is written to the log and doesn't break the phone.

## Events
`local handle = api.on(eventName, function(...) end)` adds a listener and `api.off(handle)` removes it.

| Event | Arguments |
|---|---|
| `settingChanged` | `id, value` |
| `bodyChanged` | `key, sliderId, value` |
| `bodyReset` | `key` |
| `tattooChanged` | `key, slotId, designId` (`designId` is `nil` when removed) |
| `tattoosCleared` | `key` |
| `designRegistered` | `list, id` |
| `petAdopted` | `pet` |
| `petReleased` | `pet` |
| `petChanged` | `pet, what` |
| `petCommand` | `pet, command` |
| `poopDropped` | `kind, x, y, z` |
| `steppedInPoop` | none |
| `menuOpened` | `pageId` |
| `menuClosed` | none |
| `needChanged` | `id, value, old, reason` (`"time"`, `"sleep"`, `"consume"`, `"api"`, `"reset"`) |
| `needLow` | `id, "low" \| "critical"` |
| `consumed` | `itemId, effects, price` |
| `needsReset` / `needsLoaded` | none |
| `needRegistered` | `id` |
| `sleepStarted` | none |
| `sleepEnded` | `energy` |

Listeners run in protected calls, so an error in one listener never breaks the mod.

## Fun
| Function | What it does |
|---|---|
| `api.hashy.play(which)` | A Hashy screen effect: `"disco"`, `"dvd"`, `"hype"`, `"chill"`, `"rain"` (`nil` = random). |

