> For the complete documentation index, see [llms.txt](https://fehdead.gitbook.io/npc-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/fetchambient_4e1.md).

# npc.fetchambient\_4e1

```lua
npc.fetchambient_4e1(x, y, z)
```

|                         |                                 |
| ----------------------- | ------------------------------- |
| id                      | `0x04E1`                        |
| arguments               | 3: Float, Float, Float          |
| in NPC Kit              | yes                             |
| measured from a kit NPC | returns                         |
| vanilla scripts         | 475 calls in 81 of 1114 scripts |

## What it does

Lights the NPC with the map's colour at a point you give, instead of the spot under it. For an NPC above the floor (on a chair, a ledge), whose own spot has no ground to sample.

## Arguments

### `x` (Float)

### `y` (Float)

### `z` (Float)

The point to sample, on the floor. Vanilla's seated NPCs sample 0.5 to 2 units in front of the NPC, computed from its heading: `x + sin(h) * d`, `y` of the floor, `z + cos(h) * d`.

## Timing

Returns at once.

## In NPC Kit

Compute the point in Lua when `npc.add` runs:

```lua
local x, y, z, h, d = 31.2, -9.0, 66.0, 0.0, 1.0
npc.fetchambient_4e1(x + math.sin(h) * d, y, z + math.cos(h) * d);
```

## Used with

* [usemapid](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/usemapid.md)`(0)` and [setpos2](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/setpos2.md) with the seat's `y`.
* [stdmotionread](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/stdmotionread.md)`(18)` + [stdmotionvariation](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/stdmotionvariation.md): sitting.
* [fetchambient](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/fetchambient.md): the same for the spot under the NPC.

## Example

An NPC seated on a bench: the light sampled on the floor one unit in front of it, the point computed in Lua from the seat and the heading.

```lua
local seat, floorY, h = { 31.2, -8.55, 66.0 }, -9.0, 0.0

init = function()
    npc.setautorelax(1);
    npc.usecharhit(0);
    npc.bindp2_d4(0x006E0019, 4, 3);
    npc.stdmotionread(18);
    npc.stdmotionreadsync();
    npc.stdmotionvariation(1);
    npc.stdmotionplay_2c2(0x01000000, 0);
    npc.usemapid(0);                          -- keeps the seat's height
    npc.setpos2(seat[1], seat[2], seat[3]);
    npc.dir(h);
    npc.fetchambient_4e1(seat[1] + math.sin(h) * 1.0, floorY, seat[3] + math.cos(h) * 1.0);
    npc.bonecalcforce(-1);
    npc.show();
    npc.showshadow();
end,
```

## Pitfalls

* A point with no ground under it lights the NPC wrong: sample the floor, not the seat.
