> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sure-developer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting Started

> Install sure_lib and load your first module

# Getting Started

<Badge icon="package" color="white" size="sm">sure\_lib 2.2.1</Badge>

This guide installs sure\_lib into a consuming FiveM resource and loads a first module through the shared loader.

## Requirements

<Columns cols={2}>
  <Card title="Runtime" icon="server">
    FiveM with `fx_version 'cerulean'`, `game 'gta5'`, and Lua 5.4 enabled.
  </Card>

  <Card title="Dependencies" icon="package-check">
    `ox_lib` and `es_extended` must start before `sure_lib`.
  </Card>
</Columns>

<Info>
  The `db` module also expects `oxmysql` to be available because it calls `exports.oxmysql:*_async` methods.
</Info>

## Install

<Steps>
  <Step title="Place the resource">
    Put the `sure_lib` folder in your server resources directory and make sure the folder name is exactly `sure_lib`.
  </Step>

  <Step title="Start dependencies first">
    Start `ox_lib`, `es_extended`, and then `sure_lib` before resources that consume it.
  </Step>

  <Step title="Import the loader">
    Add the shared loader to each consuming resource.
  </Step>
</Steps>

```lua fxmanifest.lua theme={"dark"}
fx_version 'cerulean'
game 'gta5'
lua54 'yes'

shared_script '@sure_lib/init.lua'

client_script 'client.lua'
server_script 'server.lua'

dependencies {
  'ox_lib',
  'es_extended',
  'sure_lib'
}
```

If you use the Lua UI module, point your consuming resource at the bundled renderer.

```lua fxmanifest.lua theme={"dark"}
ui_page 'https://cfx-nui-sure_lib/web/lui/index.html'
```

<Warning>
  Version `2.2.1` uses `@sure_lib/init.lua` and `sure.getModule(...)`. Keep consuming resources on this loader shape so examples and module resolution stay consistent.
</Warning>

## Load a module

<Tabs>
  <Tab title="Shared">
    ```lua shared.lua theme={"dark"}
    local validator = sure.getModule('validator')

    local schema = validator.object({
      name = validator.string().required(),
      amount = validator.integer().min(1)
    })

    schema.parse({
      name = 'bread',
      amount = 2
    })
    ```
  </Tab>

  <Tab title="Client">
    ```lua client.lua theme={"dark"}
    local player = sure.player
    local lui = sure.getModule('lui')

    player.waitUntilLoaded()

    print(player.serverId, player.health, player.coords)
    print(player.inventory.bread and player.inventory.bread.count or 0)

    lui.page('hello', function(ui)
      ui.panel(function()
        ui.text('Hello from Lua UI')
      end)
    end)
    ```
  </Tab>

  <Tab title="Server">
    ```lua server.lua theme={"dark"}
    local esx = sure.getModule('esx')
    local db = sure.getModule('db')
    local users = db:schema('users', { tableName = 'users' })

    RegisterCommand('givebread', function(source)
      esx.giveItem(source, 'bread', 1)
      users:create({
        data = {
          identifier = GetPlayerIdentifierByType(source, 'license')
        }
      })
    end, false)
    ```
  </Tab>
</Tabs>

## Common setup checks

<AccordionGroup>
  <Accordion title="sure.getModule returns nil">
    Confirm the module name is valid and that you are requesting it from a supported runtime. For example, `player`, `spawn`, and `lui` only exist on the client, while `esx` and `db` only exist on the server.
  </Accordion>

  <Accordion title="ESX data is empty on client">
    Call `sure.player.waitUntilLoaded()` before reading player data during resource startup.
  </Accordion>

  <Accordion title="Cooldown state does not sync">
    Define the cooldown on the server first, then read or start that key from the client.
  </Accordion>
</AccordionGroup>
