Ox Lib

Uma biblioteca standalone para fornecer código reutilizável de forma fácil como módulos importáveis e exports.

Instalação

Recomendamos fortemente consultar os Guias para configurar o Git, Node.js e pnpm.

Baixe uma release (opens in a new tab) ou compile o código-fonte.

git clone https://github.com/overextended/ox_lib.git
cd ox_lib/web
pnpm i
pnpm build

Configuração

A configuração do recurso é feita utilizando convars (opens in a new tab).

# https://v6.mantine.dev/theming/colors/#default-colors
setr ox:primaryColor blue
setr ox:primaryShade 8
setr ox:userLocales 1 # Permite que os usuários escolham seus idiomas usando /ox_lib

Você também precisará conceder permissões ACE ao recurso.

add_ace resource.ox_lib command.add_ace allow
add_ace resource.ox_lib command.remove_ace allow
add_ace resource.ox_lib command.add_principal allow
add_ace resource.ox_lib command.remove_principal allow

Uso

Para habilitar a biblioteca no seu recurso, basta adicionar @ox_lib/init.lua como um shared_script no seu arquivo fxmanifest.lua.

shared_scripts {
    '@ox_lib/init.lua',
}

Ou, se este for o único shared script que você usa, pode fazer:

shared_script '@ox_lib/init.lua'

Você pode especificar os módulos para importar no fxmanifest.lua, ou carregá-los dinamicamente.

ox_libs {
    'locale',
    'math',
    'table',
}

Quando o ox_lib for importado no seu script, ele disponibilizará várias variáveis globais:

  • lib Para importar módulos dinamicamente do ox_lib.
  • require Para importar módulos do seu próprio script.
  • cache Veja aqui.

You can now use the library functions inside of your resource, check the rest of the documentation to see how to utilise them.

Using icons for interface functions

The icon library used is Font Awesome 6.0, if for the icon you define only a string the default icon type will be solid.
If you want to use a different icon type, i.e apple as a brand, you need to define icon as a table (array) with the first value being the icon type (fas, far, fab) as a string, and the second being the icon name.

icon = {'fab', 'apple'}

Building the UI

If you wish to edit any of the UI elements you will need to download the source code, edit what you need and then compile it.

⚠️

DO NOT de-bundle and un-minify the release CSS and JS files to edit them.

Requirements:

Installing Node.js:

  • Download the LTS version of Node.js.
  • Go through the install and make sure you install all of the features.
  • Run node --version in cmd and make sure that it gives you the version number. If it doesn't then you didn't install it correctly.

Installing pnpm:

  • After installing NodeJS you can install pnpm by running npm install -g pnpm.

Building the UI:

  • cd into the web directory.
  • run pnpm i to install the dependencies.
  • run pnpm build to build the source files.

When working in the browser you can run pnpm start, which supports hot reloads meaning that you will see your changes after saving your file.

If you want to work in game you can run pnpm start:game which writes changes to disk, so the only thing you have to do is restart the resource for it take affect.